20#include <radio_tool/fw/fw.hpp>
21#include <radio_tool/fw/cipher/uv3x0.hpp>
22#include <radio_tool/fw/cipher/dm1701.hpp>
23#include <radio_tool/fw/cipher/md380.hpp>
24#include <radio_tool/fw/cipher/md9600.hpp>
40 TYTRadioConfig(
const std::string& model,
const std::string& fw_model,
const std::vector<uint8_t>& c_magic,
const uint8_t*
cipher,
const uint32_t& cipher_l)
73 using namespace std::literals::string_literals;
76 const std::vector<uint8_t> begin = { 0x4f, 0x75, 0x74, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x42, 0x69, 0x6e, 0x00, 0x00 };
78 const std::vector<uint8_t> end = { 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x42, 0x69, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x64 };
85 const std::vector<uint8_t> MD2017_D = { 0x02, 0x19, 0x0c };
86 const std::vector<uint8_t> MD2017_S = { 0x02, 0x18, 0x0c };
87 const std::vector<uint8_t> MD2017_V = { 0x01, 0x19 };
88 const std::vector<uint8_t> MD2017_P = { 0x01, 0x18 };
90 const std::vector<uint8_t> MD9600 = { 0x01, 0x14 };
92 const std::vector<uint8_t> UV3X0_GPS = { 0x02, 0x16, 0x0c };
93 const std::vector<uint8_t> UV3X0 = { 0x02, 0x17, 0x0c };
95 const std::vector<uint8_t> DM1701 = { 0x01, 0x0f };
97 const std::vector<uint8_t> MD390 = { 0x01, 0x10 };
98 const std::vector<uint8_t> MD380 = { 0x01, 0x0d };
99 const std::vector<uint8_t> MD280 = { 0x01, 0x1b };
102 namespace tyt::config
104 const std::vector<TYTRadioConfig> All = {
105 TYTRadioConfig(
"MD2017" ,
"MD-9600", tyt::magic::MD2017_D, cipher::uv3x0, cipher::uv3x0_length),
106 TYTRadioConfig(
"MD2017 GPS" ,
"MD-9600", tyt::magic::MD2017_S, cipher::uv3x0, cipher::uv3x0_length),
107 TYTRadioConfig(
"MD2017" ,
"MD-9600", tyt::magic::MD2017_V, cipher::uv3x0, cipher::uv3x0_length),
108 TYTRadioConfig(
"MD2017 GPS" ,
"MD-9600", tyt::magic::MD2017_P, cipher::uv3x0, cipher::uv3x0_length),
109 TYTRadioConfig(
"MD9600",
"MD-9600", tyt::magic::MD9600, cipher::md9600, cipher::md9600_length),
110 TYTRadioConfig(
"UV3X0 GPS",
"MD-9600", tyt::magic::UV3X0_GPS, cipher::uv3x0, cipher::uv3x0_length),
111 TYTRadioConfig(
"UV3X0",
"MD-9600", tyt::magic::UV3X0, cipher::uv3x0, cipher::uv3x0_length),
112 TYTRadioConfig(
"DM1701",
"DM1701", tyt::magic::DM1701,
cipher::dm1701, cipher::dm1701_length),
113 TYTRadioConfig(
"MD390",
"JST51", tyt::magic::MD390,
cipher::md380, cipher::md380_length),
114 TYTRadioConfig(
"MD380",
"JST51", tyt::magic::MD380,
cipher::md380, cipher::md380_length),
115 TYTRadioConfig(
"MD446",
"JST51", tyt::magic::MD380,
cipher::md380, cipher::md380_length),
116 TYTRadioConfig(
"MD280",
"JST51", tyt::magic::MD280,
cipher::md380, cipher::md380_length)
126 uint32_t n1, n2, n3, n4;
127 uint8_t counter_magic[76];
136 TYTFW(
const std::vector<uint8_t>& cMagic)
140 auto Read(
const std::string& file) ->
void override;
141 auto Write(
const std::string& file) ->
void override;
142 auto ToString()
const->std::string
override;
143 auto Decrypt() ->
void override;
144 auto Encrypt() ->
void override;
159 for (
const auto& r : tyt::config::All)
161 if (r.radio_model == radio)
163 return r.counter_magic;
166 throw std::runtime_error(
"Radio not supported");
175 for (
const auto& r : tyt::config::All)
177 if (r.counter_magic.size() != cm.size())
180 if (std::equal(cm.begin(), cm.end(), r.counter_magic.begin()))
182 return r.radio_model;
185 throw std::runtime_error(
"Radio not supported");
201 static auto Create() -> std::unique_ptr<FirmwareSupport>
203 return std::make_unique<TYTFW>();
207 std::vector<uint8_t> counterMagic;
208 std::string firmware_model, radio_model;
210 static auto ReadHeader(std::ifstream&)->TYTFirmwareHeader;
212 auto ApplyXOR() -> void;