2015-11-20 07:59:09 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2016-02-04 10:27:53 +01:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-11-20 07:59:09 +01:00
|
|
|
*
|
|
|
|
* 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_loadmodule.hpp"
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
|
|
|
|
#include "ff.h"
|
2016-02-04 10:27:53 +01:00
|
|
|
#include "event_m0.hpp"
|
2015-11-20 07:59:09 +01:00
|
|
|
#include "hackrf_gpio.hpp"
|
|
|
|
#include "portapack.hpp"
|
2016-01-05 20:17:55 +01:00
|
|
|
#include "portapack_shared_memory.hpp"
|
2015-11-20 07:59:09 +01:00
|
|
|
#include "hackrf_hal.hpp"
|
2016-02-04 10:27:53 +01:00
|
|
|
#include "string_format.hpp"
|
2015-11-20 07:59:09 +01:00
|
|
|
|
2016-04-28 14:59:14 +02:00
|
|
|
#include "ui_rds.hpp"
|
|
|
|
#include "ui_xylos.hpp"
|
2016-05-13 09:34:15 +02:00
|
|
|
#include "ui_epar.hpp"
|
2016-04-28 14:59:14 +02:00
|
|
|
#include "ui_lcr.hpp"
|
2016-05-09 20:42:20 +02:00
|
|
|
#include "analog_audio_app.hpp"
|
|
|
|
#include "ui_soundboard.hpp"
|
2016-04-28 14:59:14 +02:00
|
|
|
#include "ui_debug.hpp"
|
2016-05-11 12:45:03 +02:00
|
|
|
#include "ui_closecall.hpp"
|
2016-05-09 20:42:20 +02:00
|
|
|
#include "ui_audiotx.hpp"
|
2016-07-25 16:21:27 +02:00
|
|
|
#include "ui_jammer.hpp"
|
2016-04-28 14:59:14 +02:00
|
|
|
|
2015-11-20 07:59:09 +01:00
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-02-06 23:19:28 +01:00
|
|
|
using namespace portapack;
|
2015-11-20 07:59:09 +01:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void LoadModuleView::focus() {
|
2023-05-19 08:16:05 +12:00
|
|
|
button_ok.focus();
|
2015-11-20 07:59:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadModuleView::on_show() {
|
2023-05-19 08:16:05 +12:00
|
|
|
char md5_signature[16];
|
|
|
|
uint8_t c;
|
|
|
|
|
|
|
|
memcpy(md5_signature, (const void*)(0x10087FF0), 16);
|
|
|
|
for (c = 0; c < 16; c++) {
|
|
|
|
if (md5_signature[c] != _hash[c]) break;
|
|
|
|
}
|
|
|
|
// text_info.set(to_string_hex(*((unsigned int*)0x10087FF0), 8));
|
|
|
|
|
|
|
|
if (c == 16) {
|
|
|
|
text_info.set("Module already loaded :)");
|
|
|
|
_mod_loaded = true;
|
|
|
|
} else {
|
|
|
|
text_info.set("Loading module");
|
|
|
|
loadmodule();
|
|
|
|
}
|
2016-01-05 20:17:55 +01:00
|
|
|
}
|
|
|
|
|
2016-02-04 10:27:53 +01:00
|
|
|
int LoadModuleView::load_image() {
|
2023-05-19 08:16:05 +12:00
|
|
|
const char magic[6] = {'P', 'P', 'M', ' ', 0x02, 0x00};
|
|
|
|
UINT bw;
|
|
|
|
uint8_t i;
|
|
|
|
uint32_t cnt;
|
|
|
|
char md5sum[16];
|
|
|
|
FILINFO modinfo;
|
|
|
|
FIL modfile;
|
|
|
|
DIR rootdir;
|
|
|
|
FRESULT res;
|
|
|
|
|
|
|
|
// Scan SD card root directory for files with the right MD5 fingerprint at the right location
|
|
|
|
if (f_opendir(&rootdir, "/") == FR_OK) {
|
|
|
|
for (;;) {
|
|
|
|
res = f_readdir(&rootdir, &modinfo);
|
|
|
|
if (res != FR_OK || modinfo.fname[0] == 0) break; // Reached last file, abort
|
|
|
|
// Only care about files with .bin extension
|
|
|
|
if ((!(modinfo.fattrib & AM_DIR)) && (modinfo.fname[9] == 'B') && (modinfo.fname[10] == 'I') && (modinfo.fname[11] == 'N')) {
|
|
|
|
res = f_open(&modfile, modinfo.fname, FA_OPEN_EXISTING | FA_READ);
|
|
|
|
if (res != FR_OK) return 0;
|
|
|
|
// Magic bytes and version check
|
|
|
|
f_read(&modfile, &md5sum, 6, &bw);
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
if (md5sum[i] != magic[i]) break;
|
|
|
|
if (i == 6) {
|
|
|
|
f_lseek(&modfile, 26);
|
|
|
|
f_read(&modfile, &md5sum, 16, &bw);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
if (md5sum[i] != _hash[i]) break;
|
|
|
|
// f_read can't read more than 512 bytes at a time ?
|
|
|
|
if (i == 16) {
|
|
|
|
f_lseek(&modfile, 512);
|
|
|
|
for (cnt = 0; cnt < 64; cnt++) {
|
|
|
|
if (f_read(&modfile, reinterpret_cast<void*>(portapack::memory::map::m4_code.base() + (cnt * 512)), 512, &bw)) return 0;
|
|
|
|
}
|
|
|
|
f_close(&modfile);
|
|
|
|
f_closedir(&rootdir);
|
|
|
|
LPC_RGU->RESET_CTRL[0] = (1 << 13);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f_close(&modfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f_closedir(&rootdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2016-02-04 10:27:53 +01:00
|
|
|
}
|
|
|
|
|
2016-01-05 20:17:55 +01:00
|
|
|
void LoadModuleView::loadmodule() {
|
2023-05-19 08:16:05 +12:00
|
|
|
// baseband::shutdown();
|
|
|
|
|
|
|
|
/*EventDispatcher::message_map().register_handler(Message::ID::ReadyForSwitch,
|
|
|
|
[this](Message* const p) {
|
|
|
|
(void)p;*/
|
|
|
|
if (load_image()) {
|
|
|
|
text_infob.set("Module loaded :)");
|
|
|
|
_mod_loaded = true;
|
|
|
|
} else {
|
|
|
|
text_info.set("Module not found :(");
|
|
|
|
_mod_loaded = false;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
//);
|
2015-11-20 07:59:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LoadModuleView::LoadModuleView(
|
2023-05-19 08:16:05 +12:00
|
|
|
NavigationView& nav,
|
|
|
|
const char* hash,
|
|
|
|
ViewID viewid) {
|
|
|
|
add_children({&text_info,
|
|
|
|
&text_infob,
|
|
|
|
&button_ok});
|
|
|
|
|
|
|
|
_hash = hash;
|
|
|
|
|
|
|
|
button_ok.on_select = [this, &nav, viewid](Button&) {
|
|
|
|
nav.pop();
|
|
|
|
if (_mod_loaded == true) {
|
|
|
|
if (viewid == AudioTX) nav.push<AudioTXView>();
|
|
|
|
if (viewid == Xylos) nav.push<XylosView>();
|
|
|
|
if (viewid == EPAR) nav.push<EPARView>();
|
|
|
|
if (viewid == LCR) nav.push<LCRView>();
|
|
|
|
if (viewid == SoundBoard) nav.push<SoundBoardView>();
|
|
|
|
if (viewid == AnalogAudio) nav.push<AnalogAudioView>();
|
|
|
|
if (viewid == RDS) nav.push<RDSView>();
|
|
|
|
if (viewid == CloseCall) nav.push<CloseCallView>();
|
|
|
|
if (viewid == Receiver) nav.push<ReceiverMenuView>();
|
|
|
|
if (viewid == Jammer) nav.push<JammerView>();
|
|
|
|
}
|
|
|
|
};
|
2015-11-20 07:59:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|