[FL-1496] SubGhz: Library, Cli, Application (#543)
* ApiHal: set frequency and path in one go. Drivers: proper frequency registers calculation for CC1101. Update subghz cli to match new api. * SubGhz: preparation for parsers porting, tim2 sharing * ApiHal: add interrupts API, move all TIM2 related things there. * SubGhz: refactor protocol lib and add keeloq. * SubGhz: proper init_set for keeloq manafacture key * SubGhz: port more protocols to lib * SubGhz: load keeloq manufacture keys from sd card (if any). * SubGhz: format output from protocols. * SubGhz: use default frequency in subghz_rx cli command. * SubGhz: keeloq key types * Fix compillation error when internal storage disabled * SubGhz: minor cleanup * SubGhz: properly handle timeout and reset signal in subghz_rx * SubGhz: Worker, Capture View. Furi: emulate thread join. * SubGhz: free strings on keeloq key load end * SubGhz: update protocols reporting API, app refactoring and capture view, update API HAL usage. * SubGhz: update dump formatting * ApiHal: backport subghz preset to F5 * ApiHal: backport subghz frequency range to F5
This commit is contained in:
130
lib/fl_subghz/protocols/subghz_protocol.c
Normal file
130
lib/fl_subghz/protocols/subghz_protocol.c
Normal file
@@ -0,0 +1,130 @@
|
||||
#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 <furi.h>
|
||||
#include <m-string.h>
|
||||
#include <filesystem-api.h>
|
||||
|
||||
#define FILE_BUFFER_SIZE 64
|
||||
|
||||
struct SubGhzProtocol {
|
||||
SubGhzProtocolCame* came;
|
||||
SubGhzProtocolKeeloq* keeloq;
|
||||
SubGhzProtocolNiceFlo* nice_flo;
|
||||
SubGhzProtocolNiceFlorS* nice_flor_s;
|
||||
SubGhzProtocolPrinceton* princeton;
|
||||
|
||||
SubGhzProtocolTextCallback text_callback;
|
||||
void* text_callback_context;
|
||||
};
|
||||
|
||||
static void subghz_protocol_came_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);
|
||||
}
|
||||
|
||||
SubGhzProtocol* subghz_protocol_alloc() {
|
||||
SubGhzProtocol* instance = furi_alloc(sizeof(SubGhzProtocol));
|
||||
|
||||
instance->came = subghz_protocol_came_alloc();
|
||||
instance->keeloq = subghz_protocol_keeloq_alloc();
|
||||
instance->princeton = subghz_protocol_princeton_alloc();
|
||||
instance->nice_flo = subghz_protocol_nice_flo_alloc();
|
||||
instance->nice_flor_s = subghz_protocol_nice_flor_s_alloc();
|
||||
|
||||
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);
|
||||
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_enable_dump(SubGhzProtocol* instance, SubGhzProtocolTextCallback callback, void* context) {
|
||||
furi_assert(instance);
|
||||
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->came, subghz_protocol_came_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->keeloq, subghz_protocol_came_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->princeton, subghz_protocol_came_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->nice_flo, subghz_protocol_came_rx_callback, instance);
|
||||
subghz_protocol_common_set_callback((SubGhzProtocolCommon*)instance->nice_flor_s, subghz_protocol_came_rx_callback, instance);
|
||||
|
||||
instance->text_callback = callback;
|
||||
instance->text_callback_context = context;
|
||||
}
|
||||
|
||||
static void subghz_protocol_load_keeloq_file_process_line(SubGhzProtocol* instance, string_t line) {
|
||||
uint64_t key = 0;
|
||||
uint16_t type = 0;
|
||||
char skey[17] = {0};
|
||||
char name[65] = {0};
|
||||
int ret = sscanf(string_get_cstr(line), "%16s:%hu:%64s", skey, &type, name);
|
||||
key = strtoull(skey, NULL, 16);
|
||||
if (ret == 3) {
|
||||
subghz_protocol_keeloq_add_manafacture_key(instance->keeloq, name, key, type);
|
||||
} else {
|
||||
printf("Failed to load line: %s\r\n", string_get_cstr(line));
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_load_keeloq_file(SubGhzProtocol* instance, const char* file_name) {
|
||||
File manufacture_keys_file;
|
||||
FS_Api* fs_api = furi_record_open("sdcard");
|
||||
fs_api->file.open(&manufacture_keys_file, file_name, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
string_t line;
|
||||
string_init(line);
|
||||
if(manufacture_keys_file.error_id == FSE_OK) {
|
||||
printf("Loading manufacture keys file %s\r\n", file_name);
|
||||
char buffer[FILE_BUFFER_SIZE];
|
||||
uint16_t ret;
|
||||
do {
|
||||
ret = fs_api->file.read(&manufacture_keys_file, buffer, FILE_BUFFER_SIZE);
|
||||
for (uint16_t i=0; i < ret; i++) {
|
||||
if (buffer[i] == '\n' && string_size(line) > 0) {
|
||||
subghz_protocol_load_keeloq_file_process_line(instance, line);
|
||||
string_clean(line);
|
||||
} else {
|
||||
string_push_back(line, buffer[i]);
|
||||
}
|
||||
}
|
||||
} while(ret > 0);
|
||||
} else {
|
||||
printf("Manufacture keys file is not found: %s\r\n", file_name);
|
||||
}
|
||||
string_clear(line);
|
||||
fs_api->file.close(&manufacture_keys_file);
|
||||
furi_record_close("sdcard");
|
||||
}
|
||||
|
||||
void subghz_protocol_reset(SubGhzProtocol* instance) {
|
||||
}
|
||||
|
||||
void subghz_protocol_parse(SubGhzProtocol* instance, LevelPair data) {
|
||||
subghz_protocol_came_parse(instance->came, data);
|
||||
subghz_protocol_keeloq_parse(instance->keeloq, data);
|
||||
subghz_protocol_princeton_parse(instance->princeton, data);
|
||||
subghz_protocol_nice_flo_parse(instance->nice_flo, data);
|
||||
subghz_protocol_nice_flor_s_parse(instance->nice_flor_s, data);
|
||||
}
|
19
lib/fl_subghz/protocols/subghz_protocol.h
Normal file
19
lib/fl_subghz/protocols/subghz_protocol.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef void (*SubGhzProtocolTextCallback)(string_t text, void* context);
|
||||
|
||||
typedef struct SubGhzProtocol SubGhzProtocol;
|
||||
|
||||
SubGhzProtocol* subghz_protocol_alloc();
|
||||
|
||||
void subghz_protocol_free(SubGhzProtocol* instance);
|
||||
|
||||
void subghz_protocol_enable_dump(SubGhzProtocol* instance, SubGhzProtocolTextCallback callback, void* context);
|
||||
|
||||
void subghz_protocol_load_keeloq_file(SubGhzProtocol* instance, const char* file_name);
|
||||
|
||||
void subghz_protocol_reset(SubGhzProtocol* instance);
|
||||
|
||||
void subghz_protocol_parse(SubGhzProtocol* instance, LevelPair data);
|
119
lib/fl_subghz/protocols/subghz_protocol_came.c
Normal file
119
lib/fl_subghz/protocols/subghz_protocol_came.c
Normal file
@@ -0,0 +1,119 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
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_parse(SubGhzProtocolCame* instance, LevelPair data) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((data.level == ApiHalSubGhzCaptureLevelLow)
|
||||
&& (DURATION_DIFF(data.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 (data.level == ApiHalSubGhzCaptureLevelLow) {
|
||||
break;
|
||||
} else if (DURATION_DIFF(data.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 (data.level == ApiHalSubGhzCaptureLevelLow) { //save interval
|
||||
if (data.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) {
|
||||
|
||||
//ToDo out data display
|
||||
if (instance->common.callback)
|
||||
instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
}
|
||||
break;
|
||||
}
|
||||
instance->common.te_last = data.duration;
|
||||
instance->common.parser_step = 3;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (data.level == ApiHalSubGhzCaptureLevelHigh) {
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot) < instance->common.te_delta)
|
||||
&& (DURATION_DIFF(data.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(data.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;
|
||||
}
|
||||
}
|
13
lib/fl_subghz/protocols/subghz_protocol_came.h
Normal file
13
lib/fl_subghz/protocols/subghz_protocol_came.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolCame SubGhzProtocolCame;
|
||||
|
||||
SubGhzProtocolCame* subghz_protocol_came_alloc();
|
||||
|
||||
void subghz_protocol_came_free(SubGhzProtocolCame* instance);
|
||||
|
||||
void subghz_protocol_came_send_key(SubGhzProtocolCame* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
void subghz_protocol_came_parse(SubGhzProtocolCame* instance, LevelPair data);
|
4
lib/fl_subghz/protocols/subghz_protocol_cfm.c
Normal file
4
lib/fl_subghz/protocols/subghz_protocol_cfm.c
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
/*
|
||||
* https://phreakerclub.com/616
|
||||
*/
|
0
lib/fl_subghz/protocols/subghz_protocol_cfm.h
Normal file
0
lib/fl_subghz/protocols/subghz_protocol_cfm.h
Normal file
70
lib/fl_subghz/protocols/subghz_protocol_common.c
Normal file
70
lib/fl_subghz/protocols/subghz_protocol_common.c
Normal file
@@ -0,0 +1,70 @@
|
||||
#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++;
|
||||
}
|
||||
|
||||
uint8_t subghz_protocol_common_check_interval (SubGhzProtocolCommon *common, uint32_t interval, uint16_t interval_check) {
|
||||
if ((interval_check >= (interval - common->te_delta))&&(interval_check <= (interval + common->te_delta))){
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
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",
|
||||
instance->name,
|
||||
instance->code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
code_found_reverse_hi,
|
||||
code_found_reverse_lo
|
||||
);
|
||||
} else {
|
||||
string_cat_printf(
|
||||
output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
" KEY:0x%lX%lX\r\n"
|
||||
" YEK:0x%lX%lX\r\n",
|
||||
instance->name,
|
||||
instance->code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
code_found_reverse_hi,
|
||||
code_found_reverse_lo
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
53
lib/fl_subghz/protocols/subghz_protocol_common.h
Normal file
53
lib/fl_subghz/protocols/subghz_protocol_common.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#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;
|
||||
uint16_t te_last;
|
||||
uint8_t header_count;
|
||||
uint16_t cnt;
|
||||
|
||||
/* Standard Callback for on rx complete event */
|
||||
SubGhzProtocolCommonCallback callback;
|
||||
void* context;
|
||||
|
||||
/* Dump To String */
|
||||
SubGhzProtocolCommonToStr to_string;
|
||||
};
|
||||
|
||||
void subghz_protocol_common_add_bit(SubGhzProtocolCommon *common, uint8_t bit);
|
||||
|
||||
uint8_t subghz_protocol_common_check_interval(SubGhzProtocolCommon *common, uint32_t interval, uint16_t interval_check);
|
||||
|
||||
uint64_t subghz_protocol_common_reverse_key(uint64_t key, uint8_t count_bit);
|
||||
|
||||
void subghz_protocol_common_set_callback(SubGhzProtocolCommon* instance, SubGhzProtocolCommonCallback callback, void* context);
|
||||
|
||||
void subghz_protocol_common_to_str(SubGhzProtocolCommon* instance, string_t output);
|
||||
|
378
lib/fl_subghz/protocols/subghz_protocol_keeloq.c
Normal file
378
lib/fl_subghz/protocols/subghz_protocol_keeloq.c
Normal file
@@ -0,0 +1,378 @@
|
||||
#include "subghz_protocol_keeloq.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include <m-string.h>
|
||||
#include <m-array.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
|
||||
|
||||
typedef struct {
|
||||
string_t name;
|
||||
uint64_t key;
|
||||
uint16_t type;
|
||||
} KeeLoqManufactureCode;
|
||||
|
||||
ARRAY_DEF(KeeLoqManufactureCodeArray, KeeLoqManufactureCode, M_POD_OPLIST)
|
||||
#define M_OPL_KeeLoqManufactureCodeArray_t() ARRAY_OPLIST(KeeLoqManufactureCodeArray, M_POD_OPLIST)
|
||||
|
||||
struct SubGhzProtocolKeeloq {
|
||||
SubGhzProtocolCommon common;
|
||||
KeeLoqManufactureCodeArray_t manufacture_codes;
|
||||
const char* manufacture_name;
|
||||
};
|
||||
|
||||
/** Simple Learning Encrypt
|
||||
* @param data - serial number (28bit)
|
||||
* @param key - manufacture (64bit)
|
||||
* @return ?
|
||||
*/
|
||||
inline uint32_t subghz_protocol_keeloq_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 - serial number (28bit)
|
||||
* @param key - manufacture (64bit)
|
||||
* @return ?
|
||||
*/
|
||||
inline uint32_t subghz_protocol_keeloq_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 ?
|
||||
*/
|
||||
inline uint64_t subghz_protocol_keeloq_normal_learning(uint32_t data, const uint64_t key){
|
||||
uint32_t k1,k2;
|
||||
|
||||
data&=0x0FFFFFFF;
|
||||
data|=0x20000000;
|
||||
k1=subghz_protocol_keeloq_decrypt(data, key);
|
||||
|
||||
data&=0x0FFFFFFF;
|
||||
data|=0x60000000;
|
||||
k2=subghz_protocol_keeloq_decrypt(data, key);
|
||||
|
||||
return ((uint64_t)k2<<32)| k1; // key - shifrovanoya
|
||||
}
|
||||
|
||||
SubGhzProtocolKeeloq* subghz_protocol_keeloq_alloc() {
|
||||
SubGhzProtocolKeeloq* instance = furi_alloc(sizeof(SubGhzProtocolKeeloq));
|
||||
|
||||
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;
|
||||
|
||||
KeeLoqManufactureCodeArray_init(instance->manufacture_codes);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_keeloq_free(SubGhzProtocolKeeloq* instance) {
|
||||
furi_assert(instance);
|
||||
for
|
||||
M_EACH(manufacture_code, instance->manufacture_codes, KeeLoqManufactureCodeArray_t) {
|
||||
string_clear(manufacture_code->name);
|
||||
manufacture_code->key = 0;
|
||||
}
|
||||
KeeLoqManufactureCodeArray_clear(instance->manufacture_codes);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_protocol_keeloq_add_manafacture_key(SubGhzProtocolKeeloq* instance, const char* name, uint64_t key, uint16_t type) {
|
||||
KeeLoqManufactureCode* manufacture_code = KeeLoqManufactureCodeArray_push_raw(instance->manufacture_codes);
|
||||
string_init_set_str(manufacture_code->name, name);
|
||||
manufacture_code->key = key;
|
||||
manufacture_code->type = type;
|
||||
}
|
||||
|
||||
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, instance->manufacture_codes, KeeLoqManufactureCodeArray_t) {
|
||||
switch (manufacture_code->type){
|
||||
case KEELOQ_LEARNING_SIMPLE:
|
||||
//Simple Learning
|
||||
decrypt = subghz_protocol_keeloq_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_normal_learning(fix, manufacture_code->key);
|
||||
decrypt=subghz_protocol_keeloq_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_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_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_normal_learning(fix, manufacture_code->key);
|
||||
decrypt=subghz_protocol_keeloq_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_normal_learning(fix, man_rev);
|
||||
decrypt=subghz_protocol_keeloq_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;
|
||||
}
|
||||
|
||||
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) ){
|
||||
instance->manufacture_name = "AN-Motors";
|
||||
instance->common.cnt = key_hop>>16;
|
||||
} else {
|
||||
subghz_protocol_keeloq_check_remote_controller_selector(instance, key_fix, key_hop);
|
||||
}
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
}
|
||||
|
||||
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_parse(SubGhzProtocolKeeloq* instance, LevelPair data) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((data.level == ApiHalSubGhzCaptureLevelHigh) && DURATION_DIFF(data.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 ((data.level == ApiHalSubGhzCaptureLevelLow) && (DURATION_DIFF(data.duration, instance->common.te_shot ) < instance->common.te_delta)) {
|
||||
instance->common.parser_step = 0;
|
||||
break;
|
||||
}
|
||||
if ((instance->common.header_count > 2) && ( DURATION_DIFF(data.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 (data.level == ApiHalSubGhzCaptureLevelHigh) {
|
||||
instance->common.te_last = data.duration;
|
||||
instance->common.parser_step = 3;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (data.level == ApiHalSubGhzCaptureLevelLow) {
|
||||
if (data.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) {
|
||||
//&& (instance->common.code_last_found != instance->common.code_found )) {
|
||||
instance->common.code_last_found = instance->common.code_found;
|
||||
|
||||
//ToDo out data display
|
||||
subghz_protocol_keeloq_check_remote_controller(instance);
|
||||
|
||||
//Print_Code(&KEELOQ);
|
||||
//Reverse_Code(KEELOQ.Code);
|
||||
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(data.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(data.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) {
|
||||
//snprintf(BufTX, sizeof(BufTX),"Protocol %s: %d Bit | KEY:0x%llX HEX \n\r", common->Name_Protocol, common->Count_BIT, common->Code);
|
||||
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;
|
||||
|
||||
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",
|
||||
instance->common.name,
|
||||
instance->common.code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
code_found_reverse_hi,
|
||||
code_found_reverse_lo
|
||||
);
|
||||
} else {
|
||||
string_cat_printf(
|
||||
output,
|
||||
"Protocol %s, %d Bit\r\n"
|
||||
" KEY:0x%lX%lX\r\n"
|
||||
" YEK:0x%lX%lX\r\n",
|
||||
instance->common.name,
|
||||
instance->common.code_count_bit,
|
||||
code_found_hi,
|
||||
code_found_lo,
|
||||
code_found_reverse_hi,
|
||||
code_found_reverse_lo
|
||||
);
|
||||
}
|
||||
string_cat_printf(
|
||||
output,
|
||||
" MF:%s FIX:%lX\r\n"
|
||||
" HOP:%lX CNT:%04X BTN:%02lX\r\n",
|
||||
instance->manufacture_name,
|
||||
code_found_reverse_hi,
|
||||
code_found_reverse_lo,
|
||||
instance->common.cnt, //need manufacture code
|
||||
code_found_reverse_hi >> 28
|
||||
);
|
||||
}
|
17
lib/fl_subghz/protocols/subghz_protocol_keeloq.h
Normal file
17
lib/fl_subghz/protocols/subghz_protocol_keeloq.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolKeeloq SubGhzProtocolKeeloq;
|
||||
|
||||
SubGhzProtocolKeeloq* subghz_protocol_keeloq_alloc();
|
||||
|
||||
void subghz_protocol_keeloq_free(SubGhzProtocolKeeloq* instance);
|
||||
|
||||
void subghz_protocol_keeloq_add_manafacture_key(SubGhzProtocolKeeloq* instance, const char* name, uint64_t key, uint16_t type);
|
||||
|
||||
void subghz_protocol_keeloq_send_key(SubGhzProtocolKeeloq* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
void subghz_protocol_keeloq_parse(SubGhzProtocolKeeloq* instance, LevelPair data);
|
||||
|
||||
void subghz_protocol_keeloq_to_str(SubGhzProtocolKeeloq* instance, string_t output);
|
117
lib/fl_subghz/protocols/subghz_protocol_nice_flo.c
Normal file
117
lib/fl_subghz/protocols/subghz_protocol_nice_flo.c
Normal file
@@ -0,0 +1,117 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
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_parse(SubGhzProtocolNiceFlo* instance, LevelPair data) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((data.level == ApiHalSubGhzCaptureLevelLow)
|
||||
&& (DURATION_DIFF(data.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 (data.level == ApiHalSubGhzCaptureLevelLow) {
|
||||
break;
|
||||
} else if (DURATION_DIFF(data.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 (data.level == ApiHalSubGhzCaptureLevelLow) { //save interval
|
||||
if (data.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) {
|
||||
|
||||
//ToDo out data display
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
}
|
||||
break;
|
||||
}
|
||||
instance->common.te_last = data.duration;
|
||||
instance->common.parser_step = 3;
|
||||
} else {
|
||||
instance->common.parser_step = 0;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (data.level == ApiHalSubGhzCaptureLevelHigh) {
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot) < instance->common.te_delta)
|
||||
&& (DURATION_DIFF(data.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(data.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;
|
||||
}
|
||||
}
|
15
lib/fl_subghz/protocols/subghz_protocol_nice_flo.h
Normal file
15
lib/fl_subghz/protocols/subghz_protocol_nice_flo.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolNiceFlo SubGhzProtocolNiceFlo;
|
||||
|
||||
SubGhzProtocolNiceFlo* subghz_protocol_nice_flo_alloc();
|
||||
|
||||
void subghz_protocol_nice_flo_free(SubGhzProtocolNiceFlo* instance);
|
||||
|
||||
void subghz_protocol_nice_flo_set_callback(SubGhzProtocolNiceFlo* instance, SubGhzProtocolCommonCallback callback, void* context);
|
||||
|
||||
void subghz_protocol_nice_flo_send_key(SubGhzProtocolNiceFlo* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
void subghz_protocol_nice_flo_parse(SubGhzProtocolNiceFlo* instance, LevelPair data);
|
133
lib/fl_subghz/protocols/subghz_protocol_nice_flor_s.c
Normal file
133
lib/fl_subghz/protocols/subghz_protocol_nice_flor_s.c
Normal file
@@ -0,0 +1,133 @@
|
||||
#include "subghz_protocol_nice_flor_s.h"
|
||||
/*
|
||||
* https://phreakerclub.com/1615
|
||||
* https://phreakerclub.com/forum/showthread.php?t=2360
|
||||
* https://vrtp.ru/index.php?showtopic=27867
|
||||
*/
|
||||
|
||||
struct SubGhzProtocolNiceFlorS {
|
||||
SubGhzProtocolCommon common;
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flor_s_free(SubGhzProtocolNiceFlorS* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_protocol_nice_flor_s_parse(SubGhzProtocolNiceFlorS* instance, LevelPair data) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((data.level == ApiHalSubGhzCaptureLevelLow)
|
||||
&& (DURATION_DIFF(data.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 ((data.level == ApiHalSubGhzCaptureLevelHigh)
|
||||
&& (DURATION_DIFF(data.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 ((data.level == ApiHalSubGhzCaptureLevelLow)
|
||||
&& (DURATION_DIFF(data.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 (data.level == ApiHalSubGhzCaptureLevelHigh) {
|
||||
if(DURATION_DIFF(data.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) {
|
||||
|
||||
//ToDo out data display
|
||||
if (instance->common.callback) instance->common.callback((SubGhzProtocolCommon*)instance, instance->common.context);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
//save interval
|
||||
instance->common.te_last = data.duration;
|
||||
instance->common.parser_step = 4;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (data.level == ApiHalSubGhzCaptureLevelLow) {
|
||||
if ((DURATION_DIFF(instance->common.te_last,instance->common.te_shot) < instance->common.te_delta)
|
||||
&& (DURATION_DIFF(data.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(data.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;
|
||||
}
|
||||
}
|
15
lib/fl_subghz/protocols/subghz_protocol_nice_flor_s.h
Normal file
15
lib/fl_subghz/protocols/subghz_protocol_nice_flor_s.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolNiceFlorS SubGhzProtocolNiceFlorS;
|
||||
|
||||
SubGhzProtocolNiceFlorS* subghz_protocol_nice_flor_s_alloc();
|
||||
|
||||
void subghz_protocol_nice_flor_s_free(SubGhzProtocolNiceFlorS* instance);
|
||||
|
||||
void subghz_protocol_nice_flor_s_set_callback(SubGhzProtocolNiceFlorS* instance, SubGhzProtocolCommonCallback callback, void* context);
|
||||
|
||||
void subghz_protocol_nice_flor_s_send_key(SubGhzProtocolNiceFlorS* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
void subghz_protocol_nice_flor_s_parse(SubGhzProtocolNiceFlorS* instance, LevelPair data);
|
109
lib/fl_subghz/protocols/subghz_protocol_princeton.c
Normal file
109
lib/fl_subghz/protocols/subghz_protocol_princeton.c
Normal file
@@ -0,0 +1,109 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
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_parse(SubGhzProtocolPrinceton* instance, LevelPair data) {
|
||||
switch (instance->common.parser_step) {
|
||||
case 0:
|
||||
if ((data.level == ApiHalSubGhzCaptureLevelLow)
|
||||
&& (DURATION_DIFF(data.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 (data.level == ApiHalSubGhzCaptureLevelHigh) {
|
||||
instance->common.te_last = data.duration;
|
||||
instance->common.parser_step = 2;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (data.level == ApiHalSubGhzCaptureLevelLow) {
|
||||
if (data.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) {
|
||||
//ToDo out data display
|
||||
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(data.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(data.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;
|
||||
}
|
||||
}
|
15
lib/fl_subghz/protocols/subghz_protocol_princeton.h
Normal file
15
lib/fl_subghz/protocols/subghz_protocol_princeton.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "subghz_protocol_common.h"
|
||||
|
||||
typedef struct SubGhzProtocolPrinceton SubGhzProtocolPrinceton;
|
||||
|
||||
SubGhzProtocolPrinceton* subghz_protocol_princeton_alloc();
|
||||
|
||||
void subghz_protocol_princeton_free(SubGhzProtocolPrinceton* instance);
|
||||
|
||||
void subghz_protocol_princeton_send_key(SubGhzProtocolPrinceton* instance, uint64_t key, uint8_t bit, uint8_t repeat);
|
||||
|
||||
void subghz_protocol_princeton_parse(SubGhzProtocolPrinceton* instance, LevelPair data);
|
||||
|
||||
void subghz_protocol_princeton_to_str(SubGhzProtocolPrinceton* instance, string_t output);
|
Reference in New Issue
Block a user