[FL-1546, FL-1534, FL-1550] Drop F5, Certification preparation, Global application start lock (#585)
* Firmware: drop F5 target * Rename app-loader to loader * Update code owners file * Loader: global application start lock API, minor refactoring * Archive: update loader usage * Cli: Command flags, global application start lock * Apps: update cli API usage * Bootloader: minor refactoring * Firmware: minor build refactoring * SubGhz: GUI packet test * SubGhz: drop packet transmission and unused presets * Github: drop F5 from build * Archive: favorites * Archive: a little bit more of Favorites
This commit is contained in:
167
lib/subghz/protocols/subghz_protocol.c
Normal file
167
lib/subghz/protocols/subghz_protocol.c
Normal file
@@ -0,0 +1,167 @@
|
||||
#include "subghz_protocol.h"
|
||||
#include "subghz_protocol_came.h"
|
||||
#include "subghz_protocol_cfm.h"
|
||||
#include "subghz_protocol_keeloq.h"
|
||||
#include "subghz_protocol_nice_flo.h"
|
||||
#include "subghz_protocol_nice_flor_s.h"
|
||||
#include "subghz_protocol_princeton.h"
|
||||
#include "subghz_protocol_gate_tx.h"
|
||||
#include "subghz_protocol_ido.h"
|
||||
#include "subghz_protocol_faac_slh.h"
|
||||
#include "subghz_protocol_nero_sketch.h"
|
||||
#include "subghz_protocol_star_line.h"
|
||||
|
||||
#include "../subghz_keystore.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <m-string.h>
|
||||
|
||||
struct SubGhzProtocol {
|
||||
SubGhzKeystore* keystore;
|
||||
|
||||
SubGhzProtocolCame* came;
|
||||
SubGhzProtocolKeeloq* keeloq;
|
||||
SubGhzProtocolNiceFlo* nice_flo;
|
||||
SubGhzProtocolNiceFlorS* nice_flor_s;
|
||||
SubGhzProtocolPrinceton* princeton;
|
||||
SubGhzProtocolGateTX* gate_tx;
|
||||
SubGhzProtocolIDo* ido;
|
||||
SubGhzProtocolFaacSLH* faac_slh;
|
||||
SubGhzProtocolNeroSketch* nero_sketch;
|
||||
SubGhzProtocolStarLine* star_line;
|
||||
|
||||
SubGhzProtocolTextCallback text_callback;
|
||||
void* text_callback_context;
|
||||
SubGhzProtocolCommonCallbackDump parser_callback;
|
||||
void* parser_callback_context;
|
||||
};
|
||||
|
||||
static void subghz_protocol_text_rx_callback(SubGhzProtocolCommon* parser, void* context) {
|
||||
SubGhzProtocol* instance = context;
|
||||
|
||||
string_t output;
|
||||
string_init(output);
|
||||
subghz_protocol_common_to_str((SubGhzProtocolCommon*)parser, output);
|
||||
if (instance->text_callback) {
|
||||
instance->text_callback(output, instance->text_callback_context);
|
||||
} else {
|
||||
printf(string_get_cstr(output));
|
||||
}
|
||||
string_clear(output);
|
||||
}
|
||||
|
||||
static void subghz_protocol_parser_rx_callback(SubGhzProtocolCommon* parser, void* context) {
|
||||
SubGhzProtocol* instance = context;
|
||||
if (instance->parser_callback) {
|
||||
instance->parser_callback(parser, instance->parser_callback_context);
|
||||
}
|
||||
}
|
||||
|
||||
SubGhzProtocol* subghz_protocol_alloc() {
|
||||
SubGhzProtocol* instance = furi_alloc(sizeof(SubGhzProtocol));
|
||||
|
||||
instance->keystore = subghz_keystore_alloc();
|
||||
|
||||
instance->came = subghz_protocol_came_alloc();
|
||||
instance->keeloq = subghz_protocol_keeloq_alloc(instance->keystore);
|
||||
instance->princeton = subghz_protocol_princeton_alloc();
|
||||
instance->nice_flo = subghz_protocol_nice_flo_alloc();
|
||||
instance->nice_flor_s = subghz_protocol_nice_flor_s_alloc();
|
||||
instance->gate_tx = subghz_protocol_gate_tx_alloc();
|
||||
instance->ido = subghz_protocol_ido_alloc();
|
||||
instance->faac_slh = subghz_protocol_faac_slh_alloc();
|
||||
instance->nero_sketch = subghz_protocol_nero_sketch_alloc();
|
||||
instance->star_line = subghz_protocol_star_line_alloc(instance->keystore);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_free(SubGhzProtocol* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
subghz_protocol_came_free(instance->came);
|
||||
subghz_protocol_keeloq_free(instance->keeloq);
|
||||
subghz_protocol_princeton_free(instance->princeton);
|
||||
subghz_protocol_nice_flo_free(instance->nice_flo);
|
||||
subghz_protocol_nice_flor_s_free(instance->nice_flor_s);
|
||||
subghz_protocol_gate_tx_free(instance->gate_tx);
|
||||
subghz_protocol_ido_free(instance->ido);
|
||||
subghz_protocol_faac_slh_free(instance->faac_slh);
|
||||
subghz_protocol_nero_sketch_free(instance->nero_sketch);
|
||||
subghz_protocol_star_line_free(instance->star_line);
|
||||
|
||||
subghz_keystore_free(instance->keystore);
|
||||
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_enable_dump_text(SubGhzProtocol* instance, SubGhzProtocolTextCallback callback, void* context) {
|
||||
furi_assert(instance);
|
||||
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->came, subghz_protocol_text_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->keeloq, subghz_protocol_text_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->princeton, subghz_protocol_text_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->nice_flo, subghz_protocol_text_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->nice_flor_s, subghz_protocol_text_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->gate_tx, subghz_protocol_text_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->ido, subghz_protocol_text_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->faac_slh, subghz_protocol_text_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->nero_sketch, subghz_protocol_text_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->star_line, subghz_protocol_text_rx_callback, instance);
|
||||
|
||||
instance->text_callback = callback;
|
||||
instance->text_callback_context = context;
|
||||
}
|
||||
|
||||
void subghz_protocol_enable_dump(SubGhzProtocol* instance, SubGhzProtocolCommonCallbackDump callback, void* context) {
|
||||
furi_assert(instance);
|
||||
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->came, subghz_protocol_parser_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->keeloq, subghz_protocol_parser_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->princeton, subghz_protocol_parser_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->nice_flo, subghz_protocol_parser_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->nice_flor_s, subghz_protocol_parser_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->gate_tx, subghz_protocol_parser_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->ido, subghz_protocol_parser_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->faac_slh, subghz_protocol_parser_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->nero_sketch, subghz_protocol_parser_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->star_line, subghz_protocol_parser_rx_callback, instance);
|
||||
|
||||
instance->parser_callback = callback;
|
||||
instance->parser_callback_context = context;
|
||||
}
|
||||
|
||||
|
||||
void subghz_protocol_load_nice_flor_s_file(SubGhzProtocol* instance, const char* file_name) {
|
||||
subghz_protocol_nice_flor_s_name_file(instance->nice_flor_s, file_name);
|
||||
}
|
||||
|
||||
void subghz_protocol_load_keeloq_file(SubGhzProtocol* instance, const char* file_name) {
|
||||
subghz_keystore_load(instance->keystore, file_name);
|
||||
}
|
||||
|
||||
void subghz_protocol_reset(SubGhzProtocol* instance) {
|
||||
subghz_protocol_came_reset(instance->came);
|
||||
subghz_protocol_keeloq_reset(instance->keeloq);
|
||||
subghz_protocol_princeton_reset(instance->princeton);
|
||||
subghz_protocol_nice_flo_reset(instance->nice_flo);
|
||||
subghz_protocol_nice_flor_s_reset(instance->nice_flor_s);
|
||||
subghz_protocol_gate_tx_reset(instance->gate_tx);
|
||||
subghz_protocol_ido_reset(instance->ido);
|
||||
subghz_protocol_faac_slh_reset(instance->faac_slh);
|
||||
subghz_protocol_nero_sketch_reset(instance->nero_sketch);
|
||||
subghz_protocol_star_line_reset(instance->star_line);
|
||||
}
|
||||
|
||||
void subghz_protocol_parse(SubGhzProtocol* instance, bool level, uint32_t duration) {
|
||||
subghz_protocol_came_parse(instance->came, level, duration);
|
||||
subghz_protocol_keeloq_parse(instance->keeloq, level, duration);
|
||||
subghz_protocol_princeton_parse(instance->princeton, level, duration);
|
||||
subghz_protocol_nice_flo_parse(instance->nice_flo, level, duration);
|
||||
subghz_protocol_nice_flor_s_parse(instance->nice_flor_s, level, duration);
|
||||
subghz_protocol_gate_tx_parse(instance->gate_tx, level, duration);
|
||||
subghz_protocol_ido_parse(instance->ido, level, duration);
|
||||
subghz_protocol_faac_slh_parse(instance->faac_slh, level, duration);
|
||||
subghz_protocol_nero_sketch_parse(instance->nero_sketch, level, duration);
|
||||
subghz_protocol_star_line_parse(instance->star_line, level, duration);
|
||||
}
|
64
lib/subghz/protocols/subghz_protocol.h
Normal file
64
lib/subghz/protocols/subghz_protocol.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef void (*SubGhzProtocolTextCallback)(string_t text, void* context);
|
||||
typedef void (*SubGhzProtocolCommonCallbackDump)(SubGhzProtocolCommon *parser, void* context);
|
||||
|
||||
typedef struct SubGhzProtocol SubGhzProtocol;
|
||||
|
||||
/** Allocate SubGhzProtocol
|
||||
*
|
||||
* @return SubGhzProtocol*
|
||||
*/
|
||||
SubGhzProtocol* subghz_protocol_alloc();
|
||||
|
||||
/** Free SubGhzProtocol
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_free(SubGhzProtocol* instance);
|
||||
|
||||
/** Outputting data text from all parsers
|
||||
*
|
||||
* @param instance - SubGhzProtocol instance
|
||||
* @param callback - SubGhzProtocolTextCallback callback
|
||||
* @param context
|
||||
*/
|
||||
void subghz_protocol_enable_dump_text(SubGhzProtocol* instance, SubGhzProtocolTextCallback callback, void* context);
|
||||
|
||||
/** Outputting data SubGhzProtocol from all parsers
|
||||
*
|
||||
* @param instance - SubGhzProtocol instance
|
||||
* @param callback - SubGhzProtocolTextCallback callback
|
||||
* @param context
|
||||
*/
|
||||
void subghz_protocol_enable_dump( SubGhzProtocol* instance, SubGhzProtocolCommonCallbackDump callback, void* context);
|
||||
|
||||
/** File name rainbow table Nice Flor-S
|
||||
*
|
||||
* @param instance - SubGhzProtocol instance
|
||||
* @param file_name - "path/file_name"
|
||||
*/
|
||||
void subghz_protocol_load_nice_flor_s_file(SubGhzProtocol* instance, const char* file_name);
|
||||
|
||||
/** File upload manufacture keys
|
||||
*
|
||||
* @param instance - SubGhzProtocol instance
|
||||
* @param file_name - "path/file_name"
|
||||
*/
|
||||
void subghz_protocol_load_keeloq_file(SubGhzProtocol* instance, const char* file_name);
|
||||
|
||||
/** Restarting all parsers
|
||||
*
|
||||
* @param instance - SubGhzProtocol instance
|
||||
*/
|
||||
void subghz_protocol_reset(SubGhzProtocol* instance);
|
||||
|
||||
/** Loading data into all parsers
|
||||
*
|
||||
* @param instance - SubGhzProtocol instance
|
||||
* @param level - true is high, false if low
|
||||
* @param duration - level duration in microseconds
|
||||
*/
|
||||
void subghz_protocol_parse(SubGhzProtocol* instance, bool level, uint32_t duration);
|
131
lib/subghz/protocols/subghz_protocol_came.c
Normal file
131
lib/subghz/protocols/subghz_protocol_came.c
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "subghz_protocol_came.h"
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://phreakerclub.com/447
|
||||
*
|
||||
*/
|
||||
|
||||
struct SubGhzProtocolCame {
|
||||
SubGhzProtocolCommon common;
|
||||
};
|
||||
|
||||
SubGhzProtocolCame* subghz_protocol_came_alloc() {
|
||||
SubGhzProtocolCame* instance = furi_alloc(sizeof(SubGhzProtocolCame));
|
||||
|
||||
instance->common.name = "Came";
|
||||
instance->common.code_min_count_bit_for_found = 12;
|
||||
instance->common.te_shot = 320;
|
||||
instance->common.te_long = 640;
|
||||
instance->common.te_delta = 150;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_came_free(SubGhzProtocolCame* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolCame instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_came_send_bit(SubGhzProtocolCame* instance, uint8_t bit) {
|
||||
if (bit) {
|
||||
//send bit 1
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
} else {
|
||||
//send bit 0
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_came_send_key(SubGhzProtocolCame* instance, uint64_t key, uint8_t bit, uint8_t repeat) {
|
||||
while (repeat--) {
|
||||
//Send header
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot * 34); //+2 interval v bit 1
|
||||
//Send start bit
|
||||
subghz_protocol_came_send_bit(instance, 1);
|
||||
//Send key data
|
||||
for (uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_came_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_came_reset(SubGhzProtocolCame* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
void subghz_protocol_came_parse(SubGhzProtocolCame* instance, bool level, uint32_t duration) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((!level)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_shot * 51)< instance->common.te_delta * 51)) { //Need protocol 36 te_shot
|
||||
//Found header CAME
|
||||
instance->common.parser_step = 1;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!level) {
|
||||
break;
|
||||
} else if (DURATION_DIFF(duration, instance->common.te_shot)< instance->common.te_delta) {
|
||||
//Found start bit CAME
|
||||
instance->common.parser_step = 2;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!level) { //save interval
|
||||
if (duration >= (instance->common.te_shot * 4)) {
|
||||
instance->common.parser_step = 1;
|
||||
if (instance->common.code_count_bit>= instance->common.code_min_count_bit_for_found) {
|
||||
|
||||
|
||||
instance->common.serial = 0x0;
|
||||
instance->common.btn = 0x0;
|
||||
if (instance->common.callback)
|
||||
instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 3;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (level) {
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot) < instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_long)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
instance->common.parser_step = 2;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last,instance->common.te_long)< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_shot)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
instance->common.parser_step = 2;
|
||||
} else
|
||||
instance->common.parser_step = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
38
lib/subghz/protocols/subghz_protocol_came.h
Normal file
38
lib/subghz/protocols/subghz_protocol_came.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolCame SubGhzProtocolCame;
|
||||
|
||||
/** Allocate SubGhzProtocolCame
|
||||
*
|
||||
* @return SubGhzProtocolCame*
|
||||
*/
|
||||
SubGhzProtocolCame* subghz_protocol_came_alloc();
|
||||
|
||||
/** Free SubGhzProtocolCame
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_came_free(SubGhzProtocolCame* instance);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolCame instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_came_send_key(SubGhzProtocolCame* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolCame instance
|
||||
*/
|
||||
void subghz_protocol_came_reset(SubGhzProtocolCame* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolCame instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_came_parse(SubGhzProtocolCame* instance, bool level, uint32_t duration);
|
4
lib/subghz/protocols/subghz_protocol_cfm.c
Normal file
4
lib/subghz/protocols/subghz_protocol_cfm.c
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
/*
|
||||
* https://phreakerclub.com/616
|
||||
*/
|
0
lib/subghz/protocols/subghz_protocol_cfm.h
Normal file
0
lib/subghz/protocols/subghz_protocol_cfm.h
Normal file
77
lib/subghz/protocols/subghz_protocol_common.c
Normal file
77
lib/subghz/protocols/subghz_protocol_common.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "subghz_protocol_common.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void subghz_protocol_common_add_bit(SubGhzProtocolCommon *common, uint8_t bit){
|
||||
common->code_found = common->code_found <<1 | bit;
|
||||
common->code_count_bit++;
|
||||
}
|
||||
|
||||
bool subghz_protocol_common_check_interval (SubGhzProtocolCommon *common, uint32_t duration, uint16_t duration_check) {
|
||||
if ((duration_check >= (duration - common->te_delta))&&(duration_check <= (duration + common->te_delta))){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t subghz_protocol_common_reverse_key(uint64_t key, uint8_t count_bit){
|
||||
uint64_t key_reverse=0;
|
||||
for(uint8_t i=0; i<count_bit; i++) {
|
||||
key_reverse=key_reverse<<1|bit_read(key,i);
|
||||
}
|
||||
return key_reverse;
|
||||
}
|
||||
|
||||
void subghz_protocol_common_set_callback(SubGhzProtocolCommon* common, SubGhzProtocolCommonCallback callback, void* context) {
|
||||
common->callback = callback;
|
||||
common->context = context;
|
||||
}
|
||||
|
||||
|
||||
void subghz_protocol_common_to_str(SubGhzProtocolCommon* instance, string_t output) {
|
||||
if (instance->to_string) {
|
||||
instance->to_string(instance, output);
|
||||
} else {
|
||||
uint32_t code_found_hi = instance->code_found >> 32;
|
||||
uint32_t code_found_lo = instance->code_found & 0x00000000ffffffff;
|
||||
|
||||
uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->code_found, instance->code_count_bit);
|
||||
|
||||
uint32_t code_found_reverse_hi = code_found_reverse>>32;
|
||||
uint32_t code_found_reverse_lo = code_found_reverse&0x00000000ffffffff;
|
||||
|
||||
if (code_found_hi>0) {
|
||||
string_cat_printf(
|
||||
output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
" KEY:0x%lX%08lX\r\n"
|
||||
" YEK:0x%lX%08lX\r\n"
|
||||
" SN:0x%05lX BTN:%02X\r\n",
|
||||
instance->name,
|
||||
instance->code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
code_found_reverse_hi,
|
||||
code_found_reverse_lo,
|
||||
instance->serial,
|
||||
instance->btn
|
||||
);
|
||||
} else {
|
||||
string_cat_printf(
|
||||
output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
" KEY:0x%lX%lX\r\n"
|
||||
" YEK:0x%lX%lX\r\n"
|
||||
" SN:0x%05lX BTN:%02X\r\n",
|
||||
instance->name,
|
||||
instance->code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
code_found_reverse_hi,
|
||||
code_found_reverse_lo,
|
||||
instance->serial,
|
||||
instance->btn
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
86
lib/subghz/protocols/subghz_protocol_common.h
Normal file
86
lib/subghz/protocols/subghz_protocol_common.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <m-string.h>
|
||||
#include <api-hal.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define bit_read(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bit_set(value, bit) ((value) |= (1UL << (bit)))
|
||||
#define bit_clear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||
#define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit))
|
||||
|
||||
#define SUBGHZ_TX_PIN_HIGTH()
|
||||
#define SUBGHZ_TX_PIN_LOW()
|
||||
#define DURATION_DIFF(x, y) ((x < y) ? (y - x) : (x - y))
|
||||
|
||||
typedef struct SubGhzProtocolCommon SubGhzProtocolCommon;
|
||||
|
||||
typedef void (*SubGhzProtocolCommonCallback)(SubGhzProtocolCommon* parser, void* context);
|
||||
|
||||
typedef void (*SubGhzProtocolCommonToStr)(SubGhzProtocolCommon* instance, string_t output);
|
||||
|
||||
struct SubGhzProtocolCommon {
|
||||
const char* name;
|
||||
uint16_t te_long;
|
||||
uint16_t te_shot;
|
||||
uint16_t te_delta;
|
||||
uint64_t code_found;
|
||||
uint64_t code_last_found;
|
||||
uint8_t code_count_bit;
|
||||
uint8_t code_min_count_bit_for_found;
|
||||
uint8_t parser_step;
|
||||
uint32_t te_last;
|
||||
uint8_t header_count;
|
||||
uint16_t cnt;
|
||||
uint32_t serial;
|
||||
uint8_t btn;
|
||||
|
||||
/* Standard Callback for on rx complete event */
|
||||
SubGhzProtocolCommonCallback callback;
|
||||
void* context;
|
||||
|
||||
/* Dump To String */
|
||||
SubGhzProtocolCommonToStr to_string;
|
||||
};
|
||||
|
||||
|
||||
/** Add data bit to code_found
|
||||
*
|
||||
* @param common - SubGhzProtocolCommon common
|
||||
* @param bit - add bit
|
||||
*/
|
||||
void subghz_protocol_common_add_bit(SubGhzProtocolCommon *common, uint8_t bit);
|
||||
|
||||
/** Checking that the duration is included in the interval
|
||||
*
|
||||
* @param common - SubGhzProtocolCommon common
|
||||
* @param duration duration reference
|
||||
* @param duration_check duration checked
|
||||
* @return true on success
|
||||
*/
|
||||
bool subghz_protocol_common_check_interval(SubGhzProtocolCommon *common, uint32_t duration, uint16_t duration_check);
|
||||
|
||||
/** Bit-by-bit data mirroring
|
||||
*
|
||||
* @param key - data to mirror
|
||||
* @param count_bit number of data bits
|
||||
* @return mirrored data
|
||||
*/
|
||||
uint64_t subghz_protocol_common_reverse_key(uint64_t key, uint8_t count_bit);
|
||||
|
||||
|
||||
/** Callback protocol
|
||||
*
|
||||
* @param instance - SubGhzProtocolCommon* instance
|
||||
* @param callback
|
||||
* @param context
|
||||
*/
|
||||
void subghz_protocol_common_set_callback(SubGhzProtocolCommon* instance, SubGhzProtocolCommonCallback callback, void* context);
|
||||
|
||||
/** outputting information from the parser
|
||||
*
|
||||
* @param instance - SubGhzProtocolCommon* instance
|
||||
* @param output - output string
|
||||
*/
|
||||
void subghz_protocol_common_to_str(SubGhzProtocolCommon* instance, string_t output);
|
||||
|
162
lib/subghz/protocols/subghz_protocol_faac_slh.c
Normal file
162
lib/subghz/protocols/subghz_protocol_faac_slh.c
Normal file
@@ -0,0 +1,162 @@
|
||||
#include "subghz_protocol_faac_slh.h"
|
||||
|
||||
|
||||
struct SubGhzProtocolFaacSLH {
|
||||
SubGhzProtocolCommon common;
|
||||
};
|
||||
|
||||
SubGhzProtocolFaacSLH* subghz_protocol_faac_slh_alloc(void) {
|
||||
SubGhzProtocolFaacSLH* instance = furi_alloc(sizeof(SubGhzProtocolFaacSLH));
|
||||
|
||||
instance->common.name = "Faac SLH";
|
||||
instance->common.code_min_count_bit_for_found = 64;
|
||||
instance->common.te_shot = 255;
|
||||
instance->common.te_long = 595;
|
||||
instance->common.te_delta = 100;
|
||||
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_faac_slh_to_str;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_faac_slh_free(SubGhzProtocolFaacSLH* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolFaacSLH instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_faac_slh_send_bit(SubGhzProtocolFaacSLH* instance, uint8_t bit) {
|
||||
if (bit) {
|
||||
//send bit 1
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
} else {
|
||||
//send bit 0
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_faac_slh_send_key(SubGhzProtocolFaacSLH* instance, uint64_t key, uint8_t bit,uint8_t repeat) {
|
||||
while (repeat--) {
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
//Send header
|
||||
delay_us(instance->common.te_long * 2);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long * 2);
|
||||
//Send key data
|
||||
for (uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_faac_slh_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_faac_slh_reset(SubGhzProtocolFaacSLH* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolFaacSLH instance
|
||||
*/
|
||||
void subghz_protocol_faac_slh_check_remote_controller(SubGhzProtocolFaacSLH* instance) {
|
||||
uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
uint32_t code_fix = code_found_reverse & 0xFFFFFFFF;
|
||||
//uint32_t code_hop = (code_found_reverse >> 24) & 0xFFFFF;
|
||||
|
||||
instance->common.serial = code_fix & 0xFFFFFFF;
|
||||
instance->common.btn = (code_fix >> 28) & 0x0F;
|
||||
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
|
||||
}
|
||||
|
||||
void subghz_protocol_faac_slh_parse(SubGhzProtocolFaacSLH* instance, bool level, uint32_t duration) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((level)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_long * 2)< instance->common.te_delta * 3)) {
|
||||
instance->common.parser_step = 1;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ((!level)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_long * 2)< instance->common.te_delta * 3)) {
|
||||
//Found Preambula
|
||||
instance->common.parser_step = 2;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (level) {
|
||||
if (duration >= (instance->common.te_shot * 3 + instance->common.te_delta)) {
|
||||
instance->common.parser_step = 1;
|
||||
if (instance->common.code_count_bit>= instance->common.code_min_count_bit_for_found) {
|
||||
subghz_protocol_faac_slh_check_remote_controller(instance);
|
||||
}
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
break;
|
||||
} else {
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 3;
|
||||
}
|
||||
|
||||
}else{
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(!level){
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot)< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_long)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
instance->common.parser_step = 2;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last,instance->common.te_long )< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
instance->common.parser_step = 2;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_faac_slh_to_str(SubGhzProtocolFaacSLH* instance, string_t output) {
|
||||
|
||||
uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
uint32_t code_fix = code_found_reverse & 0xFFFFFFFF;
|
||||
uint32_t code_hop = (code_found_reverse >>32) & 0xFFFFFFFF;
|
||||
|
||||
//uint32_t rev_hi =
|
||||
|
||||
string_cat_printf(output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
" KEY:0x%lX%08lX\r\n"
|
||||
" FIX:%08lX \r\n"
|
||||
" HOP:%08lX \r\n"
|
||||
" SN:%07lX BTN:%lX\r\n",
|
||||
instance->common.name,
|
||||
instance->common.code_count_bit,
|
||||
(uint32_t)(instance->common.code_found >> 32),
|
||||
(uint32_t)instance->common.code_found,
|
||||
code_fix, code_hop,
|
||||
instance->common.serial,
|
||||
instance->common.btn);
|
||||
}
|
51
lib/subghz/protocols/subghz_protocol_faac_slh.h
Normal file
51
lib/subghz/protocols/subghz_protocol_faac_slh.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolFaacSLH SubGhzProtocolFaacSLH;
|
||||
|
||||
/** Allocate SubGhzProtocolFaacSLH
|
||||
*
|
||||
* @return SubGhzProtocolFaacSLH*
|
||||
*/
|
||||
SubGhzProtocolFaacSLH* subghz_protocol_faac_slh_alloc();
|
||||
|
||||
/** Free SubGhzProtocolFaacSLH
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_faac_slh_free(SubGhzProtocolFaacSLH* instance);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolFaacSLH instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_faac_slh_send_key(SubGhzProtocolFaacSLH* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolFaacSLH instance
|
||||
*/
|
||||
void subghz_protocol_faac_slh_reset(SubGhzProtocolFaacSLH* instance);
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolFaacSLH instance
|
||||
*/
|
||||
void subghz_protocol_faac_slh_check_remote_controller(SubGhzProtocolFaacSLH* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolFaacSLH instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_faac_slh_parse(SubGhzProtocolFaacSLH* instance, bool level, uint32_t duration);
|
||||
|
||||
/** Outputting information from the parser
|
||||
*
|
||||
* @param instance - SubGhzProtocolFaacSLH* instance
|
||||
* @param output - output string
|
||||
*/
|
||||
void subghz_protocol_faac_slh_to_str(SubGhzProtocolFaacSLH* instance, string_t output);
|
154
lib/subghz/protocols/subghz_protocol_gate_tx.c
Normal file
154
lib/subghz/protocols/subghz_protocol_gate_tx.c
Normal file
@@ -0,0 +1,154 @@
|
||||
#include "subghz_protocol_gate_tx.h"
|
||||
|
||||
|
||||
struct SubGhzProtocolGateTX {
|
||||
SubGhzProtocolCommon common;
|
||||
};
|
||||
|
||||
SubGhzProtocolGateTX* subghz_protocol_gate_tx_alloc(void) {
|
||||
SubGhzProtocolGateTX* instance = furi_alloc(sizeof(SubGhzProtocolGateTX));
|
||||
|
||||
instance->common.name = "GateTX";
|
||||
instance->common.code_min_count_bit_for_found = 24;
|
||||
instance->common.te_shot = 350;
|
||||
instance->common.te_long = 700;
|
||||
instance->common.te_delta = 100;
|
||||
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_gate_tx_to_str;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_gate_tx_free(SubGhzProtocolGateTX* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolGateTX instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_gate_tx_send_bit(SubGhzProtocolGateTX* instance, uint8_t bit) {
|
||||
if (bit) {
|
||||
//send bit 1
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
} else {
|
||||
//send bit 0
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_gate_tx_send_key(SubGhzProtocolGateTX* instance, uint64_t key, uint8_t bit,uint8_t repeat) {
|
||||
while (repeat--) {
|
||||
//Send header
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot * 47); //+2 interval v bit 1
|
||||
//Send start bit
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
//Send key data
|
||||
for (uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_gate_tx_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_gate_tx_reset(SubGhzProtocolGateTX* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolFaacSLH instance
|
||||
*/
|
||||
void subghz_protocol_gate_tx_check_remote_controller(SubGhzProtocolGateTX* instance) {
|
||||
uint32_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
|
||||
instance->common.serial = (code_found_reverse & 0xFF) << 12 | ((code_found_reverse >>8) & 0xFF) << 4 | ((code_found_reverse >>20) & 0x0F) ;
|
||||
instance->common.btn = ((code_found_reverse >> 16) & 0x0F);
|
||||
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
|
||||
}
|
||||
|
||||
void subghz_protocol_gate_tx_parse(SubGhzProtocolGateTX* instance, bool level, uint32_t duration) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((!level)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot * 47)< instance->common.te_delta * 47)) {
|
||||
//Found Preambula
|
||||
instance->common.parser_step = 1;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (level && ((DURATION_DIFF(duration,instance->common.te_long)< instance->common.te_delta*3))){
|
||||
//Found start bit
|
||||
instance->common.parser_step = 2;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!level) {
|
||||
if (duration >= (instance->common.te_shot * 10 + instance->common.te_delta)) {
|
||||
instance->common.parser_step = 1;
|
||||
if (instance->common.code_count_bit>= instance->common.code_min_count_bit_for_found) {
|
||||
subghz_protocol_gate_tx_check_remote_controller(instance);
|
||||
}
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
break;
|
||||
} else {
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 3;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(level){
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot)< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_long)< instance->common.te_delta*3)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
instance->common.parser_step = 2;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last,instance->common.te_long)< instance->common.te_delta*3)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
instance->common.parser_step = 2;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
}else{
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_gate_tx_to_str(SubGhzProtocolGateTX* instance, string_t output) {
|
||||
|
||||
// uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
// uint32_t code_fix = code_found_reverse & 0xFFFFFFFF;
|
||||
// uint32_t code_hop = (code_found_reverse >>32) & 0xFFFFFFFF;
|
||||
|
||||
//uint32_t rev_hi =
|
||||
|
||||
string_cat_printf(output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
" KEY:%06lX\r\n"
|
||||
" SN:%05lX BTN:%lX\r\n",
|
||||
instance->common.name,
|
||||
instance->common.code_count_bit,
|
||||
(uint32_t)(instance->common.code_found & 0xFFFFFF),
|
||||
instance->common.serial,
|
||||
instance->common.btn);
|
||||
}
|
45
lib/subghz/protocols/subghz_protocol_gate_tx.h
Normal file
45
lib/subghz/protocols/subghz_protocol_gate_tx.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolGateTX SubGhzProtocolGateTX;
|
||||
|
||||
/** Allocate SubGhzProtocolGateTX
|
||||
*
|
||||
* @return SubGhzProtocolGateTX*
|
||||
*/
|
||||
SubGhzProtocolGateTX* subghz_protocol_gate_tx_alloc();
|
||||
|
||||
/** Free SubGhzProtocolGateTX
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_gate_tx_free(SubGhzProtocolGateTX* instance);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolGateTX instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_gate_tx_send_key(SubGhzProtocolGateTX* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolGateTX instance
|
||||
*/
|
||||
void subghz_protocol_gate_tx_reset(SubGhzProtocolGateTX* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolGateTX instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_gate_tx_parse(SubGhzProtocolGateTX* instance, bool level, uint32_t duration);
|
||||
|
||||
/** Outputting information from the parser
|
||||
*
|
||||
* @param instance - SubGhzProtocolFaacSLH* instance
|
||||
* @param output - output string
|
||||
*/
|
||||
void subghz_protocol_gate_tx_to_str(SubGhzProtocolGateTX* instance, string_t output);
|
160
lib/subghz/protocols/subghz_protocol_ido.c
Normal file
160
lib/subghz/protocols/subghz_protocol_ido.c
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "subghz_protocol_ido.h"
|
||||
|
||||
|
||||
struct SubGhzProtocolIDo {
|
||||
SubGhzProtocolCommon common;
|
||||
};
|
||||
|
||||
SubGhzProtocolIDo* subghz_protocol_ido_alloc(void) {
|
||||
SubGhzProtocolIDo* instance = furi_alloc(sizeof(SubGhzProtocolIDo));
|
||||
|
||||
instance->common.name = "iDo 117/111"; // PT4301-X";
|
||||
instance->common.code_min_count_bit_for_found = 48;
|
||||
instance->common.te_shot = 450;
|
||||
instance->common.te_long = 1450;
|
||||
instance->common.te_delta = 150;
|
||||
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_ido_to_str;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_ido_free(SubGhzProtocolIDo* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolIDo instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_ido_send_bit(SubGhzProtocolIDo* instance, uint8_t bit) {
|
||||
if (bit) {
|
||||
//send bit 1
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
} else {
|
||||
//send bit 0
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_ido_send_key(SubGhzProtocolIDo* instance, uint64_t key, uint8_t bit,uint8_t repeat) {
|
||||
while (repeat--) {
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
//Send header
|
||||
delay_us(instance->common.te_shot * 10);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot * 10);
|
||||
//Send key data
|
||||
for (uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_ido_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_ido_reset(SubGhzProtocolIDo* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolIDo instance
|
||||
*/
|
||||
void subghz_protocol_ido_check_remote_controller(SubGhzProtocolIDo* instance) {
|
||||
uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
uint32_t code_fix = code_found_reverse & 0xFFFFFF;
|
||||
//uint32_t code_hop = (code_found_reverse >> 24) & 0xFFFFF;
|
||||
|
||||
instance->common.serial = code_fix & 0xFFFFF;
|
||||
instance->common.btn = (code_fix >> 20) & 0x0F;
|
||||
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
|
||||
}
|
||||
|
||||
void subghz_protocol_ido_parse(SubGhzProtocolIDo* instance, bool level, uint32_t duration) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((level)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot * 10)< instance->common.te_delta * 5)) {
|
||||
instance->common.parser_step = 1;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ((!level)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot * 10)< instance->common.te_delta * 5)) {
|
||||
//Found Preambula
|
||||
instance->common.parser_step = 2;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (level) {
|
||||
if (duration >= (instance->common.te_shot * 5 + instance->common.te_delta)) {
|
||||
instance->common.parser_step = 1;
|
||||
if (instance->common.code_count_bit>= instance->common.code_min_count_bit_for_found) {
|
||||
subghz_protocol_ido_check_remote_controller(instance);
|
||||
}
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
break;
|
||||
} else {
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 3;
|
||||
}
|
||||
|
||||
}else{
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(!level){
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot)< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_long)< instance->common.te_delta*3)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
instance->common.parser_step = 2;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot )< instance->common.te_delta*3)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
instance->common.parser_step = 2;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_ido_to_str(SubGhzProtocolIDo* instance, string_t output) {
|
||||
|
||||
uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
uint32_t code_fix = code_found_reverse & 0xFFFFFF;
|
||||
uint32_t code_hop = (code_found_reverse >>24) & 0xFFFFFF;
|
||||
|
||||
string_cat_printf(output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
" KEY:0x%lX%08lX\r\n"
|
||||
" FIX:%06lX \r\n"
|
||||
" HOP:%06lX \r\n"
|
||||
" SN:%05lX BTN:%lX\r\n",
|
||||
instance->common.name,
|
||||
instance->common.code_count_bit,
|
||||
(uint32_t)(instance->common.code_found >> 32),
|
||||
(uint32_t)instance->common.code_found,
|
||||
code_fix, code_hop,
|
||||
instance->common.serial,
|
||||
instance->common.btn);
|
||||
}
|
51
lib/subghz/protocols/subghz_protocol_ido.h
Normal file
51
lib/subghz/protocols/subghz_protocol_ido.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolIDo SubGhzProtocolIDo;
|
||||
|
||||
/** Allocate SubGhzProtocolIDo
|
||||
*
|
||||
* @return SubGhzProtocolIDo*
|
||||
*/
|
||||
SubGhzProtocolIDo* subghz_protocol_ido_alloc();
|
||||
|
||||
/** Free SubGhzProtocolIDo
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_ido_free(SubGhzProtocolIDo* instance);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolIDo instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_ido_send_key(SubGhzProtocolIDo* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolIDo instance
|
||||
*/
|
||||
void subghz_protocol_ido_reset(SubGhzProtocolIDo* instance);
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolIDo instance
|
||||
*/
|
||||
void subghz_protocol_ido_check_remote_controller(SubGhzProtocolIDo* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolIDo instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_ido_parse(SubGhzProtocolIDo* instance, bool level, uint32_t duration);
|
||||
|
||||
/** Outputting information from the parser
|
||||
*
|
||||
* @param instance - SubGhzProtocolIDo* instance
|
||||
* @param output - output string
|
||||
*/
|
||||
void subghz_protocol_ido_to_str(SubGhzProtocolIDo* instance, string_t output);
|
295
lib/subghz/protocols/subghz_protocol_keeloq.c
Normal file
295
lib/subghz/protocols/subghz_protocol_keeloq.c
Normal file
@@ -0,0 +1,295 @@
|
||||
#include "subghz_protocol_keeloq.h"
|
||||
#include "subghz_protocol_keeloq_common.h"
|
||||
|
||||
#include "../subghz_keystore.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include <m-string.h>
|
||||
|
||||
struct SubGhzProtocolKeeloq {
|
||||
SubGhzProtocolCommon common;
|
||||
SubGhzKeystore* keystore;
|
||||
const char* manufacture_name;
|
||||
};
|
||||
|
||||
SubGhzProtocolKeeloq* subghz_protocol_keeloq_alloc(SubGhzKeystore* keystore) {
|
||||
SubGhzProtocolKeeloq* instance = furi_alloc(sizeof(SubGhzProtocolKeeloq));
|
||||
|
||||
instance->keystore = keystore;
|
||||
|
||||
instance->common.name = "KeeLoq";
|
||||
instance->common.code_min_count_bit_for_found = 64;
|
||||
instance->common.te_shot = 400;
|
||||
instance->common.te_long = 800;
|
||||
instance->common.te_delta = 140;
|
||||
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_keeloq_to_str;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_keeloq_free(SubGhzProtocolKeeloq* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/** Checking the accepted code against the database manafacture key
|
||||
*
|
||||
* @param instance SubGhzProtocolKeeloq instance
|
||||
* @param fix fix part of the parcel
|
||||
* @param hop hop encrypted part of the parcel
|
||||
* @return true on successful search
|
||||
*/
|
||||
uint8_t subghz_protocol_keeloq_check_remote_controller_selector(SubGhzProtocolKeeloq* instance, uint32_t fix , uint32_t hop) {
|
||||
uint16_t end_serial = (uint16_t)(fix&0x3FF);
|
||||
uint8_t btn = (uint8_t)(fix>>28);
|
||||
uint32_t decrypt = 0;
|
||||
uint64_t man_normal_learning;
|
||||
|
||||
for
|
||||
M_EACH(manufacture_code, *subghz_keystore_get_data(instance->keystore), SubGhzKeyArray_t) {
|
||||
switch (manufacture_code->type){
|
||||
case KEELOQ_LEARNING_SIMPLE:
|
||||
//Simple Learning
|
||||
decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key);
|
||||
if((decrypt>>28 == btn) && ((((uint16_t)(decrypt>>16)) & 0x3FF) == end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt = decrypt & 0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case KEELOQ_LEARNING_NORMAL:
|
||||
// Normal_Learning
|
||||
// https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37
|
||||
man_normal_learning = subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key);
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning);
|
||||
if( (decrypt>>28 ==btn)&& ((((uint16_t)(decrypt>>16))&0x3FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt = decrypt & 0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case KEELOQ_LEARNING_UNKNOWN:
|
||||
// Simple Learning
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key);
|
||||
if( (decrypt>>28 ==btn) && ((((uint16_t)(decrypt>>16))&0x3FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt = decrypt & 0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
// Check for mirrored man
|
||||
uint64_t man_rev=0;
|
||||
uint64_t man_rev_byte=0;
|
||||
for(uint8_t i=0; i<64; i+=8){
|
||||
man_rev_byte=(uint8_t)(manufacture_code->key >> i);
|
||||
man_rev = man_rev | man_rev_byte << (56-i);
|
||||
}
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, man_rev);
|
||||
if( (decrypt>>28 ==btn) && ((((uint16_t)(decrypt>>16))&0x3FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt= decrypt&0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
//###########################
|
||||
// Normal_Learning
|
||||
// https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37
|
||||
man_normal_learning = subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key);
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning);
|
||||
if( (decrypt>>28 ==btn)&& ((((uint16_t)(decrypt>>16))&0x3FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt= decrypt&0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
// Check for mirrored man
|
||||
man_rev=0;
|
||||
man_rev_byte=0;
|
||||
for(uint8_t i=0; i<64; i+=8){
|
||||
man_rev_byte = (uint8_t)(manufacture_code->key >> i);
|
||||
man_rev = man_rev | man_rev_byte << (56-i);
|
||||
}
|
||||
man_normal_learning = subghz_protocol_keeloq_common_normal_learning(fix, man_rev);
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning);
|
||||
if( (decrypt>>28 ==btn) && ((((uint16_t)(decrypt>>16))&0x3FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt= decrypt&0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
instance->manufacture_name = "Unknown";
|
||||
instance->common.cnt=0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolKeeloq instance
|
||||
*/
|
||||
void subghz_protocol_keeloq_check_remote_controller(SubGhzProtocolKeeloq* instance) {
|
||||
uint64_t key = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
uint32_t key_fix = key >> 32;
|
||||
uint32_t key_hop = key & 0x00000000ffffffff;
|
||||
// Check key AN-Motors
|
||||
if((key_hop >> 24) == ((key_hop>>16)&0x00ff) && (key_fix>>28) ==((key_hop>>12)&0x0f) && (key_hop & 0xFFF ) == 0x404){
|
||||
instance->manufacture_name = "AN-Motors";
|
||||
instance->common.cnt = key_hop>>16;
|
||||
} else if((key_hop & 0xFFF) == (0x000) && (key_fix>>28) ==((key_hop>>12)&0x0f) ){
|
||||
instance->manufacture_name = "HCS101";
|
||||
instance->common.cnt = key_hop>>16;
|
||||
} else {
|
||||
subghz_protocol_keeloq_check_remote_controller_selector(instance, key_fix, key_hop);
|
||||
}
|
||||
instance ->common.serial= key_fix&0x0FFFFFFF;
|
||||
instance->common.btn = key_fix >> 28;
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolKeeloq instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_keeloq_send_bit(SubGhzProtocolKeeloq* instance, uint8_t bit) {
|
||||
if (bit) {
|
||||
// send bit 1
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
} else {
|
||||
// send bit 0
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_keeloq_send_key(SubGhzProtocolKeeloq* instance, uint64_t key, uint8_t bit, uint8_t repeat) {
|
||||
while (repeat--) {
|
||||
// Send header
|
||||
for (uint8_t i = 11; i > 0; i--) {
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
}
|
||||
delay_us(instance->common.te_shot * 9); //+1 up Send header
|
||||
|
||||
for (uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_keeloq_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
// +send 2 status bit
|
||||
subghz_protocol_keeloq_send_bit(instance, 0);
|
||||
subghz_protocol_keeloq_send_bit(instance, 0);
|
||||
// send end
|
||||
subghz_protocol_keeloq_send_bit(instance, 0);
|
||||
delay_us(instance->common.te_shot * 2); //+2 interval END SEND
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_keeloq_reset(SubGhzProtocolKeeloq* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
void subghz_protocol_keeloq_parse(SubGhzProtocolKeeloq* instance, bool level, uint32_t duration) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((level) && DURATION_DIFF(duration, instance->common.te_shot)< instance->common.te_delta) {
|
||||
instance->common.parser_step = 1;
|
||||
instance->common.header_count++;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if ((!level) && (DURATION_DIFF(duration, instance->common.te_shot ) < instance->common.te_delta)) {
|
||||
instance->common.parser_step = 0;
|
||||
break;
|
||||
}
|
||||
if ((instance->common.header_count > 2) && ( DURATION_DIFF(duration, instance->common.te_shot * 10)< instance->common.te_delta * 10)) {
|
||||
// Found header
|
||||
instance->common.parser_step = 2;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
instance->common.header_count = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (level) {
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 3;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (!level) {
|
||||
if (duration >= (instance->common.te_shot * 2 + instance->common.te_delta)) {
|
||||
// Found end TX
|
||||
instance->common.parser_step = 0;
|
||||
if (instance->common.code_count_bit >= instance->common.code_min_count_bit_for_found) {
|
||||
if(instance->common.code_last_found != instance->common.code_found ){
|
||||
subghz_protocol_keeloq_check_remote_controller(instance);
|
||||
}
|
||||
instance->common.code_last_found = instance->common.code_found;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
instance->common.header_count = 0;
|
||||
}
|
||||
break;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last, instance->common.te_shot) < instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_long) < instance->common.te_delta)) {
|
||||
if (instance->common.code_count_bit < instance->common.code_min_count_bit_for_found) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
}
|
||||
instance->common.parser_step = 2;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last, instance->common.te_long) < instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_shot) < instance->common.te_delta)) {
|
||||
if (instance->common.code_count_bit < instance->common.code_min_count_bit_for_found) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
}
|
||||
instance->common.parser_step = 2;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
instance->common.header_count = 0;
|
||||
}
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
instance->common.header_count = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_keeloq_to_str(SubGhzProtocolKeeloq* instance, string_t output) {
|
||||
uint32_t code_found_hi = instance->common.code_found >> 32;
|
||||
uint32_t code_found_lo = instance->common.code_found & 0x00000000ffffffff;
|
||||
|
||||
uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
|
||||
uint32_t code_found_reverse_hi = code_found_reverse>>32;
|
||||
uint32_t code_found_reverse_lo = code_found_reverse&0x00000000ffffffff;
|
||||
string_cat_printf(
|
||||
output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
"KEY:0x%lX%lX\r\n"
|
||||
"FIX:%08lX MF:%s \r\n"
|
||||
"HOP:%08lX \r\n"
|
||||
"SN:%07lX CNT:%04X B:%02lX\r\n",
|
||||
instance->common.name,
|
||||
instance->common.code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
code_found_reverse_hi,
|
||||
instance->manufacture_name,
|
||||
code_found_reverse_lo,
|
||||
instance->common.serial,
|
||||
instance->common.cnt,
|
||||
instance->common.btn
|
||||
);
|
||||
}
|
47
lib/subghz/protocols/subghz_protocol_keeloq.h
Normal file
47
lib/subghz/protocols/subghz_protocol_keeloq.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzKeystore SubGhzKeystore;
|
||||
|
||||
typedef struct SubGhzProtocolKeeloq SubGhzProtocolKeeloq;
|
||||
|
||||
/** Allocate SubGhzProtocolKeeloq
|
||||
*
|
||||
* @return SubGhzProtocolKeeloq*
|
||||
*/
|
||||
SubGhzProtocolKeeloq* subghz_protocol_keeloq_alloc(SubGhzKeystore* keystore);
|
||||
|
||||
/** Free SubGhzProtocolKeeloq
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_keeloq_free(SubGhzProtocolKeeloq* instance);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolKeeloq instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_keeloq_send_key(SubGhzProtocolKeeloq* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolKeeloq instance
|
||||
*/
|
||||
void subghz_protocol_keeloq_reset(SubGhzProtocolKeeloq* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolKeeloq instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_keeloq_parse(SubGhzProtocolKeeloq* instance, bool level, uint32_t duration);
|
||||
|
||||
/** Outputting information from the parser
|
||||
*
|
||||
* @param instance - SubGhzProtocolKeeloq* instance
|
||||
* @param output - output string
|
||||
*/
|
||||
void subghz_protocol_keeloq_to_str(SubGhzProtocolKeeloq* instance, string_t output);
|
49
lib/subghz/protocols/subghz_protocol_keeloq_common.c
Normal file
49
lib/subghz/protocols/subghz_protocol_keeloq_common.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "subghz_protocol_keeloq_common.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include <m-string.h>
|
||||
#include <m-array.h>
|
||||
|
||||
/** Simple Learning Encrypt
|
||||
* @param data - 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
|
||||
* @param key - manufacture (64bit)
|
||||
* @return keelog encrypt data
|
||||
*/
|
||||
inline uint32_t subghz_protocol_keeloq_common_encrypt(const uint32_t data, const uint64_t key) {
|
||||
uint32_t x = data, r;
|
||||
for (r = 0; r < 528; r++)
|
||||
x = (x>>1)^((bit(x,0)^bit(x,16)^(uint32_t)bit(key,r&63)^bit(KEELOQ_NLF,g5(x,1,9,20,26,31)))<<31);
|
||||
return x;
|
||||
}
|
||||
|
||||
/** Simple Learning Decrypt
|
||||
* @param data - keelog encrypt data
|
||||
* @param key - manufacture (64bit)
|
||||
* @return 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
|
||||
*/
|
||||
inline uint32_t subghz_protocol_keeloq_common_decrypt(const uint32_t data, const uint64_t key) {
|
||||
uint32_t x = data, r;
|
||||
for (r = 0; r < 528; r++)
|
||||
x = (x<<1)^bit(x,31)^bit(x,15)^(uint32_t)bit(key,(15-r)&63)^bit(KEELOQ_NLF,g5(x,0,8,19,25,30));
|
||||
return x;
|
||||
}
|
||||
|
||||
/** Normal Learning
|
||||
* @param data - serial number (28bit)
|
||||
* @param key - manufacture (64bit)
|
||||
* @return manufacture for this serial number (64bit)
|
||||
*/
|
||||
inline uint64_t subghz_protocol_keeloq_common_normal_learning(uint32_t data, const uint64_t key){
|
||||
uint32_t k1,k2;
|
||||
|
||||
data&=0x0FFFFFFF;
|
||||
data|=0x20000000;
|
||||
k1=subghz_protocol_keeloq_common_decrypt(data, key);
|
||||
|
||||
data&=0x0FFFFFFF;
|
||||
data|=0x60000000;
|
||||
k2=subghz_protocol_keeloq_common_decrypt(data, key);
|
||||
|
||||
return ((uint64_t)k2<<32)| k1; // key - shifrovanoya
|
||||
}
|
46
lib/subghz/protocols/subghz_protocol_keeloq_common.h
Normal file
46
lib/subghz/protocols/subghz_protocol_keeloq_common.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
/*
|
||||
* Keeloq
|
||||
* https://ru.wikipedia.org/wiki/KeeLoq
|
||||
* https://phreakerclub.com/forum/showthread.php?t=1094
|
||||
*
|
||||
*/
|
||||
|
||||
#define KEELOQ_NLF 0x3A5C742E
|
||||
#define bit(x,n) (((x)>>(n))&1)
|
||||
#define g5(x,a,b,c,d,e) (bit(x,a)+bit(x,b)*2+bit(x,c)*4+bit(x,d)*8+bit(x,e)*16)
|
||||
|
||||
/*
|
||||
* KeeLoq learning types
|
||||
* https://phreakerclub.com/forum/showthread.php?t=67
|
||||
*/
|
||||
#define KEELOQ_LEARNING_UNKNOWN 0u
|
||||
#define KEELOQ_LEARNING_SIMPLE 1u
|
||||
#define KEELOQ_LEARNING_NORMAL 2u
|
||||
#define KEELOQ_LEARNING_SECURE 3u
|
||||
|
||||
|
||||
/** Simple Learning Encrypt
|
||||
* @param data - 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
|
||||
* @param key - manufacture (64bit)
|
||||
* @return keelog encrypt data
|
||||
*/
|
||||
uint32_t subghz_protocol_keeloq_common_encrypt(const uint32_t data, const uint64_t key);
|
||||
|
||||
/** Simple Learning Decrypt
|
||||
* @param data - keelog encrypt data
|
||||
* @param key - manufacture (64bit)
|
||||
* @return 0xBSSSCCCC, B(4bit) key, S(10bit) serial&0x3FF, C(16bit) counter
|
||||
*/
|
||||
uint32_t subghz_protocol_keeloq_common_decrypt(const uint32_t data, const uint64_t key);
|
||||
|
||||
/** Normal Learning
|
||||
* @param data - serial number (28bit)
|
||||
* @param key - manufacture (64bit)
|
||||
* @return manufacture for this serial number (64bit)
|
||||
*/
|
||||
uint64_t subghz_protocol_keeloq_common_normal_learning(uint32_t data, const uint64_t key);
|
200
lib/subghz/protocols/subghz_protocol_nero_sketch.c
Normal file
200
lib/subghz/protocols/subghz_protocol_nero_sketch.c
Normal file
@@ -0,0 +1,200 @@
|
||||
#include "subghz_protocol_nero_sketch.h"
|
||||
|
||||
|
||||
struct SubGhzProtocolNeroSketch {
|
||||
SubGhzProtocolCommon common;
|
||||
};
|
||||
|
||||
SubGhzProtocolNeroSketch* subghz_protocol_nero_sketch_alloc(void) {
|
||||
SubGhzProtocolNeroSketch* instance = furi_alloc(sizeof(SubGhzProtocolNeroSketch));
|
||||
|
||||
instance->common.name = "Nero Sketch";
|
||||
instance->common.code_min_count_bit_for_found = 40;
|
||||
instance->common.te_shot = 330;
|
||||
instance->common.te_long = 660;
|
||||
instance->common.te_delta = 150;
|
||||
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_nero_sketch_to_str;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_nero_sketch_free(SubGhzProtocolNeroSketch* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolNeroSketch instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_nero_sketch_send_bit(SubGhzProtocolNeroSketch* instance, uint8_t bit) {
|
||||
if (bit) {
|
||||
//send bit 1
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
} else {
|
||||
//send bit 0
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_nero_sketch_send_key(SubGhzProtocolNeroSketch* instance, uint64_t key, uint8_t bit,uint8_t repeat) {
|
||||
while (repeat--) {
|
||||
//Send header
|
||||
for(uint8_t i = 0; i < 47; i++){
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
}
|
||||
|
||||
//Send start bit
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot*4);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
|
||||
//Send key data
|
||||
for (uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_nero_sketch_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
//Send stop bit
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot*3);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_nero_sketch_reset(SubGhzProtocolNeroSketch* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolNeroSketch instance
|
||||
*/
|
||||
void subghz_protocol_nero_sketch_check_remote_controller(SubGhzProtocolNeroSketch* instance) {
|
||||
//пока не понятно с серийником, но код статический
|
||||
// uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
// uint32_t code_fix = code_found_reverse & 0xFFFFFFFF;
|
||||
// //uint32_t code_hop = (code_found_reverse >> 24) & 0xFFFFF;
|
||||
|
||||
// instance->common.serial = code_fix & 0xFFFFFFF;
|
||||
// instance->common.btn = (code_fix >> 28) & 0x0F;
|
||||
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
|
||||
}
|
||||
|
||||
void subghz_protocol_nero_sketch_parse(SubGhzProtocolNeroSketch* instance, bool level, uint32_t duration) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((level)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot)< instance->common.te_delta)) {
|
||||
instance->common.parser_step = 1;
|
||||
instance->common.te_last = duration;
|
||||
instance->common.header_count = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (level){
|
||||
if((DURATION_DIFF(duration,instance->common.te_shot)< instance->common.te_delta )
|
||||
|| (DURATION_DIFF(duration,instance->common.te_shot*4)< instance->common.te_delta)) {
|
||||
instance->common.te_last = duration;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
} else if(DURATION_DIFF(duration,instance->common.te_shot)< instance->common.te_delta){
|
||||
if(DURATION_DIFF(instance->common.te_last,instance->common.te_shot)< instance->common.te_delta){
|
||||
// Found header
|
||||
instance->common.header_count++;
|
||||
break;
|
||||
}else if(DURATION_DIFF(instance->common.te_last,instance->common.te_shot*4)< instance->common.te_delta){
|
||||
// Found start bit
|
||||
if(instance->common.header_count>40) {
|
||||
instance->common.parser_step = 2;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
}else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (level) {
|
||||
if (duration >= (instance->common.te_shot * 2 + instance->common.te_delta*2)) {
|
||||
//Found stop bit
|
||||
instance->common.parser_step = 0;
|
||||
if (instance->common.code_count_bit>= instance->common.code_min_count_bit_for_found) {
|
||||
subghz_protocol_nero_sketch_check_remote_controller(instance);
|
||||
}
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
break;
|
||||
} else {
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 3;
|
||||
}
|
||||
|
||||
}else{
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(!level){
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot)< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_long)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
instance->common.parser_step = 2;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last,instance->common.te_long )< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
instance->common.parser_step = 2;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_nero_sketch_to_str(SubGhzProtocolNeroSketch* instance, string_t output) {
|
||||
|
||||
uint32_t code_found_hi = instance->common.code_found >> 32;
|
||||
uint32_t code_found_lo = instance->common.code_found & 0x00000000ffffffff;
|
||||
|
||||
uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
|
||||
uint32_t code_found_reverse_hi = code_found_reverse>>32;
|
||||
uint32_t code_found_reverse_lo = code_found_reverse&0x00000000ffffffff;
|
||||
|
||||
//uint32_t rev_hi =
|
||||
|
||||
string_cat_printf(output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
" KEY:0x%lX%08lX\r\n"
|
||||
" YEK:0x%lX%08lX\r\n",
|
||||
instance->common.name,
|
||||
instance->common.code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
code_found_reverse_hi,
|
||||
code_found_reverse_lo
|
||||
);
|
||||
}
|
51
lib/subghz/protocols/subghz_protocol_nero_sketch.h
Normal file
51
lib/subghz/protocols/subghz_protocol_nero_sketch.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolNeroSketch SubGhzProtocolNeroSketch;
|
||||
|
||||
/** Allocate SubGhzProtocolNeroSketch
|
||||
*
|
||||
* @return SubGhzProtocolNeroSketch*
|
||||
*/
|
||||
SubGhzProtocolNeroSketch* subghz_protocol_nero_sketch_alloc();
|
||||
|
||||
/** Free SubGhzProtocolNeroSketch
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_nero_sketch_free(SubGhzProtocolNeroSketch* instance);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolNeroSketch instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_faac_nero_sketch_key(SubGhzProtocolNeroSketch* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolNeroSketch instance
|
||||
*/
|
||||
void subghz_protocol_nero_sketch_reset(SubGhzProtocolNeroSketch* instance);
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolNeroSketch instance
|
||||
*/
|
||||
void subghz_protocol_nero_sketch_check_remote_controller(SubGhzProtocolNeroSketch* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolNeroSketch instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_nero_sketch_parse(SubGhzProtocolNeroSketch* instance, bool level, uint32_t duration);
|
||||
|
||||
/** Outputting information from the parser
|
||||
*
|
||||
* @param instance - SubGhzProtocolNeroSketch* instance
|
||||
* @param output - output string
|
||||
*/
|
||||
void subghz_protocol_nero_sketch_to_str(SubGhzProtocolNeroSketch* instance, string_t output);
|
126
lib/subghz/protocols/subghz_protocol_nice_flo.c
Normal file
126
lib/subghz/protocols/subghz_protocol_nice_flo.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "subghz_protocol_nice_flo.h"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://phreakerclub.com/447
|
||||
*
|
||||
*/
|
||||
|
||||
struct SubGhzProtocolNiceFlo {
|
||||
SubGhzProtocolCommon common;
|
||||
};
|
||||
|
||||
SubGhzProtocolNiceFlo* subghz_protocol_nice_flo_alloc() {
|
||||
SubGhzProtocolNiceFlo* instance = furi_alloc(sizeof(SubGhzProtocolNiceFlo));
|
||||
|
||||
instance->common.name = "Nice FLO";
|
||||
instance->common.code_min_count_bit_for_found = 12;
|
||||
instance->common.te_shot = 700;
|
||||
instance->common.te_long = 1400;
|
||||
instance->common.te_delta = 200;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flo_free(SubGhzProtocolNiceFlo* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlo instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_nice_flo_send_bit(SubGhzProtocolNiceFlo* instance, uint8_t bit) {
|
||||
if (bit) {
|
||||
//send bit 1
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
} else {
|
||||
//send bit 0
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flo_send_key(SubGhzProtocolNiceFlo* instance, uint64_t key, uint8_t bit, uint8_t repeat) {
|
||||
while (repeat--) {
|
||||
//Send header
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot * 34); //+2 interval v bit 1
|
||||
//Send start bit
|
||||
subghz_protocol_nice_flo_send_bit(instance, 1);
|
||||
//Send key data
|
||||
for (uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_nice_flo_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flo_reset(SubGhzProtocolNiceFlo* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flo_parse(SubGhzProtocolNiceFlo* instance, bool level, uint32_t duration) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((!level)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_shot * 36)< instance->common.te_delta * 36)) {
|
||||
//Found header Nice Flo
|
||||
instance->common.parser_step = 1;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!level) {
|
||||
break;
|
||||
} else if (DURATION_DIFF(duration, instance->common.te_shot)< instance->common.te_delta) {
|
||||
//Found start bit Nice Flo
|
||||
instance->common.parser_step = 2;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!level) { //save interval
|
||||
if (duration >= (instance->common.te_shot * 4)) {
|
||||
instance->common.parser_step = 1;
|
||||
if (instance->common.code_count_bit>= instance->common.code_min_count_bit_for_found) {
|
||||
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 3;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (level) {
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot) < instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_long)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
instance->common.parser_step = 2;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last,instance->common.te_long)< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_shot)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
instance->common.parser_step = 2;
|
||||
} else
|
||||
instance->common.parser_step = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
38
lib/subghz/protocols/subghz_protocol_nice_flo.h
Normal file
38
lib/subghz/protocols/subghz_protocol_nice_flo.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolNiceFlo SubGhzProtocolNiceFlo;
|
||||
|
||||
/** Allocate SubGhzProtocolNiceFlo
|
||||
*
|
||||
* @return SubGhzProtocolNiceFlo*
|
||||
*/
|
||||
SubGhzProtocolNiceFlo* subghz_protocol_nice_flo_alloc();
|
||||
|
||||
/** Free SubGhzProtocolNiceFlo
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_nice_flo_free(SubGhzProtocolNiceFlo* instance);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlo instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_nice_flo_send_key(SubGhzProtocolNiceFlo* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolNiceFlo instance
|
||||
*/
|
||||
void subghz_protocol_nice_flo_reset(SubGhzProtocolNiceFlo* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlo instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_nice_flo_parse(SubGhzProtocolNiceFlo* instance, bool level, uint32_t duration);
|
238
lib/subghz/protocols/subghz_protocol_nice_flor_s.c
Normal file
238
lib/subghz/protocols/subghz_protocol_nice_flor_s.c
Normal file
@@ -0,0 +1,238 @@
|
||||
#include "subghz_protocol_nice_flor_s.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include "file-worker.h"
|
||||
/*
|
||||
* https://phreakerclub.com/1615
|
||||
* https://phreakerclub.com/forum/showthread.php?t=2360
|
||||
* https://vrtp.ru/index.php?showtopic=27867
|
||||
*/
|
||||
|
||||
struct SubGhzProtocolNiceFlorS {
|
||||
SubGhzProtocolCommon common;
|
||||
const char* rainbow_table_file_name;
|
||||
};
|
||||
|
||||
SubGhzProtocolNiceFlorS* subghz_protocol_nice_flor_s_alloc() {
|
||||
SubGhzProtocolNiceFlorS* instance = furi_alloc(sizeof(SubGhzProtocolNiceFlorS));
|
||||
|
||||
instance->common.name = "Nice FloR-S";
|
||||
instance->common.code_min_count_bit_for_found = 52;
|
||||
instance->common.te_shot = 500;
|
||||
instance->common.te_long = 1000;
|
||||
instance->common.te_delta = 300;
|
||||
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_nice_flor_s_to_str;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flor_s_free(SubGhzProtocolNiceFlorS* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flor_s_name_file(SubGhzProtocolNiceFlorS* instance, const char* name) {
|
||||
instance->rainbow_table_file_name = name;
|
||||
printf("Loading Nice FloR S rainbow table %s\r\n", name);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlorS instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_nice_flor_s_send_bit(SubGhzProtocolNiceFlorS* instance, uint8_t bit) {
|
||||
if(bit) {
|
||||
//send bit 1
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
} else {
|
||||
//send bit 0
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flor_s_send_key(
|
||||
SubGhzProtocolNiceFlorS* instance,
|
||||
uint64_t key,
|
||||
uint8_t bit,
|
||||
uint8_t repeat) {
|
||||
while(repeat--) {
|
||||
//Send header
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot * 34);
|
||||
//Send Start Bit
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot * 3);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot * 3);
|
||||
//Send key data
|
||||
for(uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_nice_flor_s_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
//Send Stop Bit
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot * 3);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot * 3);
|
||||
}
|
||||
}
|
||||
|
||||
/** Read bytes from rainbow table
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlorS* instance
|
||||
* @param address - address byte
|
||||
* @return byte data
|
||||
*/
|
||||
uint8_t subghz_nice_flor_s_get_byte_in_file(SubGhzProtocolNiceFlorS* instance, uint32_t address) {
|
||||
if(!instance->rainbow_table_file_name)
|
||||
return 0;
|
||||
|
||||
uint8_t buffer = 0;
|
||||
FileWorker* file_worker = file_worker_alloc(true);
|
||||
if(file_worker_open(file_worker, instance->rainbow_table_file_name, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
file_worker_seek(file_worker, address, true);
|
||||
file_worker_read(file_worker, &buffer, 1);
|
||||
// bool res = file_worker_read(file_worker, &buffer, 1);
|
||||
// furi_assert(res== true);
|
||||
}
|
||||
file_worker_close(file_worker);
|
||||
file_worker_free(file_worker);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/** Decrypt protocol Nice Flor S
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlorS* instance
|
||||
*/
|
||||
void subghz_nice_flor_s_decoder_decrypt(SubGhzProtocolNiceFlorS* instance) {
|
||||
/*
|
||||
* Packet format Nice Flor-s: START-P0-P1-P2-P3-P4-P5-P6-P7-STOP
|
||||
* P0 (4-bit) - button positional code - 1:0x1, 2:0x2, 3:0x4, 4:0x8;
|
||||
* P1 (4-bit) - batch repetition number, calculated by the formula:
|
||||
* P1 = 0xF ^ P0 ^ n; where n changes from 1 to 15, then 0, and then in a circle
|
||||
* key 1: {0xF,0xC,0xD,0xA,0xB,0x8,0x9,0x6,0x7,0x4,0x5,0x2,0x3,0x0,0x1,0xE};
|
||||
* key 2: {0xC,0xF,0xE,0x9,0x8,0xB,0xA,0x5,0x4,0x7,0x6,0x1,0x0,0x3,0x2,0xD};
|
||||
* key 3: {0xA,0x9,0x8,0xF,0xE,0xD,0xC,0x3,0x2,0x1,0x0,0x7,0x6,0x5,0x4,0xB};
|
||||
* P2 (4-bit) - part of the serial number, P2 = (K ^ S3) & 0xF;
|
||||
* P3 (byte) - the major part of the encrypted index
|
||||
* P4 (byte) - the low-order part of the encrypted index
|
||||
* P5 (byte) - part of the serial number, P5 = K ^ S2;
|
||||
* P6 (byte) - part of the serial number, P6 = K ^ S1;
|
||||
* P7 (byte) - part of the serial number, P7 = K ^ S0;
|
||||
* K (byte) - depends on P3 and P4, K = Fk(P3, P4);
|
||||
* S3,S2,S1,S0 - serial number of the console 28 bit.
|
||||
*/
|
||||
|
||||
uint16_t p3p4 = (uint16_t)(instance->common.code_found >> 24);
|
||||
instance->common.cnt = subghz_nice_flor_s_get_byte_in_file(instance,p3p4*2) << 8 | subghz_nice_flor_s_get_byte_in_file(instance,p3p4*2+1); //nice_flor_srainbow_table_for_search[p3p4]; тут надо считать поле с файла причем адрес надо у множить на 2
|
||||
uint8_t k =(uint8_t)(p3p4 & 0x00FF) ^subghz_nice_flor_s_get_byte_in_file(instance,(0x20000 |(instance->common.cnt &0x00ff))); //nice_flor_srainbow_table_for_search[0x10000|subghz_protocol_nice_flor_s.cnt & 0x00ff];
|
||||
|
||||
uint8_t s3 = ((uint8_t)(instance->common.code_found >> 40) ^ k) & 0x0f;
|
||||
uint8_t s2 = ((uint8_t)(instance->common.code_found >> 16) ^ k);
|
||||
uint8_t s1 = ((uint8_t)(instance->common.code_found >> 8) ^ k);
|
||||
uint8_t s0 = ((uint8_t)(instance->common.code_found) ^ k);
|
||||
instance->common.serial = s3 << 24 | s2 << 16 | s1 << 8 | s0;
|
||||
|
||||
instance->common.btn = (instance->common.code_found >> 48) & 0x0f;
|
||||
if(instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flor_s_reset(SubGhzProtocolNiceFlorS* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flor_s_parse(SubGhzProtocolNiceFlorS* instance, bool level, uint32_t duration) {
|
||||
switch(instance->common.parser_step) {
|
||||
case 0:
|
||||
if((!level)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_shot * 38) < instance->common.te_delta * 38)) {
|
||||
//Found start header Nice Flor-S
|
||||
instance->common.parser_step = 1;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if((level)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_shot * 3) < instance->common.te_delta * 3)) {
|
||||
//Found next header Nice Flor-S
|
||||
instance->common.parser_step = 2;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if((!level)
|
||||
&& (DURATION_DIFF(duration, instance->common.te_shot * 3) < instance->common.te_delta * 3)) {
|
||||
//Found header Nice Flor-S
|
||||
instance->common.parser_step = 3;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(level) {
|
||||
if(DURATION_DIFF(duration, instance->common.te_shot * 3) < instance->common.te_delta) {
|
||||
//Found STOP bit
|
||||
instance->common.parser_step = 0;
|
||||
if(instance->common.code_count_bit >=instance->common.code_min_count_bit_for_found) {
|
||||
|
||||
subghz_nice_flor_s_decoder_decrypt(instance);
|
||||
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
//save interval
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 4;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(!level) {
|
||||
if((DURATION_DIFF(instance->common.te_last, instance->common.te_shot) < instance->common.te_delta)
|
||||
&&(DURATION_DIFF(duration, instance->common.te_long) < instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
instance->common.parser_step = 3;
|
||||
} else if(
|
||||
(DURATION_DIFF(instance->common.te_last, instance->common.te_long) < instance->common.te_delta)
|
||||
&&(DURATION_DIFF(duration, instance->common.te_shot) < instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
instance->common.parser_step = 3;
|
||||
} else
|
||||
instance->common.parser_step = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flor_s_to_str(SubGhzProtocolNiceFlorS* instance, string_t output) {
|
||||
uint32_t code_found_hi = instance->common.code_found >> 32;
|
||||
uint32_t code_found_lo = instance->common.code_found & 0x00000000ffffffff;
|
||||
|
||||
string_cat_printf(
|
||||
output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
" KEY:0x%lX%08lX\r\n"
|
||||
" SN:%05lX\r\n"
|
||||
" CNT:%04X BTN:%02lX\r\n",
|
||||
instance->common.name,
|
||||
instance->common.code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
instance->common.serial,
|
||||
instance->common.cnt,
|
||||
instance->common.btn
|
||||
);
|
||||
}
|
52
lib/subghz/protocols/subghz_protocol_nice_flor_s.h
Normal file
52
lib/subghz/protocols/subghz_protocol_nice_flor_s.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolNiceFlorS SubGhzProtocolNiceFlorS;
|
||||
|
||||
/** Allocate SubGhzProtocolNiceFlorS
|
||||
*
|
||||
* @return SubGhzProtocolNiceFlorS*
|
||||
*/
|
||||
SubGhzProtocolNiceFlorS* subghz_protocol_nice_flor_s_alloc();
|
||||
|
||||
/** Free SubGhzProtocolNiceFlorS
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_nice_flor_s_free(SubGhzProtocolNiceFlorS* instance);
|
||||
|
||||
/** File name rainbow table Nice Flor-S
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlorS instance
|
||||
* @param file_name - "path/file_name"
|
||||
*/
|
||||
void subghz_protocol_nice_flor_s_name_file(SubGhzProtocolNiceFlorS* instance, const char* name);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlorS instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_nice_flor_s_send_key(SubGhzProtocolNiceFlorS* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolNiceFlorS instance
|
||||
*/
|
||||
void subghz_protocol_nice_flor_s_reset(SubGhzProtocolNiceFlorS* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlorS instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_nice_flor_s_parse(SubGhzProtocolNiceFlorS* instance, bool level, uint32_t duration);
|
||||
|
||||
/** Outputting information from the parser
|
||||
*
|
||||
* @param instance - SubGhzProtocolNiceFlorS* instance
|
||||
* @param output - output string
|
||||
*/
|
||||
void subghz_protocol_nice_flor_s_to_str(SubGhzProtocolNiceFlorS* instance, string_t output);
|
121
lib/subghz/protocols/subghz_protocol_princeton.c
Normal file
121
lib/subghz/protocols/subghz_protocol_princeton.c
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "subghz_protocol_princeton.h"
|
||||
|
||||
/*
|
||||
* Help
|
||||
* https://phreakerclub.com/447
|
||||
*
|
||||
*/
|
||||
|
||||
struct SubGhzProtocolPrinceton {
|
||||
SubGhzProtocolCommon common;
|
||||
};
|
||||
|
||||
SubGhzProtocolPrinceton* subghz_protocol_princeton_alloc(void) {
|
||||
SubGhzProtocolPrinceton* instance = furi_alloc(sizeof(SubGhzProtocolPrinceton));
|
||||
|
||||
instance->common.name = "Princeton";
|
||||
instance->common.code_min_count_bit_for_found = 24;
|
||||
instance->common.te_shot = 450;//150;
|
||||
instance->common.te_long = 1350;//450;
|
||||
instance->common.te_delta = 200;//50;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_princeton_free(SubGhzProtocolPrinceton* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolPrinceton instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_princeton_send_bit(SubGhzProtocolPrinceton* instance, uint8_t bit) {
|
||||
if (bit) {
|
||||
//send bit 1
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
} else {
|
||||
//send bit 0
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_princeton_send_key(SubGhzProtocolPrinceton* instance, uint64_t key, uint8_t bit,uint8_t repeat) {
|
||||
while (repeat--) {
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
//Send start bit
|
||||
subghz_protocol_princeton_send_bit(instance, 1);
|
||||
//Send header
|
||||
delay_us(instance->common.te_shot * 33); //+2 interval v bit 1
|
||||
//Send key data
|
||||
for (uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_princeton_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_princeton_reset(SubGhzProtocolPrinceton* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
void subghz_protocol_princeton_parse(SubGhzProtocolPrinceton* instance, bool level, uint32_t duration) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((!level)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot * 36) < instance->common.te_delta * 36)) {
|
||||
//Found Preambula
|
||||
instance->common.parser_step = 1;
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
//save duration
|
||||
if (level) {
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 2;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!level) {
|
||||
if (duration >= (instance->common.te_shot * 10 + instance->common.te_delta)) {
|
||||
instance->common.parser_step = 1;
|
||||
if (instance->common.code_count_bit>= instance->common.code_min_count_bit_for_found) {
|
||||
|
||||
instance->common.serial = instance->common.code_found >> 4;
|
||||
instance->common.btn = (uint8_t)instance->common.code_found & 0x00000F;
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
|
||||
}
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot)< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_long)< instance->common.te_delta*3)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
instance->common.parser_step = 1;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last,instance->common.te_long)< instance->common.te_delta*3)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
instance->common.parser_step = 1;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
39
lib/subghz/protocols/subghz_protocol_princeton.h
Normal file
39
lib/subghz/protocols/subghz_protocol_princeton.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolPrinceton SubGhzProtocolPrinceton;
|
||||
|
||||
/** Allocate SubGhzProtocolPrinceton
|
||||
*
|
||||
* @return SubGhzProtocolPrinceton*
|
||||
*/
|
||||
SubGhzProtocolPrinceton* subghz_protocol_princeton_alloc();
|
||||
|
||||
/** Free SubGhzProtocolPrinceton
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_princeton_free(SubGhzProtocolPrinceton* instance);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolPrinceton instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_princeton_send_key(SubGhzProtocolPrinceton* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolPrinceton instance
|
||||
*/
|
||||
void subghz_protocol_princeton_reset(SubGhzProtocolPrinceton* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolPrinceton instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_princeton_parse(SubGhzProtocolPrinceton* instance, bool level, uint32_t duration);
|
||||
|
287
lib/subghz/protocols/subghz_protocol_star_line.c
Normal file
287
lib/subghz/protocols/subghz_protocol_star_line.c
Normal file
@@ -0,0 +1,287 @@
|
||||
#include "subghz_protocol_star_line.h"
|
||||
#include "subghz_protocol_keeloq_common.h"
|
||||
|
||||
#include "../subghz_keystore.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include <m-string.h>
|
||||
#include <m-array.h>
|
||||
|
||||
|
||||
struct SubGhzProtocolStarLine {
|
||||
SubGhzProtocolCommon common;
|
||||
SubGhzKeystore* keystore;
|
||||
const char* manufacture_name;
|
||||
};
|
||||
|
||||
SubGhzProtocolStarLine* subghz_protocol_star_line_alloc(SubGhzKeystore* keystore) {
|
||||
SubGhzProtocolStarLine* instance = furi_alloc(sizeof(SubGhzProtocolStarLine));
|
||||
|
||||
instance->keystore = keystore;
|
||||
|
||||
instance->common.name = "Star Line";
|
||||
instance->common.code_min_count_bit_for_found = 64;
|
||||
instance->common.te_shot = 250;
|
||||
instance->common.te_long = 500;
|
||||
instance->common.te_delta = 120;
|
||||
instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_star_line_to_str;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_star_line_free(SubGhzProtocolStarLine* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
/** Send bit
|
||||
*
|
||||
* @param instance - SubGhzProtocolStarLine instance
|
||||
* @param bit - bit
|
||||
*/
|
||||
void subghz_protocol_star_line_send_bit(SubGhzProtocolStarLine* instance, uint8_t bit) {
|
||||
if (bit) {
|
||||
//send bit 1
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long);
|
||||
} else {
|
||||
//send bit 0
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_shot);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_shot);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_star_line_send_key(SubGhzProtocolStarLine* instance, uint64_t key, uint8_t bit,uint8_t repeat) {
|
||||
while (repeat--) {
|
||||
//Send header
|
||||
for(uint8_t i = 0; i < 6; i++){
|
||||
SUBGHZ_TX_PIN_HIGTH();
|
||||
delay_us(instance->common.te_long * 2);
|
||||
SUBGHZ_TX_PIN_LOW();
|
||||
delay_us(instance->common.te_long * 2);
|
||||
}
|
||||
//Send Start bit ??????????
|
||||
//Send key data
|
||||
for (uint8_t i = bit; i > 0; i--) {
|
||||
subghz_protocol_star_line_send_bit(instance, bit_read(key, i - 1));
|
||||
}
|
||||
//Send Stop bit ??????????
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_star_line_reset(SubGhzProtocolStarLine* instance) {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
|
||||
/** Checking the accepted code against the database manafacture key
|
||||
*
|
||||
* @param instance SubGhzProtocolStarLine instance
|
||||
* @param fix fix part of the parcel
|
||||
* @param hop hop encrypted part of the parcel
|
||||
* @return true on successful search
|
||||
*/
|
||||
uint8_t subghz_protocol_star_line_check_remote_controller_selector(SubGhzProtocolStarLine* instance, uint32_t fix , uint32_t hop) {
|
||||
uint16_t end_serial = (uint16_t)(fix&0xFF);
|
||||
uint8_t btn = (uint8_t)(fix>>24);
|
||||
uint32_t decrypt = 0;
|
||||
uint64_t man_normal_learning;
|
||||
|
||||
for
|
||||
M_EACH(manufacture_code, *subghz_keystore_get_data(instance->keystore), SubGhzKeyArray_t) {
|
||||
switch (manufacture_code->type){
|
||||
case KEELOQ_LEARNING_SIMPLE:
|
||||
//Simple Learning
|
||||
decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key);
|
||||
if((decrypt>>24 == btn) && ((((uint16_t)(decrypt>>16)) & 0x00FF) == end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt = decrypt & 0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case KEELOQ_LEARNING_NORMAL:
|
||||
// Normal_Learning
|
||||
// https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37
|
||||
man_normal_learning = subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key);
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning);
|
||||
if( (decrypt>>24 ==btn)&& ((((uint16_t)(decrypt>>16))&0x00FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt = decrypt & 0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case KEELOQ_LEARNING_UNKNOWN:
|
||||
// Simple Learning
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key);
|
||||
if( (decrypt>>24 ==btn) && ((((uint16_t)(decrypt>>16))&0x00FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt = decrypt & 0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
// Check for mirrored man
|
||||
uint64_t man_rev=0;
|
||||
uint64_t man_rev_byte=0;
|
||||
for(uint8_t i=0; i<64; i+=8){
|
||||
man_rev_byte=(uint8_t)(manufacture_code->key >> i);
|
||||
man_rev = man_rev | man_rev_byte << (56-i);
|
||||
}
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, man_rev);
|
||||
if( (decrypt>>24 ==btn) && ((((uint16_t)(decrypt>>16))&0x00FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt= decrypt&0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
//###########################
|
||||
// Normal_Learning
|
||||
// https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37
|
||||
man_normal_learning = subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key);
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning);
|
||||
if( (decrypt>>24 ==btn)&& ((((uint16_t)(decrypt>>16))&0x00FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt= decrypt&0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
// Check for mirrored man
|
||||
man_rev=0;
|
||||
man_rev_byte=0;
|
||||
for(uint8_t i=0; i<64; i+=8){
|
||||
man_rev_byte = (uint8_t)(manufacture_code->key >> i);
|
||||
man_rev = man_rev | man_rev_byte << (56-i);
|
||||
}
|
||||
man_normal_learning = subghz_protocol_keeloq_common_normal_learning(fix, man_rev);
|
||||
decrypt=subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning);
|
||||
if( (decrypt>>24 ==btn) && ((((uint16_t)(decrypt>>16))&0x00FF)==end_serial)){
|
||||
instance->manufacture_name = string_get_cstr(manufacture_code->name);
|
||||
instance->common.cnt= decrypt&0x0000FFFF;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
instance->manufacture_name = "Unknown";
|
||||
instance->common.cnt=0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolStarLine instance
|
||||
*/
|
||||
void subghz_protocol_star_line_check_remote_controller(SubGhzProtocolStarLine* instance) {
|
||||
uint64_t key = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
uint32_t key_fix = key >> 32;
|
||||
uint32_t key_hop = key & 0x00000000ffffffff;
|
||||
|
||||
subghz_protocol_star_line_check_remote_controller_selector(instance, key_fix, key_hop);
|
||||
|
||||
instance ->common.serial= key_fix&0x00FFFFFF;
|
||||
instance->common.btn = key_fix >> 24;
|
||||
|
||||
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
|
||||
}
|
||||
|
||||
void subghz_protocol_star_line_parse(SubGhzProtocolStarLine* instance, bool level, uint32_t duration) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if (level){
|
||||
if(DURATION_DIFF(duration,instance->common.te_long * 2)< instance->common.te_delta * 2) {
|
||||
instance->common.parser_step = 1;
|
||||
instance->common.header_count++;
|
||||
} else if(instance->common.header_count>4){
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 3;
|
||||
}
|
||||
}else{
|
||||
instance->common.parser_step = 0;
|
||||
instance->common.header_count = 0;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ((!level)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_long * 2)< instance->common.te_delta * 2)) {
|
||||
//Found Preambula
|
||||
instance->common.parser_step = 0;
|
||||
} else {
|
||||
instance->common.header_count = 0;
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (level) {
|
||||
if (duration >= (instance->common.te_long + instance->common.te_delta)) {
|
||||
instance->common.parser_step = 0;
|
||||
if (instance->common.code_count_bit>= instance->common.code_min_count_bit_for_found) {
|
||||
if(instance->common.code_last_found != instance->common.code_found){
|
||||
subghz_protocol_star_line_check_remote_controller(instance);
|
||||
}
|
||||
}
|
||||
instance->common.code_found = 0;
|
||||
instance->common.code_count_bit = 0;
|
||||
instance->common.header_count = 0;
|
||||
break;
|
||||
} else {
|
||||
instance->common.te_last = duration;
|
||||
instance->common.parser_step = 3;
|
||||
}
|
||||
|
||||
}else{
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(!level){
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot)< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_shot)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 0);
|
||||
instance->common.parser_step = 2;
|
||||
} else if ((DURATION_DIFF(instance->common.te_last,instance->common.te_long )< instance->common.te_delta)
|
||||
&& (DURATION_DIFF(duration,instance->common.te_long)< instance->common.te_delta)) {
|
||||
subghz_protocol_common_add_bit(&instance->common, 1);
|
||||
instance->common.parser_step = 2;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_star_line_to_str(SubGhzProtocolStarLine* instance, string_t output) {
|
||||
uint32_t code_found_hi = instance->common.code_found >> 32;
|
||||
uint32_t code_found_lo = instance->common.code_found & 0x00000000ffffffff;
|
||||
|
||||
uint64_t code_found_reverse = subghz_protocol_common_reverse_key(instance->common.code_found, instance->common.code_count_bit);
|
||||
|
||||
uint32_t code_found_reverse_hi = code_found_reverse>>32;
|
||||
uint32_t code_found_reverse_lo = code_found_reverse&0x00000000ffffffff;
|
||||
string_cat_printf(
|
||||
output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
"KEY:0x%lX%lX\r\n"
|
||||
"FIX:%08lX MF:%s \r\n"
|
||||
"HOP:%08lX \r\n"
|
||||
"SN:%06lX CNT:%04X B:%02lX\r\n",
|
||||
instance->common.name,
|
||||
instance->common.code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
code_found_reverse_hi,
|
||||
instance->manufacture_name,
|
||||
code_found_reverse_lo,
|
||||
instance->common.serial,
|
||||
instance->common.cnt,
|
||||
instance->common.btn
|
||||
);
|
||||
}
|
53
lib/subghz/protocols/subghz_protocol_star_line.h
Normal file
53
lib/subghz/protocols/subghz_protocol_star_line.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzKeystore SubGhzKeystore;
|
||||
|
||||
typedef struct SubGhzProtocolStarLine SubGhzProtocolStarLine;
|
||||
|
||||
/** Allocate SubGhzProtocolStarLine
|
||||
*
|
||||
* @return SubGhzProtocolStarLine*
|
||||
*/
|
||||
SubGhzProtocolStarLine* subghz_protocol_star_line_alloc(SubGhzKeystore* keystore);
|
||||
|
||||
/** Free SubGhzProtocolStarLine
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
void subghz_protocol_star_line_free(SubGhzProtocolStarLine* instance);
|
||||
|
||||
/** Sends the key on the air
|
||||
*
|
||||
* @param instance - SubGhzProtocolStarLine instance
|
||||
* @param key - key send
|
||||
* @param bit - count bit key
|
||||
* @param repeat - repeat send key
|
||||
*/
|
||||
void subghz_protocol_star_line_send_key(SubGhzProtocolStarLine* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
/** Reset internal state
|
||||
* @param instance - SubGhzProtocolStarLine instance
|
||||
*/
|
||||
void subghz_protocol_star_line_reset(SubGhzProtocolStarLine* instance);
|
||||
|
||||
/** Analysis of received data
|
||||
*
|
||||
* @param instance SubGhzProtocolStarLine instance
|
||||
*/
|
||||
void subghz_protocol_star_line_check_remote_controller(SubGhzProtocolStarLine* instance);
|
||||
|
||||
/** Parse accepted duration
|
||||
*
|
||||
* @param instance - SubGhzProtocolStarLine instance
|
||||
* @param data - LevelDuration level_duration
|
||||
*/
|
||||
void subghz_protocol_star_line_parse(SubGhzProtocolStarLine* instance, bool level, uint32_t duration);
|
||||
|
||||
/** Outputting information from the parser
|
||||
*
|
||||
* @param instance - SubGhzProtocolStarLine* instance
|
||||
* @param output - output string
|
||||
*/
|
||||
void subghz_protocol_star_line_to_str(SubGhzProtocolStarLine* instance, string_t output);
|
Reference in New Issue
Block a user