subghz marantec protocol implement crc verification and add manually

fix crc function, add valid/invalid display (does not affect TX) and use new crc sum in add manually menu
This commit is contained in:
MX
2025-07-06 18:42:16 +03:00
parent 6ae1ce6861
commit 43b35019ed
6 changed files with 99 additions and 4 deletions

View File

@@ -126,6 +126,8 @@ typedef enum {
SetTypeHollarm_433,
SetTypeReversRB2_433,
SetTypeMarantec24_868,
SetTypeMarantec_433,
SetTypeMarantec_868,
SetTypeLinear_300_00,
// SetTypeNeroSketch, //Deleted in OFW
// SetTypeNeroRadio, //Deleted in OFW

View File

@@ -6,6 +6,7 @@
#include <lib/subghz/protocols/secplus_v1.h>
#include <lib/subghz/protocols/secplus_v2.h>
#include <lib/subghz/protocols/nice_flor_s.h>
#include <lib/subghz/protocols/marantec.h>
#include <flipper_format/flipper_format_i.h>
#include <lib/toolbox/stream/stream.h>
@@ -395,3 +396,27 @@ void subghz_txrx_gen_serial_gangqi(uint64_t* result_key) {
// serial | const_and_button
*result_key = (serial << 18) | (const_and_button << 10) | (bytesum << 2);
}
void subghz_txrx_gen_key_marantec(uint64_t* result_key) {
uint64_t randkey = (uint64_t)rand();
uint32_t serial = (uint32_t)((randkey) & 0xFFFFF);
// 0x130 is the constant
// 0x4 is the button code
// 0x86 is the serial constant
// serial is random value that we pre generate above
// At the end we will put the crc sum
uint64_t full_key_no_crc = (uint64_t)((uint64_t)0x130 << 40 | (uint64_t)serial << 20 |
(uint64_t)0x4 << 16 | (uint64_t)0x86 << 8);
uint8_t tdata[6] = {
full_key_no_crc >> 48,
full_key_no_crc >> 40,
full_key_no_crc >> 32,
full_key_no_crc >> 24,
full_key_no_crc >> 16,
full_key_no_crc >> 8};
uint8_t crc = subghz_protocol_marantec_crc8(tdata, sizeof(tdata));
*result_key = ((full_key_no_crc >> 8) << 8) | crc;
}

View File

@@ -153,3 +153,10 @@ bool subghz_txrx_gen_secplus_v1_protocol(
* @return uint64_t if success
*/
void subghz_txrx_gen_serial_gangqi(uint64_t* result_key);
/**
* Generate key for Marantec protocol
*
* @param result_key Pointer to a uint64_t where the key will be stored
*/
void subghz_txrx_gen_key_marantec(uint64_t* result_key);

View File

@@ -71,6 +71,8 @@ static const char* submenu_names[SetTypeMAX] = {
[SetTypeHollarm_433] = "Hollarm 433MHz",
[SetTypeReversRB2_433] = "Revers RB2 433MHz",
[SetTypeMarantec24_868] = "Marantec24 868MHz",
[SetTypeMarantec_433] = "Marantec 433MHz",
[SetTypeMarantec_868] = "Marantec 868MHz",
[SetTypeBETT_433] = "BETT 433MHz",
[SetTypeLinear_300_00] = "Linear 300MHz",
// [SetTypeNeroSketch] = "Nero Sketch", // Deleted in OFW
@@ -192,6 +194,9 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
uint64_t gangqi_key;
subghz_txrx_gen_serial_gangqi(&gangqi_key);
uint64_t marantec_key;
subghz_txrx_gen_key_marantec(&marantec_key);
GenInfo gen_info = {0};
switch(event.event) {
case SetTypePricenton433:
@@ -360,6 +365,28 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
.data.bits = 24,
.data.te = 0};
break;
case SetTypeMarantec_433:
gen_info = (GenInfo){
.type = GenData,
.mod = "AM650",
.freq = 433920000,
.data.name =
SUBGHZ_PROTOCOL_MARANTEC_NAME, // Button code is 0x4 and crc sum to the end
.data.key = marantec_key,
.data.bits = 49,
.data.te = 0};
break;
case SetTypeMarantec_868:
gen_info = (GenInfo){
.type = GenData,
.mod = "AM650",
.freq = 868350000,
.data.name =
SUBGHZ_PROTOCOL_MARANTEC_NAME, // Button code is 0x4 and crc sum to the end
.data.key = marantec_key,
.data.bits = 49,
.data.te = 0};
break;
case SetTypeFaacSLH_433:
gen_info = (GenInfo){
.type = GenFaacSLH,