Skip to content

Commit

Permalink
Xtreme firmware build (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Apr 3, 2023
1 parent d200615 commit cbf6811
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
url = https://github.com/flipperdevices/flipperzero-firmware.git
branch = release
ignore = dirty
[submodule "flipperzero-firmware_xtreme"]
path = flipperzero-firmware_xtreme
url = https://github.com/ClaraCrazy/Flipper-Xtreme
branch = main
ignore = dirty
2 changes: 1 addition & 1 deletion .pvsoptions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--rules-config .pvsconfig -e flipperzero-firmware_official_dev -e flipperzero-firmware_official_stable
--rules-config .pvsconfig -e flipperzero-firmware_official_dev -e flipperzero-firmware_official_stable -e flipperzero-firmware_xtreme
28 changes: 24 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ $build_commands = @(
Name = "Official Dev \ Unleashed";
FbtSwitch = "od";
FirmwarePath = "flipperzero-firmware_official_dev";
ArtifactName = "totp_official-dev_unleashed_fw{FEATURES_SUFFIX}.fap"
ArtifactName = "totp_official-dev_unleashed_fw{FEATURES_SUFFIX}.fap";
FW_CDEF = "TOTP_FIRMWARE_OFFICIAL_DEV"
}
[PSCustomObject]@{
Name = "Official Stable";
FbtSwitch = "os";
FirmwarePath = "flipperzero-firmware_official_stable";
ArtifactName = "totp_official-stable_fw{FEATURES_SUFFIX}.fap"
ArtifactName = "totp_official-stable_fw{FEATURES_SUFFIX}.fap";
FW_CDEF = "TOTP_FIRMWARE_OFFICIAL_STABLE"
}
[PSCustomObject]@{
Name = "Xtreme";
FbtSwitch = "x";
FirmwarePath = "flipperzero-firmware_xtreme";
ArtifactName = "totp_xtreme_fw{FEATURES_SUFFIX}.fap";
FW_CDEF = "TOTP_FIRMWARE_XTREME"
}
)

Expand All @@ -32,7 +41,8 @@ if (!(Test-Path -PathType Container "build")) {
function Features-Configure {
param (
[string[]]$enable,
[string[]]$disable
[string[]]$disable,
[string]$set
)

$featuresConfigContent = Get-Content "totp/features_config.h" -Raw
Expand All @@ -58,6 +68,14 @@ function Features-Configure {
})
}

if ($set) {
$keyValue = $set -split '='
$key = $keyValue[0]
$value = $keyValue[1]

$featuresConfigContent = $featuresConfigContent -replace "(#define +)($key)( +.+)(( |$)+)", "`$1`$2 $value`$4"
}

Set-Content -Path "totp/features_config.h" -NoNewline -Value $featuresConfigContent
Set-Content -Path "totp/application.fam" -NoNewline -Value $appManifestContent
}
Expand All @@ -74,6 +92,8 @@ function Build-Run {
Remove-Item "$build_path\*" -Recurse -Force
}

Features-Configure -set "TOTP_TARGET_FIRMWARE=$($build_command.FW_CDEF)"

./fbt $build_command.FbtSwitch COMPACT=1 DEBUG=0 VERBOSE=0 fap_totp

$latest_dir = Get-LatestDirectory -Path $build_path
Expand All @@ -96,6 +116,6 @@ Write-Information 'Building without BadBT'
Features-Configure -disable TOTP_BADBT_TYPE_ENABLED,TOTP_AUTOMATION_ICONS_ENABLED
Build-Run -FeaturesSuffix '_no-badbt'

Features-Configure -enable TOTP_BADBT_TYPE_ENABLED,TOTP_AUTOMATION_ICONS_ENABLED
Features-Configure -enable TOTP_BADBT_TYPE_ENABLED,TOTP_AUTOMATION_ICONS_ENABLED -set TOTP_TARGET_FIRMWARE=TOTP_FIRMWARE_XTREME

Pop-Location
5 changes: 4 additions & 1 deletion fbt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ if (('official-dev', 'off-dev', 'od', 'unleashed', 'un', 'u').Contains($args[0])
elseif (('official-stable', 'off-stbl', 'os').Contains($args[0])) {
$firmware_path = "flipperzero-firmware_official_stable"
$firmware_name = "Official Stable"
} elseif (('xtreme', 'xt', 'x').Contains($args[0])) {
$firmware_path = "flipperzero-firmware_xtreme"
$firmware_name = "Xtreme"
}
else {
throw "Unable to recognize which firmware to use"
Expand All @@ -19,7 +22,7 @@ Write-Host "Using $firmware_name firmware to run FBT"
$commandline_scons = "$firmware_path\site_scons\commandline.scons"
((Get-Content -Path $commandline_scons -Raw) -replace 'applications_user','..') | Set-Content -Path $commandline_scons -NoNewline

$builtin_totp_path = "$firmware_path\applications\plugins\totp"
$builtin_totp_path = "$firmware_path\applications\external\totp"
if ((Test-Path -Path $builtin_totp_path) -eq $True) {
Remove-Item $builtin_totp_path -Recurse
}
Expand Down
1 change: 1 addition & 0 deletions flipperzero-firmware_xtreme
4 changes: 2 additions & 2 deletions pvs-build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

pushd flipperzero-firmware_official_dev
rm -rf applications/plugins/totp
pushd flipperzero-firmware_xtreme
rm -rf applications/external/totp
sed -i 's/applications_user/../' site_scons/commandline.scons
./fbt fap_totp
popd
4 changes: 2 additions & 2 deletions sonar-build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

pushd flipperzero-firmware_official_dev
rm -rf applications/plugins/totp
pushd flipperzero-firmware_xtreme
rm -rf applications/external/totp
sed -i 's/applications_user/../' site_scons/commandline.scons
./fbt fap_totp
popd
14 changes: 13 additions & 1 deletion totp/features_config.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
// Include Bluetooth token input automation
#define TOTP_BADBT_TYPE_ENABLED
#define TOTP_AUTOMATION_ICONS_ENABLED

// Include token input automation icons on the main screen
#define TOTP_AUTOMATION_ICONS_ENABLED

// List of compatible firmwares
#define TOTP_FIRMWARE_OFFICIAL_STABLE 1
#define TOTP_FIRMWARE_OFFICIAL_DEV 2
#define TOTP_FIRMWARE_XTREME 3
// End of list

// Target firmware to build for
#define TOTP_TARGET_FIRMWARE TOTP_FIRMWARE_XTREME
58 changes: 53 additions & 5 deletions totp/workers/bt_type_code/bt_type_code.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "bt_type_code.h"
#include <furi_hal_bt_hid.h>
#include <bt/bt_service/bt_i.h>
#include <storage/storage.h>
#include "../../types/common.h"
#include "../../types/token_info.h"
Expand All @@ -11,6 +12,26 @@ static inline bool totp_type_code_worker_stop_requested() {
return furi_thread_flags_get() & TotpBtTypeCodeWorkerEventStop;
}

#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
static void totp_type_code_worker_bt_set_app_mac(uint8_t* mac) {
uint8_t max_i;
size_t uid_size = furi_hal_version_uid_size();
if(uid_size < 6) {
max_i = uid_size;
} else {
max_i = 6;
}

const uint8_t* uid = furi_hal_version_uid();
memcpy(mac, uid, max_i);
for(uint8_t i = max_i; i < 6; i++) {
mac[i] = 0;
}

mac[0] = 0b10;
}
#endif

static void totp_type_code_worker_type_code(TotpBtTypeCodeWorkerContext* context) {
uint8_t i = 0;
do {
Expand All @@ -30,7 +51,7 @@ static void totp_type_code_worker_type_code(TotpBtTypeCodeWorkerContext* context
}

static int32_t totp_type_code_worker_callback(void* context) {
furi_assert(context);
furi_check(context);
FuriMutex* context_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(context_mutex == NULL) {
return 251;
Expand Down Expand Up @@ -74,7 +95,7 @@ void totp_bt_type_code_worker_start(
char* code_buf,
uint8_t code_buf_length,
FuriMutex* code_buf_update_sync) {
furi_assert(context != NULL);
furi_check(context != NULL);
context->string = code_buf;
context->string_length = code_buf_length;
context->string_sync = code_buf_update_sync;
Expand All @@ -87,7 +108,7 @@ void totp_bt_type_code_worker_start(
}

void totp_bt_type_code_worker_stop(TotpBtTypeCodeWorkerContext* context) {
furi_assert(context != NULL);
furi_check(context != NULL);
furi_thread_flags_set(furi_thread_get_id(context->thread), TotpBtTypeCodeWorkerEventStop);
furi_thread_join(context->thread);
furi_thread_free(context->thread);
Expand All @@ -98,7 +119,7 @@ void totp_bt_type_code_worker_notify(
TotpBtTypeCodeWorkerContext* context,
TotpBtTypeCodeWorkerEvent event,
uint8_t flags) {
furi_assert(context != NULL);
furi_check(context != NULL);
context->flags = flags;
furi_thread_flags_set(furi_thread_get_id(context->thread), event);
}
Expand All @@ -114,19 +135,41 @@ TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init() {
furi_hal_bt_reinit();
furi_delay_ms(200);
bt_keys_storage_set_storage_path(context->bt, HID_BT_KEYS_STORAGE_PATH);

#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
totp_type_code_worker_bt_set_app_mac(&context->bt_mac[0]);
memcpy(
&context->previous_bt_name[0],
furi_hal_bt_get_profile_adv_name(FuriHalBtProfileHidKeyboard),
TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN);
memcpy(
&context->previous_bt_mac[0],
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN);
char new_name[TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN];
snprintf(new_name, sizeof(new_name), "%s TOTP Auth", furi_hal_version_get_name_ptr());
furi_hal_bt_set_profile_adv_name(FuriHalBtProfileHidKeyboard, new_name);
furi_hal_bt_set_profile_mac_addr(FuriHalBtProfileHidKeyboard, context->bt_mac);
#endif

if(!bt_set_profile(context->bt, BtProfileHidKeyboard)) {
FURI_LOG_E(LOGGING_TAG, "Failed to switch BT to keyboard HID profile");
}

furi_hal_bt_start_advertising();

#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
bt_enable_peer_key_update(context->bt);
#endif

context->is_advertising = true;
bt_set_status_changed_callback(context->bt, connection_status_changed_callback, context);

return context;
}

void totp_bt_type_code_worker_free(TotpBtTypeCodeWorkerContext* context) {
furi_assert(context != NULL);
furi_check(context != NULL);

if(context->thread != NULL) {
totp_bt_type_code_worker_stop(context);
Expand All @@ -142,6 +185,11 @@ void totp_bt_type_code_worker_free(TotpBtTypeCodeWorkerContext* context) {
furi_delay_ms(200);
bt_keys_storage_set_default_path(context->bt);

#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
furi_hal_bt_set_profile_adv_name(FuriHalBtProfileHidKeyboard, context->previous_bt_name);
furi_hal_bt_set_profile_mac_addr(FuriHalBtProfileHidKeyboard, context->previous_bt_mac);
#endif

if(!bt_set_profile(context->bt, BtProfileSerial)) {
FURI_LOG_E(LOGGING_TAG, "Failed to switch BT to Serial profile");
}
Expand Down
11 changes: 11 additions & 0 deletions totp/workers/bt_type_code/bt_type_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#include <furi/furi.h>
#include <furi_hal.h>
#include <bt/bt_service/bt.h>
#include "../../features_config.h"

#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
#define TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN 18
#define TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN GAP_MAC_ADDR_SIZE
#endif

typedef uint8_t TotpBtTypeCodeWorkerEvent;

Expand All @@ -16,6 +22,11 @@ typedef struct {
Bt* bt;
bool is_advertising;
bool is_connected;
#if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
uint8_t bt_mac[TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN];
char previous_bt_name[TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN + 1];
uint8_t previous_bt_mac[TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN];
#endif
} TotpBtTypeCodeWorkerContext;

enum TotpBtTypeCodeWorkerEvents {
Expand Down
6 changes: 3 additions & 3 deletions totp/workers/usb_type_code/usb_type_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void totp_type_code_worker_type_code(TotpUsbTypeCodeWorkerContext* contex
}

static int32_t totp_type_code_worker_callback(void* context) {
furi_assert(context);
furi_check(context);
FuriMutex* context_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(context_mutex == NULL) {
return 251;
Expand Down Expand Up @@ -89,7 +89,7 @@ TotpUsbTypeCodeWorkerContext* totp_usb_type_code_worker_start(
}

void totp_usb_type_code_worker_stop(TotpUsbTypeCodeWorkerContext* context) {
furi_assert(context != NULL);
furi_check(context != NULL);
furi_thread_flags_set(furi_thread_get_id(context->thread), TotpUsbTypeCodeWorkerEventStop);
furi_thread_join(context->thread);
furi_thread_free(context->thread);
Expand All @@ -101,7 +101,7 @@ void totp_usb_type_code_worker_notify(
TotpUsbTypeCodeWorkerContext* context,
TotpUsbTypeCodeWorkerEvent event,
uint8_t flags) {
furi_assert(context != NULL);
furi_check(context != NULL);
context->flags = flags;
furi_thread_flags_set(furi_thread_get_id(context->thread), event);
}

0 comments on commit cbf6811

Please sign in to comment.