Compare commits

...

17 Commits

Author SHA1 Message Date
Erwin Ried 536d25db64 Update README.md (#2284)
Previous link was reported as ilegitimate store
2024-10-05 18:38:13 +02:00
Erwin Ried eca1db26e4 New sn0ren video about H4M (#2283) 2024-10-05 11:19:22 +02:00
sommermorgentraum 7d96bc4efe Optional sha512 to spread out the final password for rand_pw app (#2281)
* fix issue from #1444

* add hash sha512

* check point 1, with useless init pw usage

* gui

* should be works

* fix warning from sah512 lib

* delete diff file for debugging
2024-10-05 11:19:11 +02:00
Erwin Ried b0c92d9baf Update README.md (#2280)
aliexpress fixed the links for the alternative portapacks (the non opensourcesdrlabs)
2024-10-03 13:43:00 +02:00
Erwin Ried c1af935022 Update README.md (#2279)
Link to OpenSourceSDRLab store
2024-10-03 07:22:21 +02:00
sommermorgentraum e75fb59169 fix issue from #1444 (#2278) 2024-10-02 16:17:40 +02:00
sommermorgentraum 2d1314a3fa fine tune pwd gen app layout (#2277)
* init

* format
2024-10-01 16:16:59 +08:00
Totoo a398ed1634 Random app imp (#2276) 2024-09-30 17:45:13 +02:00
zxkmm 105742acbc add random ext app (#2273)
* copy paste from afsk

* add generate thing

* todo: remove uneeded code

* todo: remove uneeded code

* todo: asycnmsg detect indicate, check way to not use global password

* removed audio

* add log warn modal

* small tune

* remove drunk code

* password var global

* seed as text instead of console

* remove console

* should be almost done

* naming fix

* bitmap now moved to seperate folder, that header i deleted isn't related to firmware

* get cmake format back

* get cmake format back - try2

* try to revert cmake file

* get cmake format back - try3

* get cmake format back - try4

* move to util

* disable amp when launch

* refactor name

* cmake fix

* try to revert cmake file

* init in methods local var

* user another methods to generate

* change pause to flood

* fix log

* fine tune

* clang format

* fix name
2024-09-30 22:13:55 +08:00
zxkmm b43eaa8786 protect serial asyncmsg with indicate to prevent halt (#2272) 2024-09-29 10:19:29 +02:00
gullradriel b19ed5fec5 Looking glass narrow view marker wrap around (#2271)
* allow 1 MHz wide view (because why not?)
* allow marker to wrap around each corner
* added another define for clarity
2024-09-29 01:33:09 +08:00
zxkmm 419bc75d2f add ccache option and transparent color instead of bool (#2269)
* add ccache option and use language helper for proto view app

* add transparent color

* typo

* fix my typo

* fix my typo 2
2024-09-28 14:50:37 +02:00
Totoo b3a0ad018c Limit 50 items per page in sndboard. Maybe solves oom (#2263) 2024-09-28 14:48:32 +02:00
Totoo a21e9ca1af Nav fix, fixes #1197 (#2270)
* Nav fix, fixes #1197
2024-09-26 14:29:35 +02:00
Totoo 20f45e88f3 fix protoview shift, and add comments to languagehelper (#2268) 2024-09-26 09:22:24 +08:00
zxkmm 967506fb97 add pause feat for protoView app (#2267) 2024-09-25 17:45:45 +02:00
zxkmm 24ab2f29fa touch to pop splash (#2260)
* touch to pop

* debug

* have to add another var

* works but since touch screen is laggy, it's tricky

* tune to single touch

* remove debug things

* safer with sleep

* textual

* @HTotoo resolved the sleep issue

* use pop handler in another place (button)
2024-09-23 20:57:15 +02:00
26 changed files with 1198 additions and 81 deletions
+20 -7
View File
@@ -23,6 +23,8 @@ cmake_policy(SET CMP0005 NEW)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/firmware/toolchain-arm-cortex-m.cmake)
option(USE_CCACHE "Enable ccache, please keep an eye on this because sometimes it's not quite stable and generated unusable binary" OFF)
project(portapack-h1)
set(EXPECTED_GCC_VERSION "9.2.1")
@@ -72,13 +74,24 @@ set(HACKRF_CPLD_XSVF_PATH ${HACKRF_PATH}/firmware/cpld/sgpio_if/${HACKRF_CPLD_XS
set(HACKRF_FIRMWARE_DFU_IMAGE ${hackrf_usb_BINARY_DIR}/${HACKRF_FIRMWARE_DFU_FILENAME})
set(HACKRF_FIRMWARE_BIN_IMAGE ${hackrf_usb_BINARY_DIR}/${HACKRF_FIRMWARE_BIN_FILENAME})
# this seems causing some issues (ref. in discord discussions), so temporarily disabled, until figure out the pros and cons and bugs of this tool.
#find_program(CCACHE "ccache")
#if(CCACHE)
# set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
# set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
# set(ENV{CCACHE_SLOPPINESS} pch_defines,time_macros)
#endif(CCACHE)
# this seems causing some issues (ref. in discord discussions), but it sometimes do helps, so you have your choice to use. it's default disabled, unless you use such command:
# cmake -DUSE_CCACHE=ON ..
# `make` or `make -j` or `make -j10` etc
# the default behavior `cmake ..` isn't changed (aka don't use ccache)
message(STATUS "-------v ccache info--------")
if(USE_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_FOUND})
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_FOUND})
message(STATUS "Using ccache, please keep an eye on this because sometimes it's not quite stable and generated unusable binary.\n-- use `cmake -DUSE_CCACHE=OFF ..` to turn off ccache")
else()
message(WARNING "ccache is enabled but not found on the system.")
endif()
else()
message(STATUS "Not using ccache, use `cmake -DUSE_CCACHE=ON ..` to turn on ccache")
endif()
message(STATUS "-------^ ccache info--------")
enable_testing()
add_subdirectory(firmware)
+6 -6
View File
@@ -11,15 +11,15 @@ This is a fork of the [Havoc](https://github.com/furrtek/portapack-havoc/) firmw
[<img src="https://raw.githubusercontent.com/wiki/portapack-mayhem/mayhem-firmware/img/hw_overview_h2_front.png" height="400">](https://github.com/portapack-mayhem/mayhem-firmware/wiki/Hardware-overview) [<img src="https://raw.githubusercontent.com/wiki/portapack-mayhem/mayhem-firmware/img/hw_overview_h2_inside.png" height="400">](https://github.com/portapack-mayhem/mayhem-firmware/wiki/Hardware-overview#portapack-internals)
*[PortaPack H2+HackRF+battery](https://grabify.link/7T28JP) (clone) with a custom [3d printed case](https://github.com/portapack-mayhem/mayhem-firmware/wiki/H2-Enclosure)*
*[PortaPack H2+HackRF+battery](https://grabify.link/ZYYPLB) (clone) with a custom [3d printed case](https://github.com/portapack-mayhem/mayhem-firmware/wiki/H2-Enclosure)*
# What is this?
If you are new to *HackRF+PortaPack+Mayhem*, check these:
[<img alt="Its TOO Easy to Accidentally Do Illegal Stuff with This" src="https://img.youtube.com/vi/OPckpjBSAOw/maxresdefault.jpg" width="700">](https://grabify.link/X4D5TF)
[<img alt="The new HackRF Portapack H4M" src="https://img.youtube.com/vi/onQRdCITmuk/maxresdefault.jpg" width="701">](https://grabify.link/0JUHZ6)
[<img alt="What is the HackRF One Portapack H2+?" src="https://img.youtube.com/vi/alrFbY5vxt4/maxresdefault.jpg" width="230">](https://grabify.link/9UZGEW) [<img alt="Beginner's Guide To The HackRF & Portapak With Mayhem" src="https://img.youtube.com/vi/H-bqdWfbhpg/maxresdefault.jpg" width="230">](https://grabify.link/5MU2VH) [<img alt="HackRF 101 : Everything You Need to Know to Get Started!" src="https://img.youtube.com/vi/xGR_PMD9LeU/maxresdefault.jpg" width="230">](https://grabify.link/C0J6ZR)
[<img alt="Its TOO Easy to Accidentally Do Illegal Stuff with This" src="https://img.youtube.com/vi/OPckpjBSAOw/maxresdefault.jpg" width="172">](https://grabify.link/X4D5TF) [<img alt="What is the HackRF One Portapack H2+?" src="https://img.youtube.com/vi/alrFbY5vxt4/maxresdefault.jpg" width="172">](https://grabify.link/9UZGEW) [<img alt="Beginner's Guide To The HackRF & Portapak With Mayhem" src="https://img.youtube.com/vi/H-bqdWfbhpg/maxresdefault.jpg" width="172">](https://grabify.link/5MU2VH) [<img alt="HackRF 101 : Everything You Need to Know to Get Started!" src="https://img.youtube.com/vi/xGR_PMD9LeU/maxresdefault.jpg" width="172">](https://grabify.link/C0J6ZR)
# Frequently Asked Questions
@@ -27,11 +27,11 @@ This repository expands upon the previous work by many people and aims to consta
## What to buy?
:heavy_check_mark: ![Static Badge](https://img.shields.io/badge/NEW-yellow) The fabulous [PortaPack H4M Mayhem](https://grabify.link/VPMPSL), featuring numerous improvements and accessories. Sold by our friends at OpenSourceSDRLab. Join their giveaways on discord (check the badge on top).
:heavy_check_mark: ![Static Badge](https://img.shields.io/badge/NEW-yellow) The fabulous [PortaPack H4M Mayhem](https://grabify.link/VPMPSL), featuring numerous improvements and accessories. Sold by our friends at [OpenSourceSDRLab](https://grabify.link/99SAMT). Join their giveaways on discord (check the badge on top).
:heavy_check_mark: A recommended one is this [PortaPack H2](https://grabify.link/7T28JP), that includes everything you need with the plastic case "inspired" on [this](https://github.com/portapack-mayhem/mayhem-firmware/wiki/H2-Enclosure).
:heavy_check_mark: A recommended one is this [PortaPack H2](https://grabify.link/ZYYPLB), that includes everything you need with the plastic case "inspired" on [this](https://github.com/portapack-mayhem/mayhem-firmware/wiki/H2-Enclosure).
:heavy_check_mark: Some individuals lean towards the [H2 with a metal enclosure](https://grabify.link/HTDXG5), but its advantages remain debated. Share your insights on our [wiki](https://github.com/portapack-mayhem/mayhem-firmware/wiki/Hardware-overview).
:heavy_check_mark: Some individuals lean towards the [H2 with a metal enclosure](https://grabify.link/XNGTAP), but its advantages remain debated. Share your insights on our [wiki](https://github.com/portapack-mayhem/mayhem-firmware/wiki/Hardware-overview).
:warning: Be cautious , *ask* the seller about compatibility with the latest releases. Look out for the description of the item, if they provide the firmware files for an older version or they have custom setup instructions, this means it might be **NOT compatible**, for example:
+5 -3
View File
@@ -35,6 +35,8 @@ using namespace portapack;
namespace ui {
#define FILE_PER_PAGE 50
bool SoundBoardView::is_active() const {
return (bool)replay_thread;
}
@@ -178,9 +180,9 @@ void SoundBoardView::refresh_list() {
if ((reader->channels() == 1) && ((reader->bits_per_sample() == 8) || (reader->bits_per_sample() == 16))) {
// sounds[c].ms_duration = reader->ms_duration();
// sounds[c].path = u"WAV/" + entry.path().native();
if (count >= (page - 1) * 100 && count < page * 100) {
if (count >= (page - 1) * FILE_PER_PAGE && count < page * FILE_PER_PAGE) {
file_list.push_back(entry.path());
if (file_list.size() == 100) {
if (file_list.size() == FILE_PER_PAGE) {
page++;
break;
}
@@ -225,7 +227,7 @@ void SoundBoardView::refresh_list() {
menu_view.set_highlighted(0); // Refresh
}
if (file_list.size() < 100) {
if (file_list.size() < FILE_PER_PAGE) {
page = 1;
}
}
+15 -5
View File
@@ -58,6 +58,7 @@ EncodersConfigView::EncodersConfigView(
options_enctype.on_change = [this](size_t index, int32_t) {
on_type_change(index);
set_dirty();
};
options_enctype.set_options(enc_options);
@@ -104,7 +105,18 @@ void EncodersConfigView::on_type_change(size_t index) {
// Add new SymFields.
Point pos{2 * 8, 9 * 8};
std::string format_string;
std::string format_string = encoder_def->word_format;
/*important notes of this format_String
* previously before PR#1444, this code using the for loop below to generate the format_string, which MAYBE to prevent showing the S symble.
* but after PR#1444, the entireh of symfield code not compatible with this design anymore.
* however the encoder_def struct itself has a field called word_format, which exactly be avle to use as the format_string,
* because itself is ONLY a hint text, not impact protocol things.
* When you find OOK protocol is broken and see this commit from git blame, please be aware that it's not from here.
* previously me and @cusspvz already found it broken, this commit is just to fix the broken that from PR#1444.
* @zxkmm
*/
uint8_t word_length = encoder_def->word_length;
auto on_change_handler = [this](SymField&) {
generate_frame();
@@ -119,11 +131,9 @@ void EncodersConfigView::on_type_change(size_t index) {
switch (symbol_type) {
case 'A':
symfield->set_symbol_list(encoder_def->address_symbols);
format_string += 'A';
break;
case 'D':
symfield->set_symbol_list(encoder_def->data_symbols);
format_string += 'D';
break;
}
@@ -131,8 +141,8 @@ void EncodersConfigView::on_type_change(size_t index) {
pos += Point{8, 0};
}
// Ugly :( Pad to erase
format_string.append(24 - format_string.size(), ' ');
// cut the S, cuz sync bit isn't in symfield for user to chage/edit.
format_string.erase(std::remove(format_string.begin(), format_string.end(), 'S'), format_string.end());
text_format.set(format_string);
generate_frame();
@@ -98,7 +98,6 @@ rf::Frequency GlassView::get_freq_from_bin_pos(uint8_t pos) {
freq_at_pos = f_center_ini + ((pos - 120) * ((looking_glass_range - ((16 * looking_glass_range) / SPEC_NB_BINS)) / 2)) / (SCREEN_W / 2);
} else
freq_at_pos = f_min + (2 * offset * each_bin_size) + (pos * looking_glass_range) / SCREEN_W;
return freq_at_pos;
}
@@ -257,7 +256,7 @@ void GlassView::on_range_changed() {
bin_length = SCREEN_W;
ignore_dc = 0;
looking_glass_bandwidth = looking_glass_range;
looking_glass_sampling_rate = looking_glass_bandwidth;
looking_glass_sampling_rate = looking_glass_range;
each_bin_size = looking_glass_bandwidth / SCREEN_W;
looking_glass_step = looking_glass_bandwidth;
f_center_ini = f_min + (looking_glass_bandwidth / 2); // Initial center frequency for sweep
@@ -265,7 +264,7 @@ void GlassView::on_range_changed() {
// view is made in multiple pass, use original bin picking
mode = scan_type.selected_index_value();
looking_glass_bandwidth = LOOKING_GLASS_SLICE_WIDTH_MAX;
looking_glass_sampling_rate = LOOKING_GLASS_SLICE_WIDTH_MAX;
looking_glass_sampling_rate = LOOKING_GLASS_MAX_SAMPLERATE;
each_bin_size = LOOKING_GLASS_SLICE_WIDTH_MAX / SPEC_NB_BINS;
if (mode == LOOKING_GLASS_FASTSCAN) {
offset = 2;
@@ -315,8 +314,8 @@ void GlassView::update_min(int32_t v) {
int32_t min_size = steps;
if (locked_range)
min_size = search_span;
if (min_size < 2)
min_size = 2;
if (min_size < 1)
min_size = 1;
if (v > 7200 - min_size) {
v = 7200 - min_size;
}
@@ -332,8 +331,8 @@ void GlassView::update_max(int32_t v) {
int32_t min_size = steps;
if (locked_range)
min_size = search_span;
if (min_size < 2)
min_size = 2;
if (min_size < 1)
min_size = 1;
if (v < min_size) {
v = min_size;
}
@@ -487,7 +486,12 @@ GlassView::GlassView(
range_presets.set_selected_index(preset_index);
field_marker.on_encoder_change = [this](TextField&, EncoderEvent delta) {
marker_pixel_index = clip<uint8_t>(marker_pixel_index + delta, 0, SCREEN_W);
if ((marker_pixel_index + delta) < 0)
marker_pixel_index = marker_pixel_index + delta + SCREEN_W;
else if ((marker_pixel_index + delta) > SCREEN_W)
marker_pixel_index = marker_pixel_index + delta - SCREEN_W;
else
marker_pixel_index = marker_pixel_index + delta;
on_marker_change();
};
@@ -40,6 +40,7 @@
namespace ui {
#define LOOKING_GLASS_SLICE_WIDTH_MAX 20000000
#define LOOKING_GLASS_MAX_SAMPLERATE 20000000
#define MHZ_DIV 1000000
// blanked DC (16 centered bins ignored ) and top left and right (2 bins ignored on each side )
+7
View File
@@ -96,6 +96,12 @@ set(EXTCPPSRC
#sstvtx
external/sstvtx/main.cpp
external/sstvtx/ui_sstvtx.cpp
#random
external/random_password/main.cpp
external/random_password/ui_random_password.cpp
external/random_password/sha512.cpp
external/random_password/sha512.h
)
set(EXTAPPLIST
@@ -122,4 +128,5 @@ set(EXTAPPLIST
adsbtx
morse_tx
sstvtx
random_password
)
+6 -1
View File
@@ -46,6 +46,7 @@ MEMORY
ram_external_app_adsbtx(rwx) : org = 0xADC50000, len = 32k
ram_external_app_morse_tx(rwx) : org = 0xADC60000, len = 32k
ram_external_app_sstvtx(rwx) : org = 0xADC70000, len = 32k
ram_external_app_random_password(rwx) : org = 0xADC80000, len = 32k
}
SECTIONS
@@ -190,6 +191,10 @@ SECTIONS
*(*ui*external_app*sstvtx*);
} > ram_external_app_sstvtx
.external_app_random_password : ALIGN(4) SUBALIGN(4)
{
KEEP(*(.external_app.app_random_password.application_information));
*(*ui*external_app*random_password*);
} > ram_external_app_random_password
}
+41 -15
View File
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek
* Copyright (C) 2024 HTotoo, zxkmm
*
* This file is part of PortaPack.
*
@@ -49,10 +48,12 @@ ProtoView::ProtoView(NavigationView& nav)
&field_vga,
&field_volume,
&field_frequency,
&labels,
&label_zoom,
&label_shift,
&options_zoom,
&number_shift,
&button_reset,
&button_pause,
&waveform,
&waveform2,
&waveform3,
@@ -72,6 +73,10 @@ ProtoView::ProtoView(NavigationView& nav)
button_reset.on_select = [this](Button&) {
reset();
};
button_pause.on_select = [this](Button&) {
set_pause(!paused);
};
set_pause(false); // need to use this to default hide shift functionality
baseband::set_subghzd_config(0, receiver_model.sampling_rate());
audio::set_rate(audio::Rate::Hz_24000);
audio::output::start();
@@ -80,6 +85,7 @@ ProtoView::ProtoView(NavigationView& nav)
void ProtoView::reset() {
cnt = 0;
set_pause(false);
number_shift.set_value(0);
waveform_shift = 0;
for (uint16_t i = 0; i < MAXSIGNALBUFFER; i++) time_buffer[i] = 0;
@@ -134,19 +140,20 @@ void ProtoView::draw() {
drawcnt = 0;
for (uint16_t i = 0; i < MAXDRAWCNT; i++) waveform_buffer[i] = 0; // reset
// add empty data for padding (so you can shift left/nagetive)
for (int32_t i = 0;
i < ((waveform_shift > 0) ? 0 : -waveform_shift) && drawcnt < MAXDRAWCNT; // this is for shift nagetive (left side)
++i) {
waveform_buffer[drawcnt++] = 0;
// add empty data for padding (so you can shift left/negative)
if (waveform_shift < 0) {
for (int32_t i = 0; (i < -1 * waveform_shift) && drawcnt < MAXDRAWCNT; // this is for shift negative (move to right)
++i) {
waveform_buffer[drawcnt++] = 0;
}
}
for (uint16_t i = ((waveform_shift < 0) ? -waveform_shift : 0); // this is for shift positive aka right side
i < MAXSIGNALBUFFER && drawcnt < MAXDRAWCNT; // prevent out of ranging
uint16_t skipped = 0;
uint16_t to_skip = ((waveform_shift > 0) ? waveform_shift : 0); // when >0 it'll skip some to move left
for (uint16_t i = 0;
i < MAXSIGNALBUFFER && drawcnt < MAXDRAWCNT; // prevent out of ranging
++i) {
uint16_t buffer_index = (i + waveform_shift + MAXSIGNALBUFFER) % MAXSIGNALBUFFER;
state = time_buffer[buffer_index] >= 0;
int32_t timeabs = state ? time_buffer[buffer_index] : -1 * time_buffer[buffer_index];
state = time_buffer[i] >= 0;
int32_t timeabs = state ? time_buffer[i] : -1 * time_buffer[i];
int32_t timesize = timeabs / zoom;
if (timesize == 0) {
remain += timeabs;
@@ -164,7 +171,11 @@ void ProtoView::draw() {
remain = 0;
lmax = 0;
for (int32_t ii = 0; ii < timesize && drawcnt < MAXDRAWCNT; ++ii) {
waveform_buffer[drawcnt++] = state;
if (skipped < to_skip) {
skipped++;
} else {
waveform_buffer[drawcnt++] = state;
}
}
}
}
@@ -175,6 +186,7 @@ void ProtoView::add_time(int32_t time) {
}
void ProtoView::on_data(const ProtoViewDataMessage* message) {
if (paused) return;
// filter out invalid ones.
uint16_t start = 0;
uint16_t stop = 0;
@@ -207,6 +219,20 @@ void ProtoView::on_freqchg(int64_t freq) {
field_frequency.set_value(freq);
}
void ProtoView::set_pause(bool pause) {
paused = pause;
if (pause) {
label_shift.hidden(false);
number_shift.hidden(false);
button_pause.set_text(LanguageHelper::currentMessages[LANG_RESUME]);
} else {
label_shift.hidden(true);
number_shift.hidden(true);
button_pause.set_text(LanguageHelper::currentMessages[LANG_PAUSE]);
}
set_dirty();
}
ProtoView::~ProtoView() {
audio::output::stop();
receiver_model.disable();
+12 -3
View File
@@ -74,8 +74,11 @@ class ProtoView : public View {
RxFrequencyField field_frequency{
{0 * 8, 0 * 16},
nav_};
Labels labels{
{{0 * 8, 1 * 16}, "Zoom: ", Theme::getInstance()->fg_light->foreground},
// need to seperate because label shift need to hide independently
Labels label_zoom{
{{0 * 8, 1 * 16}, "Zoom: ", Theme::getInstance()->fg_light->foreground}};
Labels label_shift{
{{0 * 8, 2 * 16}, "Shift: ", Theme::getInstance()->fg_light->foreground}};
OptionsField options_zoom{
@@ -103,6 +106,10 @@ class ProtoView : public View {
{screen_width - 12 * 8, 1 * 16, 96, 24},
LanguageHelper::currentMessages[LANG_RESET]};
Button button_pause{
{screen_width - 12 * 8, 1 * 16 + 24, 96, 24},
LanguageHelper::currentMessages[LANG_PAUSE]};
Waveform waveform{
{0, 8 * 8, 240, 50},
waveform_buffer,
@@ -136,6 +143,7 @@ class ProtoView : public View {
Theme::getInstance()->fg_yellow->foreground};
bool needCntReset = false;
bool paused = false;
int16_t zoom = 1; // one value in ms
int16_t waveform_shift = 0;
@@ -151,6 +159,7 @@ class ProtoView : public View {
void on_data(const ProtoViewDataMessage* message);
void draw();
void draw2();
void set_pause(bool pause);
void reset();
MessageHandlerRegistration message_handler_packet{
@@ -178,4 +187,4 @@ class ProtoView : public View {
} // namespace ui::external_app::protoview
#endif /*__UI_PROTOVIEW_H__*/
#endif /*__UI_PROTOVIEW_H__*/
+82
View File
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2023 Bernd Herzog
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ui.hpp"
#include "ui_random_password.hpp"
#include "ui_navigation.hpp"
#include "external_app.hpp"
namespace ui::external_app::random_password {
void initialize_app(ui::NavigationView& nav) {
nav.push<RandomPasswordView>();
}
} // namespace ui::external_app::random_password
extern "C" {
__attribute__((section(".external_app.app_random_password.application_information"), used)) application_information_t _application_information_random_password = {
/*.memory_location = */ (uint8_t*)0x00000000,
/*.externalAppEntry = */ ui::external_app::random_password::initialize_app,
/*.header_version = */ CURRENT_HEADER_VERSION,
/*.app_version = */ VERSION_MD5,
/*.app_name = */ "Random passwd",
/*.bitmap_data = */ {
0xC0,
0x03,
0xE0,
0x07,
0x30,
0x0C,
0x30,
0x0C,
0x30,
0x0C,
0x30,
0x0C,
0xE0,
0x07,
0xC0,
0x03,
0x80,
0x01,
0x80,
0x01,
0x80,
0x01,
0x80,
0x01,
0x80,
0x07,
0x80,
0x03,
0x80,
0x07,
0x80,
0x01,
},
/*.icon_color = */ ui::Color::yellow().v,
/*.menu_location = */ app_location_t::UTILITIES,
/*.m4_app_tag = portapack::spi_flash::image_tag_afsk_rx */ {'P', 'A', 'F', 'R'},
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
};
}
+156
View File
@@ -0,0 +1,156 @@
/* modified from https://github.com/ulwanski/sha512
* copyright @ulwanski
* */
#include "sha512.h"
namespace ui::external_app::random_password {
const unsigned long long SHA512::sha512_k[80] = // ULL = uint64
{0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL};
void SHA512::transform(const unsigned char* message, unsigned int block_nb) {
uint64 w[80];
uint64 wv[8];
uint64 t1, t2;
const unsigned char* sub_block;
int i, j;
for (i = 0; i < (int)block_nb; i++) {
sub_block = message + (i << 7);
for (j = 0; j < 16; j++) {
SHA2_PACK64(&sub_block[j << 3], &w[j]);
}
for (j = 16; j < 80; j++) {
w[j] = SHA512_F4(w[j - 2]) + w[j - 7] + SHA512_F3(w[j - 15]) + w[j - 16];
}
for (j = 0; j < 8; j++) {
wv[j] = m_h[j];
}
for (j = 0; j < 80; j++) {
t1 = wv[7] + SHA512_F2(wv[4]) + SHA2_CH(wv[4], wv[5], wv[6]) + sha512_k[j] + w[j];
t2 = SHA512_F1(wv[0]) + SHA2_MAJ(wv[0], wv[1], wv[2]);
wv[7] = wv[6];
wv[6] = wv[5];
wv[5] = wv[4];
wv[4] = wv[3] + t1;
wv[3] = wv[2];
wv[2] = wv[1];
wv[1] = wv[0];
wv[0] = t1 + t2;
}
for (j = 0; j < 8; j++) {
m_h[j] += wv[j];
}
}
}
void SHA512::init() {
m_h[0] = 0x6a09e667f3bcc908ULL;
m_h[1] = 0xbb67ae8584caa73bULL;
m_h[2] = 0x3c6ef372fe94f82bULL;
m_h[3] = 0xa54ff53a5f1d36f1ULL;
m_h[4] = 0x510e527fade682d1ULL;
m_h[5] = 0x9b05688c2b3e6c1fULL;
m_h[6] = 0x1f83d9abfb41bd6bULL;
m_h[7] = 0x5be0cd19137e2179ULL;
m_len = 0;
m_tot_len = 0;
}
void SHA512::update(const unsigned char* message, unsigned int len) {
unsigned int block_nb;
unsigned int new_len, rem_len, tmp_len;
const unsigned char* shifted_message;
tmp_len = SHA384_512_BLOCK_SIZE - m_len;
rem_len = len < tmp_len ? len : tmp_len;
memcpy(&m_block[m_len], message, rem_len);
if (m_len + len < SHA384_512_BLOCK_SIZE) {
m_len += len;
return;
}
new_len = len - rem_len;
block_nb = new_len / SHA384_512_BLOCK_SIZE;
shifted_message = message + rem_len;
transform(m_block, 1);
transform(shifted_message, block_nb);
rem_len = new_len % SHA384_512_BLOCK_SIZE;
memcpy(m_block, &shifted_message[block_nb << 7], rem_len);
m_len = rem_len;
m_tot_len += (block_nb + 1) << 7;
}
void SHA512::final(unsigned char* digest) {
unsigned int block_nb;
unsigned int pm_len;
unsigned int len_b;
int i;
block_nb = 1 + ((SHA384_512_BLOCK_SIZE - 17) < (m_len % SHA384_512_BLOCK_SIZE));
len_b = (m_tot_len + m_len) << 3;
pm_len = block_nb << 7;
memset(m_block + m_len, 0, pm_len - m_len);
m_block[m_len] = 0x80;
SHA2_UNPACK32(len_b, m_block + pm_len - 4);
transform(m_block, block_nb);
for (i = 0; i < 8; i++) {
SHA2_UNPACK64(m_h[i], &digest[i << 3]);
}
}
std::string sha512(const void* dat, size_t len) {
unsigned char digest[SHA512::DIGEST_SIZE];
memset(digest, 0, SHA512::DIGEST_SIZE);
SHA512 ctx = SHA512();
ctx.init();
ctx.update((const unsigned char*)dat, len);
ctx.final(digest);
char buf[2 * SHA512::DIGEST_SIZE + 1];
buf[2 * SHA512::DIGEST_SIZE] = 0;
for (unsigned int i = 0; i < SHA512::DIGEST_SIZE; i++)
sprintf(buf + i * 2, "%02x", digest[i]);
return std::string(buf);
}
std::string sha512(std::string input) {
return sha512((const unsigned char*)input.c_str(), (size_t)input.length());
}
} // namespace ui::external_app::random_password
+76
View File
@@ -0,0 +1,76 @@
/* modified from https://github.com/ulwanski/sha512
* copyright @ulwanski
* */
#ifndef SHA512_H
#define SHA512_H
#include <string>
#include <cstring>
#include <fstream>
#define _CRT_SECURE_NO_WARNINGS
std::string sha512(const void* dat, size_t len);
std::string sha512(std::string input);
namespace ui::external_app::random_password {
class SHA512 {
protected:
typedef unsigned char uint8;
typedef unsigned long uint32;
typedef unsigned long long uint64;
const static uint64 sha512_k[];
static const unsigned int SHA384_512_BLOCK_SIZE = (1024 / 8);
public:
void init();
void update(const unsigned char* message, unsigned int len);
void final(unsigned char* digest);
static const unsigned int DIGEST_SIZE = (512 / 8);
protected:
void transform(const unsigned char* message, unsigned int block_nb);
unsigned int m_tot_len;
unsigned int m_len;
unsigned char m_block[2 * SHA384_512_BLOCK_SIZE];
uint64 m_h[8];
};
std::string sha512(std::string input);
#define SHA2_SHFR(x, n) (x >> n)
#define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
#define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n)))
#define SHA2_CH(x, y, z) ((x & y) ^ (~x & z))
#define SHA2_MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
#define SHA512_F1(x) (SHA2_ROTR(x, 28) ^ SHA2_ROTR(x, 34) ^ SHA2_ROTR(x, 39))
#define SHA512_F2(x) (SHA2_ROTR(x, 14) ^ SHA2_ROTR(x, 18) ^ SHA2_ROTR(x, 41))
#define SHA512_F3(x) (SHA2_ROTR(x, 1) ^ SHA2_ROTR(x, 8) ^ SHA2_SHFR(x, 7))
#define SHA512_F4(x) (SHA2_ROTR(x, 19) ^ SHA2_ROTR(x, 61) ^ SHA2_SHFR(x, 6))
#define SHA2_UNPACK32(x, str) \
{ \
*((str) + 3) = (uint8)((x)); \
*((str) + 2) = (uint8)((x) >> 8); \
*((str) + 1) = (uint8)((x) >> 16); \
*((str) + 0) = (uint8)((x) >> 24); \
}
#define SHA2_UNPACK64(x, str) \
{ \
*((str) + 7) = (uint8)((x)); \
*((str) + 6) = (uint8)((x) >> 8); \
*((str) + 5) = (uint8)((x) >> 16); \
*((str) + 4) = (uint8)((x) >> 24); \
*((str) + 3) = (uint8)((x) >> 32); \
*((str) + 2) = (uint8)((x) >> 40); \
*((str) + 1) = (uint8)((x) >> 48); \
*((str) + 0) = (uint8)((x) >> 56); \
}
#define SHA2_PACK64(str, x) \
{ \
*(x) = ((uint64) * ((str) + 7)) | ((uint64) * ((str) + 6) << 8) | ((uint64) * ((str) + 5) << 16) | ((uint64) * ((str) + 4) << 24) | ((uint64) * ((str) + 3) << 32) | ((uint64) * ((str) + 2) << 40) | ((uint64) * ((str) + 1) << 48) | ((uint64) * ((str) + 0) << 56); \
}
} // namespace ui::external_app::random_password
#endif
@@ -0,0 +1,397 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek
* Copyright (C) 2024 zxkmm
* Copyright (C) 2024 HTotoo
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/* Notes about safety/randomness:
* - Radio data is from nature, so if it's evenly tiled in space, it's random enough, but usually it's not
* - A unsafe point is the freq that fetch data is from LCG (from Cpp STL) using time as seed, but should be spread out by later random calculation
* - A unsafe point is the init data is still using LCG to generate, but used following methods to spread out:
* - - Radio data
* - - save a buffer of seeds and generate char by char, this cover all the possible chars combination
* - - Rollout with teo seeds and get a final char, this spread out again
* - - Hash out the generated password and spread out again if you choose. SHA-512 is proven very spreading out in random space by math
* - But still, this isn't meant to become a TRNG generator, don't use at critical/high safety requited/important system, this FOSS has absolutely no warranty
*/
#include "ui_random_password.hpp"
#include "ui_modemsetup.hpp"
#include "modems.hpp"
#include "rtc_time.hpp"
#include "baseband_api.hpp"
#include "string_format.hpp"
#include "portapack_persistent_memory.hpp"
#include "file_path.hpp"
#include "sha512.h"
using namespace portapack;
using namespace modems;
using namespace ui;
namespace ui::external_app::random_password {
void RandomPasswordLogger::log_raw_data(const std::string& data) {
log_file.write_entry(data);
}
void RandomPasswordView::focus() {
button_refresh.focus();
}
RandomPasswordView::RandomPasswordView(NavigationView& nav)
: nav_{nav} {
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
add_children({&rssi,
&channel,
&field_rf_amp,
&field_lna,
&field_vga,
&field_frequency,
&check_log,
&button_modem_setup,
&labels,
&text_generated_passwd,
&text_char_type_hints,
&check_digits,
&check_latin_lower,
&check_latin_upper,
&check_punctuation,
&check_show_seeds,
&check_auto_send,
&button_refresh,
&button_show_qr,
&button_flood,
&button_send,
&field_digits,
&field_method,
&check_allow_confusable_chars,
&text_seed,
&progressbar});
// no idea what's these, i copied from afsk rx app and they seems needed'
auto def_bell202 = &modem_defs[0];
persistent_memory::set_modem_baudrate(def_bell202->baudrate);
serial_format_t serial_format;
serial_format.data_bits = 7;
serial_format.parity = EVEN;
serial_format.stop_bits = 1;
serial_format.bit_order = LSB_FIRST;
persistent_memory::set_serial_format(serial_format);
progressbar.set_max(MAX_DIGITS * 2);
check_log.set_value(logging);
check_log.on_select = [this](Checkbox&, bool v) {
if (v) {
nav_.display_modal(
"Warning",
"Sure?\n"
"this will save all generated\n"
"password to sdcard\n"
"in plain text\n"
"those which generated before\n"
"you check me, will lost",
YESNO,
[this, v](bool c) {
if (c) {
logging = v;
} else {
check_log.set_value(false);
// this is needed to check back to false cuz when trigger by human, the check to true already happened
// this blocked interface so won't accidently saved even if user checked but selected no later here,
// but take care of here if in the future implemented ticking/auto/batch save etc
}
});
} else {
logging = v;
}
};
button_modem_setup.on_select = [&nav](Button&) { // copied from afsk rx app
nav.push<ModemSetupView>();
};
check_digits.on_select = [this](Checkbox&, bool) {
this->new_password();
};
check_latin_lower.on_select = [this](Checkbox&, bool) {
this->new_password();
};
check_latin_upper.on_select = [this](Checkbox&, bool) {
this->new_password();
};
check_punctuation.on_select = [this](Checkbox&, bool) {
this->new_password();
};
check_allow_confusable_chars.on_select = [this](Checkbox&, bool) {
this->new_password();
};
button_refresh.on_select = [this](Button&) {
this->set_random_freq();
this->new_password();
};
button_show_qr.on_select = [this, &nav](Button&) {
nav.push<QRCodeView>(password.data());
};
button_flood.on_select = [this](Button&) {
if (flooding) {
flooding = false;
button_flood.set_text(LanguageHelper::currentMessages[LANG_FLOOD]);
} else {
flooding = true;
button_flood.set_text(LanguageHelper::currentMessages[LANG_STOP]);
}
};
button_send.on_select = [this, &nav](Button&) {
async_prev_val = portapack::async_tx_enabled;
portapack::async_tx_enabled = true;
UsbSerialAsyncmsg::asyncmsg(password);
portapack::async_tx_enabled = async_prev_val;
};
field_digits.on_change = [this](int32_t) {
clean_buffer();
this->new_password();
};
/// v check defauly val init
check_digits.set_value(true);
check_latin_lower.set_value(true);
check_latin_upper.set_value(true);
check_punctuation.set_value(true);
check_show_seeds.set_value(true);
field_digits.set_value(16);
field_method.set_by_value(Method::RADIO_LCG_ROLL_HASH);
///^ check defauly val init
logger = std::make_unique<RandomPasswordLogger>();
if (logger)
logger->append(logs_dir / u"random.TXT");
// Auto-configure modem for LCR RX (will be removed later), copied from afsk rx app
baseband::set_afsk(persistent_memory::modem_baudrate(), 8, 0, false);
receiver_model.enable();
receiver_model.set_rf_amp(false);
set_random_freq();
new_password();
}
void RandomPasswordView::on_data(uint32_t value, bool is_data) {
if (is_data) {
seed = static_cast<unsigned int>(value);
text_seed.set(to_string_dec_uint(check_show_seeds.value() ? seed : 0));
/// v feed deque
seeds_deque.push_back(value);
if (seeds_deque.size() > MAX_DIGITS * 2) {
seeds_deque.pop_front();
}
///^ feed deque
progressbar.set_value(seeds_deque.size());
if (flooding && seeds_deque.size() >= MAX_DIGITS * 2) {
new_password();
}
} else {
text_generated_passwd.set("Baudrate estimation: ~");
text_char_type_hints.set(to_string_dec_uint(value));
}
}
void RandomPasswordView::clean_buffer() {
seeds_deque = {};
}
void RandomPasswordView::on_freqchg(int64_t freq) {
field_frequency.set_value(freq);
}
void RandomPasswordView::set_random_freq() {
std::srand(LPC_RTC->CTIME0);
// this is only for seed to visit random freq, the radio is still real random
auto random_freq = 100000000 + (std::rand() % 900000000); // 100mhz to 1ghz
receiver_model.set_target_frequency(random_freq);
field_frequency.set_value(random_freq);
}
void RandomPasswordView::new_password() {
if (seeds_deque.size() < MAX_DIGITS * 2) {
seeds_buffer_not_full = true;
text_generated_passwd.set("wait seeds buffer full");
text_char_type_hints.set("then press generate");
return;
}
password = "";
std::string charset = "";
std::string char_type_hints = "";
std::string initial_password = "";
int password_length = field_digits.value();
/// charset worker
if (check_digits.value())
charset += "0123456789";
if (check_latin_lower.value())
charset += "abcdefghijklmnopqrstuvwxyz";
if (check_latin_upper.value())
charset += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (check_punctuation.value())
charset += ".,-!?";
if (!check_allow_confusable_chars.value()) {
charset.erase(std::remove_if(charset.begin(), charset.end(),
[](char c) { return c == '0' || c == 'O' || c == 'o' || c == '1' || c == 'l'; }),
charset.end());
}
if (charset.empty()) {
text_generated_passwd.set("generate failed,");
text_char_type_hints.set("select at least 1 type");
return;
}
/// roll worker
for (int i = 0; i < password_length * 2; i += 2) {
unsigned int seed = seeds_deque[i];
std::srand(seed);
uint8_t rollnum = (uint8_t)(seeds_deque[i + 1] % 128);
uint8_t nu = 0;
for (uint8_t o = 0; o < rollnum; ++o) nu = std::rand();
nu++;
char c = charset[std::rand() % charset.length()];
initial_password += c;
}
// hash worker
std::string hashed_password = sha512(initial_password);
std::vector<char> password_chars(password_length);
for (int i = 0; i < password_length; i++) {
unsigned int index = std::stoul(hashed_password.substr(i * 2, 2), nullptr, 16) % charset.length(); // result from 0 to charset.length()-1,should be very evenly tiled in the charset space
password_chars[i] = charset[index];
}
/// hint text worker
for (char c : password_chars) {
password += c;
if (std::isdigit(c)) {
char_type_hints += "1";
} else if (std::islower(c)) {
char_type_hints += "a";
} else if (std::isupper(c)) {
char_type_hints += "A";
} else {
char_type_hints += ",";
}
}
/// decision worker
switch (field_method.selected_index_value()) {
case Method::RADIO_LCG_ROLL:
password = initial_password;
break;
case Method::RADIO_LCG_ROLL_HASH:
break;
default:
break;
}
/// give out result worker
text_generated_passwd.set(password);
text_char_type_hints.set(char_type_hints);
paint_password_hints();
if (logger && logging) {
str_log += generate_log_line();
logger->log_raw_data(str_log);
str_log = "";
}
if (check_auto_send.value() || flooding) {
async_prev_val = portapack::async_tx_enabled;
portapack::async_tx_enabled = true;
UsbSerialAsyncmsg::asyncmsg(password);
portapack::async_tx_enabled = async_prev_val;
}
clean_buffer();
}
void RandomPasswordView::paint_password_hints() {
Painter painter;
const int char_width = 8;
const int char_height = 16;
const int start_y = 6 * char_height;
const int rect_height = 4;
for (size_t i = 0; i < password.length(); i++) {
char c = password[i];
Color color;
if (std::isdigit(c)) {
color = Color::red();
} else if (std::islower(c)) {
color = Color::green();
} else if (std::isupper(c)) {
color = Color::blue();
} else {
color = Color::white();
}
painter.fill_rectangle(
{{static_cast<int>(i) * char_width, start_y},
{char_width, rect_height}},
color);
}
}
std::string RandomPasswordView::generate_log_line() {
std::string seeds_set = "";
for (auto seed : seeds_deque) {
seeds_set += std::to_string(seed);
seeds_set += " ";
}
std::string line = "\npassword=" + password +
"\nseeds=" + seeds_set +
"\n";
return line;
}
RandomPasswordView::~RandomPasswordView() {
receiver_model.disable();
baseband::shutdown();
}
} // namespace ui::external_app::random_password
@@ -0,0 +1,235 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek
* Copyright (C) 2024 zxkmm
* Copyright (C) 2024 HTotoo
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __UI_RANDOM_PASSWORD_H__
#define __UI_RANDOM_PASSWORD_H__
#define MAX_DIGITS 30
#include "ui.hpp"
#include "ui_language.hpp"
#include "ui_navigation.hpp"
#include "ui_receiver.hpp"
#include "ui_freq_field.hpp"
#include "ui_record_view.hpp"
#include "app_settings.hpp"
#include "radio_state.hpp"
#include "log_file.hpp"
#include "utility.hpp"
#include "ui_qrcode.hpp"
#include "usb_serial_asyncmsg.hpp"
#include "sha512.h"
#include <deque>
#include <string>
using namespace ui;
namespace ui::external_app::random_password {
enum Method {
RADIO_LCG_ROLL,
RADIO_LCG_ROLL_HASH,
};
class RandomPasswordLogger {
public:
Optional<File::Error> append(const std::filesystem::path& filename) {
return log_file.append(filename);
}
void log_raw_data(const std::string& data);
private:
LogFile log_file{};
};
class RandomPasswordView : public View {
public:
RandomPasswordView(NavigationView& nav);
~RandomPasswordView();
void focus() override;
std::string title() const override { return "R.passwd"; };
private:
unsigned int seed = 0; // extern void srand (unsigned int __seed) __THROW;
std::string password = "";
std::deque<unsigned int> seeds_deque = {0};
bool seeds_buffer_not_full = true;
bool in_benchmark = false;
bool flooding = false;
bool logging = false;
bool async_prev_val = false;
std::string str_log{""};
void on_data(uint32_t value, bool is_data);
void clean_buffer();
void new_password();
std::string generate_log_line();
void paint_password_hints();
NavigationView& nav_;
RxRadioState radio_state_{};
app_settings::SettingsManager settings_{
"rx_passgen", app_settings::Mode::RX};
Labels labels{
{{0 * 8, 0 * 16}, "------------seeds-------------", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 3 * 16}, "-----------password-----------", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 7 * 16 - 2}, "digits:", Theme::getInstance()->fg_light->foreground},
{{screen_width / 2, 7 * 16 - 2}, "method:", Theme::getInstance()->fg_light->foreground},
};
RFAmpField field_rf_amp{
{13 * 8, 1 * 16}};
LNAGainField field_lna{
{15 * 8, 1 * 16}};
VGAGainField field_vga{
{18 * 8, 1 * 16}};
RSSI rssi{
{21 * 8, 1 * 16 + 0, 6 * 8, 4}};
Channel channel{
{21 * 8, 1 * 16 + 5, 6 * 8, 4}};
RxFrequencyField field_frequency{
{0 * 8, 1 * 16},
nav_};
Button button_modem_setup{
{screen_width - 12 * 8, 2 * 16 - 1, 96, 16 + 2},
LanguageHelper::currentMessages[LANG_MODEM_SETUP]};
Text text_seed{
{0, 2 * 16, 10 * 8, 16},
"0000000000"};
ProgressBar progressbar{
{10 * 8 + 2, 2 * 16, screen_width - 96 - (10 * 8 + 4) - 1, 16}};
Text text_generated_passwd{
{0, 4 * 16, screen_width, 16},
"000000000000000000000000000000"};
Text text_char_type_hints{
{0, 5 * 16 + 4, screen_width, 16},
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"};
Checkbox check_show_seeds{
{17 * 8, 8 * 16},
6,
"Show seed"};
Checkbox check_auto_send{
{1 * 8, 8 * 16},
20,
"Auto send"};
Checkbox check_punctuation{
{17 * 8, 12 * 16},
6,
".,-!?"};
Checkbox check_allow_confusable_chars{
{1 * 8, 10 * 16},
20,
"0 O o 1 l"};
Checkbox check_digits{
{1 * 8, 12 * 16},
3,
"123"};
Checkbox check_latin_lower{
{1 * 8, 14 * 16},
3,
"abc"};
Checkbox check_latin_upper{
{17 * 8, 14 * 16},
3,
"ABC"};
Checkbox check_log{
{17 * 8, 10 * 16},
3,
LanguageHelper::currentMessages[LANG_SAVE]};
Button button_flood{
{0 * 8, 15 * 16 + 18, screen_width / 2, 22},
LanguageHelper::currentMessages[LANG_FLOOD]};
Button button_send{
{screen_width / 2 + 2, 15 * 16 + 18, screen_width / 2 - 2, 22},
"Send pwd"};
Button button_refresh{
{0 * 8, 17 * 16 + 10, screen_width / 2, 22},
"Generate"};
Button button_show_qr{
{screen_width / 2 + 2, 17 * 16 + 10, screen_width / 2 - 2, 22},
LanguageHelper::currentMessages[LANG_SHOWQR]};
NumberField field_digits{
{0 + (sizeof("digits:") - 1) * 8, 7 * 16 - 2},
2,
{1, 30},
1,
' '};
OptionsField field_method{
{(screen_width / 2) + (sizeof("method:") - 1) * 8, 7 * 16 - 2},
sizeof("R+L+R+H"),
{{"R+L+R", Method::RADIO_LCG_ROLL},
{"R+L+R+H", Method::RADIO_LCG_ROLL_HASH}}};
void on_data_afsk(const AFSKDataMessage& message);
std::unique_ptr<RandomPasswordLogger> logger{};
MessageHandlerRegistration message_handler_packet{
Message::ID::AFSKData,
[this](Message* const p) {
const auto message = static_cast<const AFSKDataMessage*>(p);
this->on_data(message->value, message->is_data);
}};
MessageHandlerRegistration message_handler_freqchg{
Message::ID::FreqChangeCommand,
[this](Message* const p) {
const auto message = static_cast<const FreqChangeCommandMessage*>(p);
this->on_freqchg(message->freq);
}};
void on_freqchg(int64_t freq);
void set_random_freq();
};
} // namespace ui::external_app::random_password
#endif /*__UI_RANDOM_PASSWORD_H__*/
+38 -7
View File
@@ -722,8 +722,8 @@ void NavigationView::update_view() {
auto top_view = top.view.get();
add_child(top_view);
top_view->set_parent_rect({{0, 0}, size()});
auto newSize = (is_top()) ? Size{size().width(), size().height() - 16} : size(); // if top(), then there is the info bar at the bottom, so leave space for it
top_view->set_parent_rect({{0, 0}, newSize});
focus();
set_dirty();
@@ -996,17 +996,48 @@ void BMPView::focus() {
button_done.focus();
}
BMPView::BMPView(NavigationView& nav) {
BMPView::BMPView(NavigationView& nav)
: nav_(nav) {
add_children({&button_done});
button_done.on_select = [this, &nav](Button&) {
nav.pop();
button_done.on_select = [this](Button&) {
handle_pop();
};
}
void BMPView::paint(Painter&) {
if (!portapack::display.drawBMP2({0, 0}, splash_dot_bmp))
portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, true);
portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, (const uint8_t[]){0x29, 0x18, 0x16});
}
bool BMPView::on_touch(const TouchEvent event) {
/* the event thing were resolved by HTotoo, talked here https://discord.com/channels/719669764804444213/956561375155589192/1287756910950486027
* the touch screen policy can be better, talked here https://discord.com/channels/719669764804444213/956561375155589192/1198926225897443328
*/
if (!nav_.is_valid()) {
return false;
}
switch (event.type) {
case TouchEvent::Type::Start:
return true;
case TouchEvent::Type::End:
handle_pop();
return true;
default:
break;
}
return false;
}
void BMPView::handle_pop() {
if (nav_.is_valid()) {
nav_.pop();
}
}
/* NotImplementedView ****************************************************/
@@ -1072,7 +1103,7 @@ ModalMessageView::ModalMessageView(
}
void ModalMessageView::paint(Painter& painter) {
if (!compact) portapack::display.drawBMP({100, 48}, modal_warning_bmp, true);
if (!compact) portapack::display.drawBMP({100, 48}, modal_warning_bmp, (const uint8_t[]){0, 0, 0});
// Break lines.
auto lines = split_string(message_, '\n');
+4
View File
@@ -343,7 +343,11 @@ class BMPView : public View {
void paint(Painter&) override;
void focus() override;
bool on_touch(const TouchEvent event) override;
void handle_pop();
private:
NavigationView& nav_;
Button button_done{
{240, 0, 1, 1},
""};
+3 -1
View File
@@ -37,6 +37,8 @@ class USBSerial {
void on_channel_closed();
void setEventDispatcher(EventDispatcher* ed) { _eventDispatcher = ed; }
bool serial_connected() { return connected; }
private:
void enable_xtal();
void disable_pll0();
@@ -51,4 +53,4 @@ class USBSerial {
EventDispatcher* _eventDispatcher = NULL;
};
} // namespace portapack
} // namespace portapack
+16 -15
View File
@@ -23,6 +23,7 @@
*/
#include "usb_serial_asyncmsg.hpp"
#include "usb_serial.hpp"
/// value
// to_string_bin/ to_string_decimal/ to_string_hex/ to_string_hex_array/ to_string_dec_uint/ to_string_dec_int etc seems usellss so i didn't add them here
@@ -30,7 +31,7 @@
template <>
void UsbSerialAsyncmsg::asyncmsg<int64_t>(const int64_t& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
@@ -38,7 +39,7 @@ void UsbSerialAsyncmsg::asyncmsg<int64_t>(const int64_t& data) {
template <>
void UsbSerialAsyncmsg::asyncmsg<int32_t>(const int32_t& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
@@ -46,7 +47,7 @@ void UsbSerialAsyncmsg::asyncmsg<int32_t>(const int32_t& data) {
template <>
void UsbSerialAsyncmsg::asyncmsg<int16_t>(const int16_t& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
@@ -54,7 +55,7 @@ void UsbSerialAsyncmsg::asyncmsg<int16_t>(const int16_t& data) {
template <>
void UsbSerialAsyncmsg::asyncmsg<int8_t>(const int8_t& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
@@ -62,7 +63,7 @@ void UsbSerialAsyncmsg::asyncmsg<int8_t>(const int8_t& data) {
template <>
void UsbSerialAsyncmsg::asyncmsg<uint8_t>(const uint8_t& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
@@ -70,7 +71,7 @@ void UsbSerialAsyncmsg::asyncmsg<uint8_t>(const uint8_t& data) {
template <>
void UsbSerialAsyncmsg::asyncmsg<uint16_t>(const uint16_t& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
@@ -78,7 +79,7 @@ void UsbSerialAsyncmsg::asyncmsg<uint16_t>(const uint16_t& data) {
template <>
void UsbSerialAsyncmsg::asyncmsg<uint32_t>(const uint32_t& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
@@ -86,7 +87,7 @@ void UsbSerialAsyncmsg::asyncmsg<uint32_t>(const uint32_t& data) {
template <>
void UsbSerialAsyncmsg::asyncmsg<uint64_t>(const uint64_t& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_dec_int(data).c_str());
@@ -94,7 +95,7 @@ void UsbSerialAsyncmsg::asyncmsg<uint64_t>(const uint64_t& data) {
template <>
void UsbSerialAsyncmsg::asyncmsg<float>(const float& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", to_string_decimal(data, 7).c_str());
@@ -105,7 +106,7 @@ void UsbSerialAsyncmsg::asyncmsg<float>(const float& data) {
template <>
// usage: UsbSerialAsyncmsg::asyncmsg(path);
void UsbSerialAsyncmsg::asyncmsg<std::filesystem::path>(const std::filesystem::path& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
std::string path_str = data.string();
@@ -114,7 +115,7 @@ void UsbSerialAsyncmsg::asyncmsg<std::filesystem::path>(const std::filesystem::p
template <>
void UsbSerialAsyncmsg::asyncmsg<std::filesystem::path::string_type>(const std::filesystem::path::string_type& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
std::string str_data(data.begin(), data.end());
@@ -127,7 +128,7 @@ void UsbSerialAsyncmsg::asyncmsg<std::filesystem::path::string_type>(const std::
template <>
// usage: UsbSerialAsyncmsg::asyncmsg(str);
void UsbSerialAsyncmsg::asyncmsg<std::string>(const std::string& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data.c_str());
@@ -136,7 +137,7 @@ void UsbSerialAsyncmsg::asyncmsg<std::string>(const std::string& data) {
// string literal AKA char[]
// usage: UsbSerialAsyncmsg::asyncmsg("abc");
void UsbSerialAsyncmsg::asyncmsg(const char* data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data);
@@ -146,8 +147,8 @@ void UsbSerialAsyncmsg::asyncmsg(const char* data) {
template <>
// usage: UsbSerialAsyncmsg::asyncmsg(true);
void UsbSerialAsyncmsg::asyncmsg<bool>(const bool& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
chprintf((BaseSequentialStream*)&SUSBD1, "%s\r\n", data ? "true" : "false");
}
}
+1 -1
View File
@@ -61,7 +61,7 @@ class UsbSerialAsyncmsg {
// ussgae: UsbSerialAsyncmsg::asyncmsg(vec);
template <typename VECTORCOVER>
void UsbSerialAsyncmsg::asyncmsg(const std::vector<VECTORCOVER>& data) {
if (!portapack::async_tx_enabled) {
if (!portapack::async_tx_enabled || !portapack::usb_serial.serial_connected()) {
return;
}
for (const auto& item : data) {
+19 -5
View File
@@ -344,7 +344,20 @@ void ILI9341::render_box(const ui::Point p, const ui::Size s, const ui::Color* l
}
// RLE_4 BMP loader (delta not implemented)
void ILI9341::drawBMP(const ui::Point p, const uint8_t* bitmap, const bool transparency) {
/* draw transparent, pass transparent color as arg, usage inline anonymous obj
* portapack::display.drawBMP({100, 100}, foo_bmp, (const uint8_t[]){41, 24, 22}); // dec, out of {255, 255, 255}
* portapack::display.drawBMP({100, 100}, foo_bmp, (const uint8_t[]){0x29, 0x18, 0x16}); //hex out of {0xFF, 0xFF, 0xFF}
*
* draw transparent, pass transparent color as arg, usage pass uint8_t[] obj
* const uint8_t c[] = {41, 24, 22}; or const uint8_t c[3] = {0x29, 0x18, 0x16};
* portapack::display.drawBMP({100, 100}, foo_bmp, c);
*
* don't draw transparent, pass nullptr as arg, usage
* portapack::display.drawBMP({100, 100}, foo_bmp, nullptr);
*
* if your image use RLE compress as transparency methods, pass any valid color as arg, it doesn't matter (like the modal bmp. TODO: write RLE transparency generator)
* */
void ILI9341::drawBMP(const ui::Point p, const uint8_t* bitmap, const uint8_t* transparency_color) {
const bmp_header_t* bmp_header = (const bmp_header_t*)bitmap;
uint32_t data_idx;
uint8_t by, c, count, transp_idx = 0;
@@ -362,12 +375,13 @@ void ILI9341::drawBMP(const ui::Point p, const uint8_t* bitmap, const bool trans
// Convert palette and find pure magenta index (alpha color key) rgb dec(41,24,22)
for (c = 0; c < 16; c++) {
palette[c] = ui::Color(bmp_palette->color[c].R, bmp_palette->color[c].G, bmp_palette->color[c].B);
if ((bmp_palette->color[c].R == 0x29) &&
(bmp_palette->color[c].G == 0x18) &&
(bmp_palette->color[c].B == 0x16)) transp_idx = c;
if (transparency_color &&
(bmp_palette->color[c].R == transparency_color[0]) &&
(bmp_palette->color[c].G == transparency_color[1]) &&
(bmp_palette->color[c].B == transparency_color[2])) transp_idx = c;
}
if (!transparency) {
if (!transparency_color) {
py = bmp_header->height + 16;
do {
by = bitmap[data_idx++];
+1 -1
View File
@@ -62,7 +62,7 @@ class ILI9341 {
const ui::Color background);
void draw_pixel(const ui::Point p, const ui::Color color);
void drawBMP(const ui::Point p, const uint8_t* bitmap, const bool transparency);
void drawBMP(const ui::Point p, const uint8_t* bitmap, const uint8_t* transparency_color);
bool drawBMP2(const ui::Point p, const std::filesystem::path& file);
void render_line(const ui::Point p, const uint8_t count, const ui::Color* line_buffer);
void render_box(const ui::Point p, const ui::Size s, const ui::Color* line_buffer);
+3 -1
View File
@@ -1,7 +1,9 @@
#include "ui_language.hpp"
const char* LanguageHelper::englishMessages[] = {"OK", "Cancel", "Error", "Modem setup", "Debug", "Log", "Done", "Start", "Stop", "Scan", "Clear", "Ready", "Data:", "Loop", "Reset"};
// use the exact position in this array! the enum's value is the identifier. Best to add to the end
const char* LanguageHelper::englishMessages[] = {"OK", "Cancel", "Error", "Modem setup", "Debug", "Log", "Done", "Start", "Stop", "Scan", "Clear", "Ready", "Data:", "Loop", "Reset", "Pause", "Resume", "Flood", "Show QR", "Save"};
// multi language support will changes (not in use for now)
const char** LanguageHelper::currentMessages = englishMessages;
void LanguageHelper::setLanguage(LanguageList lang) {
+40 -2
View File
@@ -1,10 +1,43 @@
/*
* Copyright (C) 2024 HTotoo
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/*
The purpose of this: when creating an ext app it's address will be changed. But the compiler doesn't know this, so when it optimizes literals it can remove something from one ext app, that is included in the other, to save space.
But when we want to run this app, it won't find the literal at the fake address, so the best case we'll get just garbage or nothing instead of the string.
So we must use this Language helper that stores the literals in the fw instead of any ext app, so it'll be always available.
In the first run we must move those string literal here what are not so unique, like "OK".
*/
#ifndef __UI_LANGUAGE_H__
#define __UI_LANGUAGE_H__
// For future multi language support
enum LanguageList {
ENGLISH,
};
// Add an element to this enum when you fill a new value.
// Then add the string literal to the LanguageHelper::englishMessages at the exact position where the enum points to (usualy to the end)
enum LangConsts {
LANG_OK,
LANG_CANCEL,
@@ -20,12 +53,17 @@ enum LangConsts {
LANG_READY,
LANG_DATADP,
LANG_LOOP,
LANG_RESET
LANG_RESET,
LANG_PAUSE,
LANG_RESUME,
LANG_FLOOD,
LANG_SHOWQR,
LANG_SAVE
};
class LanguageHelper {
public:
static void setLanguage(LanguageList lang);
static void setLanguage(LanguageList lang); // changes the pointer to the currently used language literal container. not used yet.
static const char* getMessage(LangConsts msg);
static const char** currentMessages; // expose, so can link directly too
+2
View File
@@ -156,6 +156,8 @@ class Widget {
};
class View : public Widget {
// unlike Paint class, our Y ignored the top bar;
// so when you draw some of us as Y = 0, it would be exact below the top bar, instead of overlapped with top bar
public:
View() {
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB