Faac SLH add manually

This commit is contained in:
r3df0xx 2022-04-19 00:32:25 +03:00
parent 4f544faf44
commit f2ec0a652a
9 changed files with 264 additions and 24 deletions

View file

@ -43,4 +43,6 @@ typedef enum {
SubGhzCustomEventViewTransmitterSendStart,
SubGhzCustomEventViewTransmitterSendStop,
SubGhzCustomEventViewTransmitterError,
SubGhzCustomEventByteInputDone,
} SubGhzCustomEvent;

View file

@ -17,6 +17,9 @@ ADD_SCENE(subghz, test_static, TestStatic)
ADD_SCENE(subghz, test_carrier, TestCarrier)
ADD_SCENE(subghz, test_packet, TestPacket)
ADD_SCENE(subghz, set_type, SetType)
ADD_SCENE(subghz, set_fix, SetFix)
ADD_SCENE(subghz, set_cnt, SetCnt)
ADD_SCENE(subghz, set_seed, SetSeed)
ADD_SCENE(subghz, frequency_analyzer, FrequencyAnalyzer)
ADD_SCENE(subghz, read_raw, ReadRAW)
ADD_SCENE(subghz, more_raw, MoreRAW)

View file

@ -0,0 +1,43 @@
#include "../subghz_i.h"
void subghz_scene_set_cnt_byte_input_callback(void* context) {
SubGhz* subghz = (SubGhz*)context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone);
}
void subghz_scene_set_cnt_on_enter(void* context) {
SubGhz* subghz = (SubGhz*)context;
// Setup view
ByteInput* byte_input = subghz->byte_input;
byte_input_set_header_text(byte_input, "Enter COUNTER in hex");
byte_input_set_result_callback(
byte_input,
subghz_scene_set_cnt_byte_input_callback,
NULL,
subghz,
subghz->txrx->cnt_data->cnt,
2);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
}
bool subghz_scene_set_cnt_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = (SubGhz*)context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventByteInputDone) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetSeed);
return true;
}
}
return false;
}
void subghz_scene_set_cnt_on_exit(void* context) {
SubGhz* subghz = (SubGhz*)context;
// Clear view
byte_input_set_result_callback(subghz->byte_input, NULL, NULL, NULL, NULL, 0);
byte_input_set_header_text(subghz->byte_input, "");
}

View file

@ -0,0 +1,43 @@
#include "../subghz_i.h"
void subghz_scene_set_fix_byte_input_callback(void* context) {
SubGhz* subghz = (SubGhz*)context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone);
}
void subghz_scene_set_fix_on_enter(void* context) {
SubGhz* subghz = (SubGhz*)context;
// Setup view
ByteInput* byte_input = subghz->byte_input;
byte_input_set_header_text(byte_input, "Enter FIX in hex");
byte_input_set_result_callback(
byte_input,
subghz_scene_set_fix_byte_input_callback,
NULL,
subghz,
subghz->txrx->fix_data->fix,
4);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
}
bool subghz_scene_set_fix_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = (SubGhz*)context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventByteInputDone) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetCnt);
return true;
}
}
return false;
}
void subghz_scene_set_fix_on_exit(void* context) {
SubGhz* subghz = (SubGhz*)context;
// Clear view
byte_input_set_result_callback(subghz->byte_input, NULL, NULL, NULL, NULL, 0);
byte_input_set_header_text(subghz->byte_input, "");
}

View file

@ -0,0 +1,43 @@
#include "../subghz_i.h"
void subghz_scene_set_seed_byte_input_callback(void* context) {
SubGhz* subghz = (SubGhz*)context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventByteInputDone);
}
void subghz_scene_set_seed_on_enter(void* context) {
SubGhz* subghz = (SubGhz*)context;
// Setup view
ByteInput* byte_input = subghz->byte_input;
byte_input_set_header_text(byte_input, "Enter COUNTER in hex");
byte_input_set_result_callback(
byte_input,
subghz_scene_set_seed_byte_input_callback,
NULL,
subghz,
subghz->txrx->seed_data->seed,
4);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
}
bool subghz_scene_set_seed_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = (SubGhz*)context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventByteInputDone) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
return true;
}
}
return false;
}
void subghz_scene_set_seed_on_exit(void* context) {
SubGhz* subghz = (SubGhz*)context;
// Clear view
byte_input_set_result_callback(subghz->byte_input, NULL, NULL, NULL, NULL, 0);
byte_input_set_header_text(subghz->byte_input, "");
}

View file

@ -1,5 +1,6 @@
#include "../subghz_i.h"
#include <lib/subghz/protocols/keeloq.h>
#include <lib/subghz/protocols/faac_slh.h>
#include <lib/subghz/blocks/math.h>
#include <dolphin/dolphin.h>
#include <flipper_format/flipper_format_i.h>
@ -8,6 +9,7 @@
#define TAG "SubGhzSetType"
enum SubmenuIndex {
SubmenuIndexFaacSLH,
SubmenuIndexPricenton,
SubmenuIndexNiceFlo12bit,
SubmenuIndexNiceFlo24bit,
@ -77,6 +79,12 @@ void subghz_scene_set_type_submenu_callback(void* context, uint32_t index) {
void subghz_scene_set_type_on_enter(void* context) {
SubGhz* subghz = context;
submenu_add_item(
subghz->submenu,
"Faac SLH_868",
SubmenuIndexFaacSLH,
subghz_scene_set_type_submenu_callback,
subghz);
submenu_add_item(
subghz->submenu,
"Princeton_433",
@ -150,6 +158,40 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
//ToDo Fix
uint32_t key = subghz_random_serial();
switch(event.event) {
case SubmenuIndexFaacSLH:
subghz->txrx->fix_data->fix_len = 4;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetFix);
uint32_t fix_part = subghz->txrx->fix_data->fix[0] << 24 | subghz->txrx->fix_data->fix[1] << 16 |
subghz->txrx->fix_data->fix[2] << 8 | subghz->txrx->fix_data->fix[3];
uint16_t cnt = subghz->txrx->cnt_data->cnt[0] << 8 | subghz->txrx->cnt_data->cnt[1] << 16;
uint32_t seed = subghz->txrx->seed_data->seed[0] << 24 | subghz->txrx->seed_data->seed[1] << 16 |
subghz->txrx->seed_data->seed[2] << 8 | subghz->txrx->seed_data->seed[3];
subghz->txrx->transmitter =
subghz_transmitter_alloc_init(subghz->txrx->environment, "Faac SLH");
if(subghz->txrx->transmitter) {
subghz_protocol_faac_slh_create_data(
subghz->txrx->transmitter->protocol_instance,
subghz->txrx->fff_data,
fix_part >> 4,
fix_part & 0xf,
cnt,
seed,
"FAAC_SLH",
868350000,
FuriHalSubGhzPresetOok650Async);
generated_protocol = true;
} else {
generated_protocol = false;
}
subghz_transmitter_free(subghz->txrx->transmitter);
if(!generated_protocol) {
string_set(
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
}
break;
case SubmenuIndexPricenton:
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
if(subghz_scene_set_type_submenu_gen_data_protocol(subghz, "Princeton", key, 24)) {

View file

@ -86,6 +86,16 @@ typedef struct {
uint8_t seed[4];
} SeedData;
typedef struct {
uint8_t fix_len;
uint8_t fix[4];
} FixData;
typedef struct {
uint8_t cnt_len;
uint8_t cnt[2];
} CntData;
struct SubGhzTxRx {
SubGhzWorker* worker;
@ -95,6 +105,8 @@ struct SubGhzTxRx {
SubGhzProtocolDecoderBase* decoder_result;
FlipperFormat* fff_data;
SeedData* seed_data;
FixData* fix_data;
CntData* cnt_data;
uint32_t frequency;
FuriHalSubGhzPreset preset;

View file

@ -116,7 +116,7 @@ static bool subghz_protocol_faac_slh_gen_data(SubGhzProtocolEncoderFaacSLH* inst
uint32_t hop = 0;
uint32_t decrypt = 0;
uint64_t man = 0;
instance->generic.seed = 0;
//instance->generic.seed = 0;
int res = 0;
char fixx[8] = {};
int shiftby = 32;
@ -159,6 +159,31 @@ static bool subghz_protocol_faac_slh_gen_data(SubGhzProtocolEncoderFaacSLH* inst
return true;
}
bool subghz_protocol_faac_slh_create_data(
void* context,
FlipperFormat* flipper_format,
uint32_t serial,
uint8_t btn,
uint16_t cnt,
uint32_t seed,
const char* manufacture_name,
uint32_t frequency,
FuriHalSubGhzPreset preset) {
furi_assert(context);
SubGhzProtocolEncoderFaacSLH* instance = context;
instance->generic.serial = serial;
instance->generic.cnt = cnt;
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) {
res =
subghz_block_generic_serialize(&instance->generic, flipper_format, frequency, preset);
}
return res;
}
/**
* Generating an upload from data.
* @param instance Pointer to a SubGhzProtocolEncoderFaacSLH instance
@ -373,31 +398,34 @@ static void subghz_protocol_faac_slh_check_remote_controller
//uint64_t code_found_reverse =
//subghz_protocol_blocks_reverse_key(instance->data, instance->data_count_bit);
uint32_t code_fix = instance->data >> 32;
uint32_t code_hop = instance->data & 0xFFFFFFFF;
//uint32_t code_hop = instance->data & 0xFFFFFFFF;
instance->serial = code_fix >> 4;
instance->btn = code_fix & 0xF;
uint32_t decrypt = 0;
uint64_t man;
instance->seed = 0;
//uint32_t decrypt = 0;
//uint64_t man;
//instance->seed = 0;
for
M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) {
uint32_t hi = manufacture_code->key >> 32;
uint32_t lo = manufacture_code->key & 0xFFFFFFFF;
switch(manufacture_code->type) {
case KEELOQ_LEARNING_FAAC:
// FAAC Learning
man = subghz_protocol_keeloq_common_faac_learning(instance->seed, manufacture_code->key);
FURI_LOG_I(TAG, "mfkey: %08lX%08lX mf: %s\n", hi, lo, manufacture_code->name);
uint32_t mlhi = man >> 32;
uint32_t mllo = man & 0xFFFFFFFF;
FURI_LOG_I(TAG, "man_learning: %8X%8X\n", mlhi, mllo);
decrypt = subghz_protocol_keeloq_common_decrypt(code_hop, man);
FURI_LOG_I(TAG, "hop: %8X\n", code_hop);
*manufacture_name = string_get_cstr(manufacture_code->name);
break;
}
} instance->cnt = (decrypt & 0xFFFF);
/**
* for
* M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) {
* uint32_t hi = manufacture_code->key >> 32;
* uint32_t lo = manufacture_code->key & 0xFFFFFFFF;
* switch(manufacture_code->type) {
* case KEELOQ_LEARNING_FAAC:
* // FAAC Learning
* man = subghz_protocol_keeloq_common_faac_learning(instance->seed, manufacture_code->key);
* FURI_LOG_I(TAG, "mfkey: %08lX%08lX mf: %s\n", hi, lo, manufacture_code->name);
* uint32_t mlhi = man >> 32;
* uint32_t mllo = man & 0xFFFFFFFF;
* FURI_LOG_I(TAG, "man_learning: %8X%8X\n", mlhi, mllo);
* decrypt = subghz_protocol_keeloq_common_decrypt(code_hop, man);
* FURI_LOG_I(TAG, "hop: %8X\n", code_hop);
* *manufacture_name = string_get_cstr(manufacture_code->name);
* break;
* }
* }
*/
instance->cnt = 0x0;
}
uint8_t subghz_protocol_decoder_faac_slh_get_hash_data(void* context) {
@ -443,7 +471,7 @@ void subghz_protocol_decoder_faac_slh_get_string(void* context, string_t output)
"Key:%lX%08lX\r\n"
"Fix:%08lX Cnt:%04X\r\n"
"Hop:%08lX Btn:%lX\r\n"
"Sn:%07lX Seed:%8X\r\n",
"Sn:%07lX Sd:%8X",
instance->generic.protocol_name,
instance->generic.data_count_bit,
(uint32_t)(instance->generic.data >> 32),

View file

@ -24,6 +24,30 @@ void* subghz_protocol_encoder_faac_slh_alloc(SubGhzEnvironment* environment);
*/
void subghz_protocol_encoder_faac_slh_free(void* context);
/**
* Key generation from simple data.
* @param context Pointer to a SubGhzProtocolEncoderFaacSLH instance
* @param flipper_format Pointer to a FlipperFormat instance
* @param serial Serial number, 28 bit
* @param btn Button number, 4 bit
* @param cnt Counter value, 16 bit
* @param seed Seed value, 32 bit
* @param manufacture_name Name of manufacturer's key
* @param frequency Transmission frequency, Hz
* @param preset Modulation, FuriHalSubGhzPreset
* @return true On success
*/
bool subghz_protocol_faac_slh_create_data(
void* context,
FlipperFormat* flipper_format,
uint32_t serial,
uint8_t btn,
uint16_t cnt,
uint32_t seed,
const char* manufacture_name,
uint32_t frequency,
FuriHalSubGhzPreset preset);
/**
* Deserialize and generating an upload to send.
* @param context Pointer to a SubGhzProtocolEncoderFaacSLH instance