2022-03-03 09:48:56 +00:00
|
|
|
#include "faac_slh.h"
|
2022-04-08 21:29:15 +00:00
|
|
|
#include "../subghz_keystore.h"
|
|
|
|
#include <m-string.h>
|
|
|
|
#include <m-array.h>
|
|
|
|
#include "keeloq_common.h"
|
2022-03-03 09:48:56 +00:00
|
|
|
#include "../blocks/const.h"
|
|
|
|
#include "../blocks/decoder.h"
|
|
|
|
#include "../blocks/encoder.h"
|
|
|
|
#include "../blocks/generic.h"
|
|
|
|
#include "../blocks/math.h"
|
|
|
|
|
2022-07-27 12:58:32 +00:00
|
|
|
#define TAG "SubGhzProtocolFaacSLH"
|
2022-03-03 09:48:56 +00:00
|
|
|
|
|
|
|
static const SubGhzBlockConst subghz_protocol_faac_slh_const = {
|
|
|
|
.te_short = 255,
|
|
|
|
.te_long = 595,
|
|
|
|
.te_delta = 100,
|
|
|
|
.min_count_bit_for_found = 64,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SubGhzProtocolDecoderFaacSLH {
|
|
|
|
SubGhzProtocolDecoderBase base;
|
|
|
|
|
|
|
|
SubGhzBlockDecoder decoder;
|
|
|
|
SubGhzBlockGeneric generic;
|
2022-04-08 21:29:15 +00:00
|
|
|
|
|
|
|
SubGhzKeystore* keystore;
|
|
|
|
const char* manufacture_name;
|
2022-03-03 09:48:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SubGhzProtocolEncoderFaacSLH {
|
|
|
|
SubGhzProtocolEncoderBase base;
|
|
|
|
|
|
|
|
SubGhzProtocolBlockEncoder encoder;
|
|
|
|
SubGhzBlockGeneric generic;
|
2022-04-08 21:29:15 +00:00
|
|
|
|
|
|
|
SubGhzKeystore* keystore;
|
|
|
|
const char* manufacture_name;
|
2022-03-03 09:48:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FaacSLHDecoderStepReset = 0,
|
|
|
|
FaacSLHDecoderStepFoundPreambula,
|
|
|
|
FaacSLHDecoderStepSaveDuration,
|
|
|
|
FaacSLHDecoderStepCheckDuration,
|
|
|
|
} FaacSLHDecoderStep;
|
|
|
|
|
|
|
|
const SubGhzProtocolDecoder subghz_protocol_faac_slh_decoder = {
|
|
|
|
.alloc = subghz_protocol_decoder_faac_slh_alloc,
|
|
|
|
.free = subghz_protocol_decoder_faac_slh_free,
|
|
|
|
|
|
|
|
.feed = subghz_protocol_decoder_faac_slh_feed,
|
|
|
|
.reset = subghz_protocol_decoder_faac_slh_reset,
|
|
|
|
|
|
|
|
.get_hash_data = subghz_protocol_decoder_faac_slh_get_hash_data,
|
|
|
|
.serialize = subghz_protocol_decoder_faac_slh_serialize,
|
|
|
|
.deserialize = subghz_protocol_decoder_faac_slh_deserialize,
|
|
|
|
.get_string = subghz_protocol_decoder_faac_slh_get_string,
|
|
|
|
};
|
|
|
|
|
|
|
|
const SubGhzProtocolEncoder subghz_protocol_faac_slh_encoder = {
|
2022-04-08 23:25:39 +00:00
|
|
|
.alloc = subghz_protocol_encoder_faac_slh_alloc,
|
|
|
|
.free = subghz_protocol_encoder_faac_slh_free,
|
2022-03-03 09:48:56 +00:00
|
|
|
|
2022-04-08 23:25:39 +00:00
|
|
|
.deserialize = subghz_protocol_encoder_faac_slh_deserialize,
|
|
|
|
.stop = subghz_protocol_encoder_faac_slh_stop,
|
|
|
|
.yield = subghz_protocol_encoder_faac_slh_yield,
|
2022-03-03 09:48:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SubGhzProtocol subghz_protocol_faac_slh = {
|
|
|
|
.name = SUBGHZ_PROTOCOL_FAAC_SLH_NAME,
|
|
|
|
.type = SubGhzProtocolTypeDynamic,
|
|
|
|
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_868 | SubGhzProtocolFlag_AM |
|
2022-04-08 23:37:08 +00:00
|
|
|
SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save |
|
|
|
|
SubGhzProtocolFlag_Send,
|
2022-03-03 09:48:56 +00:00
|
|
|
|
|
|
|
.decoder = &subghz_protocol_faac_slh_decoder,
|
|
|
|
.encoder = &subghz_protocol_faac_slh_encoder,
|
|
|
|
};
|
|
|
|
|
2022-04-08 23:25:39 +00:00
|
|
|
/**
|
|
|
|
* Analysis of received data
|
|
|
|
* @param instance Pointer to a SubGhzBlockGeneric* instance
|
|
|
|
* @param keystore Pointer to a SubGhzKeystore* instance
|
|
|
|
* @param manufacture_name
|
|
|
|
*/
|
2022-06-24 10:01:41 +00:00
|
|
|
static void subghz_protocol_faac_slh_check_remote_controller(
|
|
|
|
SubGhzBlockGeneric* instance,
|
|
|
|
SubGhzKeystore* keystore,
|
|
|
|
const char** manufacture_name);
|
2022-04-08 23:25:39 +00:00
|
|
|
|
|
|
|
void* subghz_protocol_encoder_faac_slh_alloc(SubGhzEnvironment* environment) {
|
|
|
|
SubGhzProtocolEncoderFaacSLH* instance = malloc(sizeof(SubGhzProtocolEncoderFaacSLH));
|
|
|
|
|
|
|
|
instance->base.protocol = &subghz_protocol_faac_slh;
|
|
|
|
instance->generic.protocol_name = instance->base.protocol->name;
|
|
|
|
instance->keystore = subghz_environment_get_keystore(environment);
|
|
|
|
|
|
|
|
instance->encoder.repeat = 10;
|
|
|
|
instance->encoder.size_upload = 256;
|
|
|
|
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
|
2022-08-17 20:33:41 +00:00
|
|
|
instance->encoder.is_running = false;
|
2022-04-08 23:25:39 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_protocol_encoder_faac_slh_free(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzProtocolEncoderFaacSLH* instance = context;
|
|
|
|
free(instance->encoder.upload);
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
2022-04-26 09:38:21 +00:00
|
|
|
static bool subghz_protocol_faac_slh_gen_data(SubGhzProtocolEncoderFaacSLH* instance) {
|
2022-04-08 23:25:39 +00:00
|
|
|
instance->generic.cnt++;
|
2022-04-24 19:50:48 +00:00
|
|
|
uint32_t fix = instance->generic.serial << 4 | instance->generic.btn;
|
2022-04-08 23:25:39 +00:00
|
|
|
uint32_t hop = 0;
|
|
|
|
uint32_t decrypt = 0;
|
|
|
|
uint64_t man = 0;
|
|
|
|
int res = 0;
|
|
|
|
char fixx[8] = {};
|
|
|
|
int shiftby = 32;
|
2022-06-24 10:01:41 +00:00
|
|
|
for(int i = 0; i < 8; i++) {
|
2022-04-08 23:25:39 +00:00
|
|
|
fixx[i] = (fix >> (shiftby -= 4)) & 0xF;
|
|
|
|
}
|
2022-06-24 10:01:41 +00:00
|
|
|
if((instance->generic.cnt % 2) == 0) {
|
2022-07-26 18:09:31 +00:00
|
|
|
decrypt = fixx[6] << 28 | fixx[7] << 24 | fixx[5] << 20 |
|
|
|
|
(instance->generic.cnt & 0xFFFFF);
|
2022-06-24 10:01:41 +00:00
|
|
|
} else {
|
2022-07-26 18:09:31 +00:00
|
|
|
decrypt = fixx[2] << 28 | fixx[3] << 24 | fixx[4] << 20 |
|
|
|
|
(instance->generic.cnt & 0xFFFFF);
|
2022-04-08 23:25:39 +00:00
|
|
|
}
|
|
|
|
for
|
|
|
|
M_EACH(manufacture_code, *subghz_keystore_get_data(instance->keystore), SubGhzKeyArray_t) {
|
|
|
|
res = strcmp(string_get_cstr(manufacture_code->name), instance->manufacture_name);
|
|
|
|
if(res == 0) {
|
|
|
|
switch(manufacture_code->type) {
|
|
|
|
case KEELOQ_LEARNING_FAAC:
|
|
|
|
//FAAC Learning
|
2022-06-24 10:01:41 +00:00
|
|
|
man = subghz_protocol_keeloq_common_faac_learning(
|
|
|
|
instance->generic.seed, manufacture_code->key);
|
2022-04-08 23:25:39 +00:00
|
|
|
hop = subghz_protocol_keeloq_common_encrypt(decrypt, man);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(hop) {
|
|
|
|
instance->generic.data = (uint64_t)fix << 32 | hop;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-18 21:32:25 +00:00
|
|
|
bool subghz_protocol_faac_slh_create_data(
|
|
|
|
void* context,
|
|
|
|
FlipperFormat* flipper_format,
|
|
|
|
uint32_t serial,
|
|
|
|
uint8_t btn,
|
2022-07-17 05:05:09 +00:00
|
|
|
uint32_t cnt,
|
2022-04-18 21:32:25 +00:00
|
|
|
uint32_t seed,
|
|
|
|
const char* manufacture_name,
|
2022-07-27 12:58:32 +00:00
|
|
|
SubGhzPresetDefinition* preset) {
|
2022-06-24 10:01:41 +00:00
|
|
|
furi_assert(context);
|
2022-07-26 18:09:31 +00:00
|
|
|
// roguemaster don't steal!!!
|
2022-06-24 10:01:41 +00:00
|
|
|
SubGhzProtocolEncoderFaacSLH* instance = context;
|
|
|
|
instance->generic.serial = serial;
|
|
|
|
instance->generic.btn = btn;
|
2022-07-17 05:05:09 +00:00
|
|
|
instance->generic.cnt = (cnt & 0xFFFFF);
|
2022-06-24 10:01:41 +00:00
|
|
|
instance->generic.seed = seed;
|
|
|
|
instance->manufacture_name = manufacture_name;
|
|
|
|
instance->generic.data_count_bit = 64;
|
|
|
|
bool res = subghz_protocol_faac_slh_gen_data(instance);
|
|
|
|
if(res) {
|
2022-07-26 18:09:31 +00:00
|
|
|
res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
2022-06-24 10:01:41 +00:00
|
|
|
}
|
|
|
|
return res;
|
2022-04-18 21:32:25 +00:00
|
|
|
}
|
|
|
|
|
2022-04-08 23:25:39 +00:00
|
|
|
/**
|
|
|
|
* Generating an upload from data.
|
|
|
|
* @param instance Pointer to a SubGhzProtocolEncoderFaacSLH instance
|
|
|
|
* @return true On success
|
|
|
|
*/
|
2022-06-24 10:01:41 +00:00
|
|
|
static bool subghz_protocol_encoder_faac_slh_get_upload(SubGhzProtocolEncoderFaacSLH* instance) {
|
2022-04-08 23:25:39 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
|
2022-04-26 09:38:21 +00:00
|
|
|
subghz_protocol_faac_slh_gen_data(instance);
|
2022-04-08 23:25:39 +00:00
|
|
|
size_t index = 0;
|
|
|
|
size_t size_upload = 2 + (instance->generic.data_count_bit * 2);
|
|
|
|
if(size_upload > instance->encoder.size_upload) {
|
|
|
|
FURI_LOG_E(TAG, "Size upload exceeds allocated encoder buffer.");
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
instance->encoder.size_upload = size_upload;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Send header
|
2022-04-13 14:15:36 +00:00
|
|
|
instance->encoder.upload[index++] =
|
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_faac_slh_const.te_long * 2);
|
|
|
|
instance->encoder.upload[index++] =
|
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_faac_slh_const.te_long * 2);
|
2022-04-08 23:25:39 +00:00
|
|
|
|
|
|
|
//Send key data
|
|
|
|
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
|
|
|
|
if(bit_read(instance->generic.data, i - 1)) {
|
|
|
|
//send bit 1
|
|
|
|
instance->encoder.upload[index++] =
|
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_faac_slh_const.te_long);
|
|
|
|
instance->encoder.upload[index++] =
|
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_faac_slh_const.te_short);
|
|
|
|
} else {
|
|
|
|
//send bit 0
|
|
|
|
instance->encoder.upload[index++] =
|
|
|
|
level_duration_make(true, (uint32_t)subghz_protocol_faac_slh_const.te_short);
|
|
|
|
instance->encoder.upload[index++] =
|
|
|
|
level_duration_make(false, (uint32_t)subghz_protocol_faac_slh_const.te_long);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool subghz_protocol_encoder_faac_slh_deserialize(void* context, FlipperFormat* flipper_format) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzProtocolEncoderFaacSLH* instance = context;
|
|
|
|
bool res = false;
|
|
|
|
do {
|
|
|
|
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
|
|
|
FURI_LOG_E(TAG, "Deserialize error");
|
|
|
|
break;
|
|
|
|
}
|
2022-05-21 02:02:12 +00:00
|
|
|
uint8_t seed_data[sizeof(uint32_t)] = {0};
|
|
|
|
for(size_t i = 0; i < sizeof(uint32_t); i++) {
|
|
|
|
seed_data[sizeof(uint32_t) - i - 1] = (instance->generic.seed >> i * 8) & 0xFF;
|
|
|
|
}
|
|
|
|
if(!flipper_format_read_hex(flipper_format, "Seed", seed_data, sizeof(uint32_t))) {
|
|
|
|
FURI_LOG_E(TAG, "Missing Seed");
|
|
|
|
break;
|
|
|
|
}
|
2022-06-24 10:01:41 +00:00
|
|
|
instance->generic.seed = seed_data[0] << 24 | seed_data[1] << 16 | seed_data[2] << 8 |
|
|
|
|
seed_data[3];
|
2022-04-08 23:25:39 +00:00
|
|
|
|
|
|
|
subghz_protocol_faac_slh_check_remote_controller(
|
2022-04-26 09:38:21 +00:00
|
|
|
&instance->generic, instance->keystore, &instance->manufacture_name);
|
2022-06-24 10:01:41 +00:00
|
|
|
|
2022-04-08 23:25:39 +00:00
|
|
|
//optional parameter parameter
|
|
|
|
flipper_format_read_uint32(
|
|
|
|
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
|
|
|
|
|
|
|
|
subghz_protocol_encoder_faac_slh_get_upload(instance);
|
|
|
|
|
|
|
|
if(!flipper_format_rewind(flipper_format)) {
|
|
|
|
FURI_LOG_E(TAG, "Rewind error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
uint8_t key_data[sizeof(uint64_t)] = {0};
|
|
|
|
for(size_t i = 0; i < sizeof(uint64_t); i++) {
|
|
|
|
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF;
|
|
|
|
}
|
|
|
|
if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
|
|
|
|
FURI_LOG_E(TAG, "Unable to add Key");
|
|
|
|
break;
|
|
|
|
}
|
2022-06-24 10:01:41 +00:00
|
|
|
|
2022-08-17 20:33:41 +00:00
|
|
|
instance->encoder.is_running = true;
|
2022-04-08 23:25:39 +00:00
|
|
|
|
|
|
|
res = true;
|
|
|
|
} while(false);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_protocol_encoder_faac_slh_stop(void* context) {
|
|
|
|
SubGhzProtocolEncoderFaacSLH* instance = context;
|
2022-08-17 20:33:41 +00:00
|
|
|
instance->encoder.is_running = false;
|
2022-04-08 23:25:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LevelDuration subghz_protocol_encoder_faac_slh_yield(void* context) {
|
|
|
|
SubGhzProtocolEncoderFaacSLH* instance = context;
|
|
|
|
|
2022-08-17 20:33:41 +00:00
|
|
|
if(instance->encoder.repeat == 0 || !instance->encoder.is_running) {
|
|
|
|
instance->encoder.is_running = false;
|
2022-04-08 23:25:39 +00:00
|
|
|
return level_duration_reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
LevelDuration ret = instance->encoder.upload[instance->encoder.front];
|
|
|
|
|
|
|
|
if(++instance->encoder.front == instance->encoder.size_upload) {
|
|
|
|
instance->encoder.repeat--;
|
|
|
|
instance->encoder.front = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void* subghz_protocol_decoder_faac_slh_alloc(SubGhzEnvironment* environment) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(environment);
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzProtocolDecoderFaacSLH* instance = malloc(sizeof(SubGhzProtocolDecoderFaacSLH));
|
|
|
|
instance->base.protocol = &subghz_protocol_faac_slh;
|
|
|
|
instance->generic.protocol_name = instance->base.protocol->name;
|
2022-04-08 21:29:15 +00:00
|
|
|
instance->keystore = subghz_environment_get_keystore(environment);
|
2022-03-03 09:48:56 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_protocol_decoder_faac_slh_free(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzProtocolDecoderFaacSLH* instance = context;
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_protocol_decoder_faac_slh_reset(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzProtocolDecoderFaacSLH* instance = context;
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepReset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_protocol_decoder_faac_slh_feed(void* context, bool level, uint32_t duration) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzProtocolDecoderFaacSLH* instance = context;
|
|
|
|
|
|
|
|
switch(instance->decoder.parser_step) {
|
|
|
|
case FaacSLHDecoderStepReset:
|
|
|
|
if((level) && (DURATION_DIFF(duration, subghz_protocol_faac_slh_const.te_long * 2) <
|
|
|
|
subghz_protocol_faac_slh_const.te_delta * 3)) {
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepFoundPreambula;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FaacSLHDecoderStepFoundPreambula:
|
|
|
|
if((!level) && (DURATION_DIFF(duration, subghz_protocol_faac_slh_const.te_long * 2) <
|
|
|
|
subghz_protocol_faac_slh_const.te_delta * 3)) {
|
|
|
|
//Found Preambula
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepSaveDuration;
|
|
|
|
instance->decoder.decode_data = 0;
|
|
|
|
instance->decoder.decode_count_bit = 0;
|
|
|
|
} else {
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepReset;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FaacSLHDecoderStepSaveDuration:
|
|
|
|
if(level) {
|
2022-05-06 13:37:10 +00:00
|
|
|
if(duration >= ((uint32_t)subghz_protocol_faac_slh_const.te_short * 3 +
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz_protocol_faac_slh_const.te_delta)) {
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepFoundPreambula;
|
2022-08-01 12:24:21 +00:00
|
|
|
if(instance->decoder.decode_count_bit ==
|
2022-03-03 09:48:56 +00:00
|
|
|
subghz_protocol_faac_slh_const.min_count_bit_for_found) {
|
|
|
|
instance->generic.data = instance->decoder.decode_data;
|
|
|
|
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
|
|
|
|
|
|
|
|
if(instance->base.callback)
|
|
|
|
instance->base.callback(&instance->base, instance->base.context);
|
|
|
|
}
|
|
|
|
instance->decoder.decode_data = 0;
|
|
|
|
instance->decoder.decode_count_bit = 0;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
instance->decoder.te_last = duration;
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepCheckDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepReset;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FaacSLHDecoderStepCheckDuration:
|
|
|
|
if(!level) {
|
|
|
|
if((DURATION_DIFF(instance->decoder.te_last, subghz_protocol_faac_slh_const.te_short) <
|
|
|
|
subghz_protocol_faac_slh_const.te_delta) &&
|
|
|
|
(DURATION_DIFF(duration, subghz_protocol_faac_slh_const.te_long) <
|
|
|
|
subghz_protocol_faac_slh_const.te_delta)) {
|
|
|
|
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepSaveDuration;
|
|
|
|
} else if(
|
|
|
|
(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_faac_slh_const.te_long) <
|
|
|
|
subghz_protocol_faac_slh_const.te_delta) &&
|
|
|
|
(DURATION_DIFF(duration, subghz_protocol_faac_slh_const.te_short) <
|
|
|
|
subghz_protocol_faac_slh_const.te_delta)) {
|
|
|
|
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepSaveDuration;
|
|
|
|
} else {
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepReset;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
instance->decoder.parser_step = FaacSLHDecoderStepReset;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-16 09:18:48 +00:00
|
|
|
/**
|
|
|
|
* Analysis of received data
|
|
|
|
* @param instance Pointer to a SubGhzBlockGeneric* instance
|
2022-04-28 09:35:47 +00:00
|
|
|
* @param keystore Pointer to a SubGhzKeystore* instance
|
|
|
|
* @param manifacture_name Manufacturer name
|
2022-03-16 09:18:48 +00:00
|
|
|
*/
|
2022-06-24 10:01:41 +00:00
|
|
|
static void subghz_protocol_faac_slh_check_remote_controller(
|
|
|
|
SubGhzBlockGeneric* instance,
|
|
|
|
SubGhzKeystore* keystore,
|
|
|
|
const char** manufacture_name) {
|
2022-04-08 21:29:15 +00:00
|
|
|
uint32_t code_fix = instance->data >> 32;
|
2022-04-20 18:12:05 +00:00
|
|
|
uint32_t code_hop = instance->data & 0xFFFFFFFF;
|
2022-04-08 21:29:15 +00:00
|
|
|
instance->serial = code_fix >> 4;
|
|
|
|
instance->btn = code_fix & 0xF;
|
2022-04-20 18:12:05 +00:00
|
|
|
uint32_t decrypt = 0;
|
|
|
|
uint64_t man;
|
|
|
|
|
|
|
|
for
|
2022-06-24 10:01:41 +00:00
|
|
|
M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) {
|
|
|
|
switch(manufacture_code->type) {
|
|
|
|
case KEELOQ_LEARNING_FAAC:
|
|
|
|
// FAAC Learning
|
|
|
|
man = subghz_protocol_keeloq_common_faac_learning(
|
|
|
|
instance->seed, manufacture_code->key);
|
|
|
|
decrypt = subghz_protocol_keeloq_common_decrypt(code_hop, man);
|
|
|
|
*manufacture_name = string_get_cstr(manufacture_code->name);
|
|
|
|
break;
|
|
|
|
}
|
2022-04-20 18:12:05 +00:00
|
|
|
}
|
2022-07-17 05:05:09 +00:00
|
|
|
instance->cnt = decrypt & 0xFFFFF;
|
2022-03-03 09:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t subghz_protocol_decoder_faac_slh_get_hash_data(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzProtocolDecoderFaacSLH* instance = context;
|
|
|
|
return subghz_protocol_blocks_get_hash_data(
|
|
|
|
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool subghz_protocol_decoder_faac_slh_serialize(
|
|
|
|
void* context,
|
|
|
|
FlipperFormat* flipper_format,
|
2022-07-27 12:58:32 +00:00
|
|
|
SubGhzPresetDefinition* preset) {
|
2022-03-03 09:48:56 +00:00
|
|
|
furi_assert(context);
|
|
|
|
SubGhzProtocolDecoderFaacSLH* instance = context;
|
2022-04-26 15:57:49 +00:00
|
|
|
|
2022-07-26 18:09:31 +00:00
|
|
|
bool res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
|
2022-05-21 02:02:12 +00:00
|
|
|
|
2022-04-26 19:57:31 +00:00
|
|
|
uint8_t seed_data[sizeof(uint32_t)] = {0};
|
2022-06-24 10:01:41 +00:00
|
|
|
for(size_t i = 0; i < sizeof(uint32_t); i++) {
|
|
|
|
seed_data[sizeof(uint32_t) - i - 1] = (instance->generic.seed >> i * 8) & 0xFF;
|
|
|
|
}
|
2022-04-26 19:57:31 +00:00
|
|
|
if(res && !flipper_format_write_hex(flipper_format, "Seed", seed_data, sizeof(uint32_t))) {
|
2022-04-26 18:35:02 +00:00
|
|
|
FURI_LOG_E(TAG, "Unable to add Seed");
|
2022-04-09 13:33:11 +00:00
|
|
|
res = false;
|
|
|
|
}
|
2022-06-24 10:01:41 +00:00
|
|
|
instance->generic.seed = seed_data[0] << 24 | seed_data[1] << 16 | seed_data[2] << 8 |
|
|
|
|
seed_data[3];
|
2022-05-21 02:02:12 +00:00
|
|
|
|
|
|
|
subghz_protocol_faac_slh_check_remote_controller(
|
|
|
|
&instance->generic, instance->keystore, &instance->manufacture_name);
|
|
|
|
|
2022-04-09 13:33:11 +00:00
|
|
|
return res;
|
2022-03-03 09:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool subghz_protocol_decoder_faac_slh_deserialize(void* context, FlipperFormat* flipper_format) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhzProtocolDecoderFaacSLH* instance = context;
|
2022-04-26 15:13:09 +00:00
|
|
|
bool res = false;
|
|
|
|
do {
|
|
|
|
if(!subghz_block_generic_deserialize(&instance->generic, flipper_format)) {
|
|
|
|
FURI_LOG_E(TAG, "Deserialize error");
|
|
|
|
break;
|
2022-04-26 19:57:31 +00:00
|
|
|
}
|
2022-08-01 12:24:21 +00:00
|
|
|
if(instance->generic.data_count_bit !=
|
|
|
|
subghz_protocol_faac_slh_const.min_count_bit_for_found) {
|
|
|
|
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
|
|
|
break;
|
|
|
|
}
|
2022-04-26 19:57:31 +00:00
|
|
|
if(!flipper_format_rewind(flipper_format)) {
|
|
|
|
FURI_LOG_E(TAG, "Rewind error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
uint8_t seed_data[sizeof(uint32_t)] = {0};
|
|
|
|
for(size_t i = 0; i < sizeof(uint32_t); i++) {
|
|
|
|
seed_data[sizeof(uint32_t) - i - 1] = (instance->generic.seed >> i * 8) & 0xFF;
|
|
|
|
}
|
|
|
|
if(!flipper_format_read_hex(flipper_format, "Seed", seed_data, sizeof(uint32_t))) {
|
|
|
|
FURI_LOG_E(TAG, "Missing Seed");
|
|
|
|
break;
|
2022-04-26 15:13:09 +00:00
|
|
|
}
|
2022-06-24 10:01:41 +00:00
|
|
|
instance->generic.seed = seed_data[0] << 24 | seed_data[1] << 16 | seed_data[2] << 8 |
|
|
|
|
seed_data[3];
|
2022-04-26 15:13:09 +00:00
|
|
|
res = true;
|
|
|
|
} while(false);
|
2022-06-24 10:01:41 +00:00
|
|
|
|
2022-04-26 15:13:09 +00:00
|
|
|
return res;
|
2022-03-03 09:48:56 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
void subghz_protocol_decoder_faac_slh_get_string(void* context, FuriString* output) {
|
2022-03-03 09:48:56 +00:00
|
|
|
furi_assert(context);
|
|
|
|
SubGhzProtocolDecoderFaacSLH* instance = context;
|
2022-06-24 10:01:41 +00:00
|
|
|
subghz_protocol_faac_slh_check_remote_controller(
|
|
|
|
&instance->generic, instance->keystore, &instance->manufacture_name);
|
2022-04-08 21:29:15 +00:00
|
|
|
uint32_t code_fix = instance->generic.data >> 32;
|
|
|
|
uint32_t code_hop = instance->generic.data & 0xFFFFFFFF;
|
2022-03-03 09:48:56 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_cat_printf(
|
2022-03-03 09:48:56 +00:00
|
|
|
output,
|
|
|
|
"%s %dbit\r\n"
|
|
|
|
"Key:%lX%08lX\r\n"
|
2022-07-17 05:05:09 +00:00
|
|
|
"Fix:%08lX Cnt:%05X\r\n"
|
2022-04-08 21:29:15 +00:00
|
|
|
"Hop:%08lX Btn:%lX\r\n"
|
2022-08-01 20:20:04 +00:00
|
|
|
"Sn:%07lX Sd:%08lX",
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->generic.protocol_name,
|
|
|
|
instance->generic.data_count_bit,
|
|
|
|
(uint32_t)(instance->generic.data >> 32),
|
|
|
|
(uint32_t)instance->generic.data,
|
|
|
|
code_fix,
|
2022-04-08 21:29:15 +00:00
|
|
|
instance->generic.cnt,
|
2022-03-03 09:48:56 +00:00
|
|
|
code_hop,
|
2022-04-08 21:29:15 +00:00
|
|
|
instance->generic.btn,
|
2022-04-09 13:33:11 +00:00
|
|
|
instance->generic.serial,
|
2022-04-10 23:35:11 +00:00
|
|
|
instance->generic.seed);
|
2022-03-03 09:48:56 +00:00
|
|
|
}
|