Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keeloq move mf to keystore #479

Merged
merged 11 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions applications/main/subghz/helpers/subghz_txrx.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "subghz_txrx_i.h"
#include <lib/subghz/protocols/protocol_items.h>
#include <lib/subghz/blocks/custom_btn.h>

#define TAG "SubGhz"

Expand Down Expand Up @@ -557,6 +558,13 @@ bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance) {
return instance->debug_pin_state;
}

void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance) {
furi_assert(instance);
subghz_environment_reset_keeloq(instance->environment);

subghz_custom_btns_reset();
}

SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) {
furi_assert(instance);
return instance->receiver;
Expand Down
2 changes: 2 additions & 0 deletions applications/main/subghz/helpers/subghz_txrx.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,6 @@ void subghz_txrx_set_raw_file_encoder_worker_callback_end(
void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state);
bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance);

void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance);

SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw
10 changes: 1 addition & 9 deletions applications/main/subghz/scenes/subghz_scene_receiver_info.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "../subghz_i.h"
#include "../helpers/subghz_custom_event.h"
#include <lib/subghz/protocols/keeloq.h>
#include <lib/subghz/protocols/star_line.h>

#include <lib/subghz/blocks/custom_btn.h>

Expand Down Expand Up @@ -108,7 +106,6 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) {
void subghz_scene_receiver_info_on_enter(void* context) {
SubGhz* subghz = context;

keeloq_reset_original_btn();
subghz_custom_btns_reset();

subghz_scene_receiver_info_draw_widget(subghz);
Expand Down Expand Up @@ -191,10 +188,5 @@ void subghz_scene_receiver_info_on_exit(void* context) {
SubGhz* subghz = context;

widget_reset(subghz->widget);
keeloq_reset_mfname();
keeloq_reset_kl_type();
keeloq_reset_original_btn();
subghz_custom_btns_reset();
star_line_reset_mfname();
star_line_reset_kl_type();
subghz_txrx_reset_dynamic_and_custom_btns(subghz->txrx);
}
9 changes: 1 addition & 8 deletions applications/main/subghz/scenes/subghz_scene_rpc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "../subghz_i.h"
#include <lib/subghz/protocols/keeloq.h>
#include <lib/subghz/protocols/star_line.h>

#include <lib/subghz/blocks/custom_btn.h>

Expand Down Expand Up @@ -110,10 +108,5 @@ void subghz_scene_rpc_on_exit(void* context) {
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
popup_set_icon(popup, 0, 0, NULL);

keeloq_reset_mfname();
keeloq_reset_kl_type();
keeloq_reset_original_btn();
subghz_custom_btns_reset();
star_line_reset_mfname();
star_line_reset_kl_type();
subghz_txrx_reset_dynamic_and_custom_btns(subghz->txrx);
}
11 changes: 2 additions & 9 deletions applications/main/subghz/scenes/subghz_scene_transmitter.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "../subghz_i.h"
#include "../views/transmitter.h"
#include <dolphin/dolphin.h>
#include <lib/subghz/protocols/keeloq.h>
#include <lib/subghz/protocols/star_line.h>

#include <lib/subghz/blocks/custom_btn.h>

Expand Down Expand Up @@ -46,7 +44,6 @@ bool subghz_scene_transmitter_update_data_show(void* context) {
void subghz_scene_transmitter_on_enter(void* context) {
SubGhz* subghz = context;

keeloq_reset_original_btn();
subghz_custom_btns_reset();

if(!subghz_scene_transmitter_update_data_show(subghz)) {
Expand Down Expand Up @@ -107,10 +104,6 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
void subghz_scene_transmitter_on_exit(void* context) {
SubGhz* subghz = context;
subghz->state_notifications = SubGhzNotificationStateIDLE;
keeloq_reset_mfname();
keeloq_reset_kl_type();
keeloq_reset_original_btn();
subghz_custom_btns_reset();
star_line_reset_mfname();
star_line_reset_kl_type();

subghz_txrx_reset_dynamic_and_custom_btns(subghz->txrx);
}
8 changes: 1 addition & 7 deletions applications/main/subghz_remote/subghz_remote_app_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ bool subrem_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset)
0);

#ifdef APP_SUBGHZREMOTE
subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK);
keeloq_reset_original_btn();
subghz_custom_btns_reset();
#endif

Expand All @@ -250,12 +248,8 @@ bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced) {
subghz_txrx_stop(app->txrx);
#ifdef APP_SUBGHZREMOTE
if(sub_preset->type == SubGhzProtocolTypeDynamic) {
keeloq_reset_mfname();
keeloq_reset_kl_type();
star_line_reset_mfname();
star_line_reset_kl_type();
subghz_txrx_reset_dynamic_and_custom_btns(app->txrx);
}
keeloq_reset_original_btn();
subghz_custom_btns_reset();
#endif
return true;
Expand Down
14 changes: 2 additions & 12 deletions firmware/targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1817,9 +1817,6 @@ Function,-,j1f,float,float
Function,-,jn,double,"int, double"
Function,-,jnf,float,"int, float"
Function,-,jrand48,long,unsigned short[3]
Function,-,keeloq_reset_kl_type,void,
Function,-,keeloq_reset_mfname,void,
Function,-,keeloq_reset_original_btn,void,
Function,-,l64a,char*,long
Function,-,labs,long,long
Function,-,lcong48,void,unsigned short[7]
Expand Down Expand Up @@ -2563,8 +2560,6 @@ Function,+,srand,void,unsigned
Function,-,srand48,void,long
Function,-,srandom,void,unsigned
Function,+,sscanf,int,"const char*, const char*, ..."
Function,-,star_line_reset_kl_type,void,
Function,-,star_line_reset_mfname,void,
Function,+,storage_common_copy,FS_Error,"Storage*, const char*, const char*"
Function,+,storage_common_exists,_Bool,"Storage*, const char*"
Function,+,storage_common_fs_info,FS_Error,"Storage*, const char*, uint64_t*, uint64_t*"
Expand Down Expand Up @@ -2711,13 +2706,6 @@ Function,+,subghz_block_generic_deserialize,SubGhzProtocolStatus,"SubGhzBlockGen
Function,+,subghz_block_generic_deserialize_check_count_bit,SubGhzProtocolStatus,"SubGhzBlockGeneric*, FlipperFormat*, uint16_t"
Function,+,subghz_block_generic_get_preset_name,void,"const char*, FuriString*"
Function,+,subghz_block_generic_serialize,SubGhzProtocolStatus,"SubGhzBlockGeneric*, FlipperFormat*, SubGhzRadioPreset*"
Function,-,subghz_custom_btn_get,uint8_t,
Function,-,subghz_custom_btn_get_original,uint8_t,
Function,-,subghz_custom_btn_is_allowed,_Bool,
Function,-,subghz_custom_btn_set,_Bool,uint8_t
Function,-,subghz_custom_btn_set_max,void,uint8_t
Function,-,subghz_custom_btn_set_original,void,uint8_t
Function,-,subghz_custom_btns_reset,void,
Function,+,subghz_environment_alloc,SubGhzEnvironment*,
Function,+,subghz_environment_free,void,SubGhzEnvironment*
Function,+,subghz_environment_get_alutech_at_4n_rainbow_table_file_name,const char*,SubGhzEnvironment*
Expand All @@ -2727,6 +2715,7 @@ Function,+,subghz_environment_get_nice_flor_s_rainbow_table_file_name,const char
Function,+,subghz_environment_get_protocol_name_registry,const char*,"SubGhzEnvironment*, size_t"
Function,+,subghz_environment_get_protocol_registry,void*,SubGhzEnvironment*
Function,+,subghz_environment_load_keystore,_Bool,"SubGhzEnvironment*, const char*"
Function,+,subghz_environment_reset_keeloq,void,SubGhzEnvironment*
Function,+,subghz_environment_set_alutech_at_4n_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*"
Function,+,subghz_environment_set_came_atomo_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*"
Function,+,subghz_environment_set_nice_flor_s_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*"
Expand All @@ -2737,6 +2726,7 @@ Function,-,subghz_keystore_get_data,SubGhzKeyArray_t*,SubGhzKeystore*
Function,-,subghz_keystore_load,_Bool,"SubGhzKeystore*, const char*"
Function,-,subghz_keystore_raw_encrypted_save,_Bool,"const char*, const char*, uint8_t*"
Function,-,subghz_keystore_raw_get_data,_Bool,"const char*, size_t, uint8_t*, size_t"
Function,-,subghz_keystore_reset_kl,void,SubGhzKeystore*
Function,-,subghz_keystore_save,_Bool,"SubGhzKeystore*, const char*, uint8_t*"
Function,-,subghz_protocol_alutech_at_4n_create_data,_Bool,"void*, FlipperFormat*, uint32_t, uint8_t, uint16_t, SubGhzRadioPreset*"
Function,+,subghz_protocol_blocks_add_bit,void,"SubGhzBlockDecoder*, uint8_t"
Expand Down
13 changes: 12 additions & 1 deletion lib/subghz/blocks/custom_btn.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "custom_btn.h"
#include "custom_btn_i.h"

static uint8_t custom_btn_id = SUBGHZ_CUSTOM_BTN_OK;
static uint8_t custom_btn_original = 0;
static uint8_t custom_btn_max_btns = 0;
static uint8_t controller_programming_mode = PROG_MODE_OFF;

bool subghz_custom_btn_set(uint8_t btn_id) {
if(btn_id > custom_btn_max_btns) {
Expand Down Expand Up @@ -33,8 +34,18 @@ void subghz_custom_btn_set_max(uint8_t b) {
void subghz_custom_btns_reset() {
custom_btn_original = 0;
custom_btn_max_btns = 0;
controller_programming_mode = PROG_MODE_OFF;
custom_btn_id = SUBGHZ_CUSTOM_BTN_OK;
}

bool subghz_custom_btn_is_allowed() {
return custom_btn_max_btns != 0;
}

void subghz_custom_btn_set_prog_mode(ProgMode prog_mode) {
controller_programming_mode = prog_mode;
}

ProgMode subghz_custom_btn_get_prog_mode() {
return controller_programming_mode;
}
4 changes: 0 additions & 4 deletions lib/subghz/blocks/custom_btn.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ bool subghz_custom_btn_set(uint8_t btn_id);

uint8_t subghz_custom_btn_get();

void subghz_custom_btn_set_original(uint8_t btn_code);

uint8_t subghz_custom_btn_get_original();

void subghz_custom_btn_set_max(uint8_t b);

void subghz_custom_btns_reset();

bool subghz_custom_btn_is_allowed();
17 changes: 17 additions & 0 deletions lib/subghz/blocks/custom_btn_i.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "custom_btn.h"

#define PROG_MODE_OFF (0U)
#define PROG_MODE_KEELOQ_BFT (1U)
#define PROG_MODE_KEELOQ_APRIMATIC (2U)

typedef uint8_t ProgMode;

void subghz_custom_btn_set_original(uint8_t btn_code);

void subghz_custom_btn_set_max(uint8_t b);

void subghz_custom_btn_set_prog_mode(ProgMode prog_mode);

ProgMode subghz_custom_btn_get_prog_mode();
12 changes: 11 additions & 1 deletion lib/subghz/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ struct SubGhzEnvironment {
const char* came_atomo_rainbow_table_file_name;
const char* nice_flor_s_rainbow_table_file_name;
const char* alutech_at_4n_rainbow_table_file_name;
const char* mfname;
uint8_t kl_type;
};

SubGhzEnvironment* subghz_environment_alloc() {
Expand All @@ -17,6 +19,8 @@ SubGhzEnvironment* subghz_environment_alloc() {
instance->came_atomo_rainbow_table_file_name = NULL;
instance->nice_flor_s_rainbow_table_file_name = NULL;
instance->alutech_at_4n_rainbow_table_file_name = NULL;
instance->mfname = "";
instance->kl_type = 0;

return instance;
}
Expand Down Expand Up @@ -115,4 +119,10 @@ const char*
} else {
return NULL;
}
}
}

void subghz_environment_reset_keeloq(SubGhzEnvironment* instance) {
furi_assert(instance);

subghz_keystore_reset_kl(instance->keystore);
}
6 changes: 6 additions & 0 deletions lib/subghz/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ void* subghz_environment_get_protocol_registry(SubGhzEnvironment* instance);
*/
const char* subghz_environment_get_protocol_name_registry(SubGhzEnvironment* instance, size_t idx);

/**
* Resetting the parameters used in the keeloq protocol.
* @param instance Pointer to a SubGhzEnvironment instance
*/
void subghz_environment_reset_keeloq(SubGhzEnvironment* instance);

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion lib/subghz/protocols/alutech_at_4n.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "../blocks/generic.h"
#include "../blocks/math.h"

#include "../blocks/custom_btn.h"
#include "../blocks/custom_btn_i.h"

#define TAG "SubGhzProtocoAlutech_at_4n"

Expand Down
2 changes: 1 addition & 1 deletion lib/subghz/protocols/came_atomo.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "../blocks/generic.h"
#include "../blocks/math.h"

#include "../blocks/custom_btn.h"
#include "../blocks/custom_btn_i.h"

#define TAG "SubGhzProtocoCameAtomo"

Expand Down
Loading