Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into 420
  • Loading branch information
RogueMaster committed Jul 6, 2023
2 parents ee30d43 + 7e14f99 commit 1164e4d
Show file tree
Hide file tree
Showing 114 changed files with 3,681 additions and 258 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Infrared: Updated universal remote assets (by @amec0e | PR #529)
* Plugins: Use correct categories for all plugins (extra pack too)
* Plugins: Various fixes for uFBT (by @hedger)
* Plugins: Added **NFC Maker** plugin (make tags with URLs, Wifi and other things) [(by Willy-JL)](https://github.com/ClaraCrazy/Flipper-Xtreme/tree/dev/applications/external/nfc_maker)
* Plugins: Added JetPack Joyride [(by timstrasser)](https://github.com/timstrasser)
* Plugins: Moved Barcode Generator [(by Kingal1337)](https://github.com/Kingal1337/flipper-barcode-generator) from extra pack into base fw, old barcode generator was removed
* Plugins: Updated ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-wifi-marauder)
* Plugins: Updated i2c Tools [(by NaejEL)](https://github.com/NaejEL/flipperzero-i2ctools)
Expand All @@ -15,6 +17,8 @@
* WIP OFW PR 2825: NFC: Improved MFC emulation on some readers (by AloneLiberty)
* OFW PR 2829: Decode only supported Oregon 3 sensor (by @wosk)
* OFW PR: Update OFW PR 2782
* OFW: SubGhz: add "SubGhz test" external application and the ability to work "SubGhz" as an external application
* OFW: API: explicitly add math.h
* OFW: NFC: Mf Ultralight emulation optimization
* OFW: Furi_Power: fix furi_hal_power_enable_otg
* OFW: FuriHal: allow nulling null isr
Expand Down
14 changes: 14 additions & 0 deletions applications/debug/subghz_test/application.fam
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
App(
appid="subghz_test",
name="Sub-Ghz test",
apptype=FlipperAppType.DEBUG,
targets=["f7"],
entry_point="subghz_test_app",
requires=["gui"],
stack_size=4 * 1024,
order=50,
fap_icon="subghz_test_10px.png",
fap_category="Debug",
fap_icon_assets="images",
fap_version="0.1",
)
7 changes: 7 additions & 0 deletions applications/debug/subghz_test/helpers/subghz_test_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

typedef enum {
//SubGhzTestCustomEvent
SubGhzTestCustomEventStartId = 100,
SubGhzTestCustomEventSceneShowOnlyRX,
} SubGhzTestCustomEvent;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "subghz_testing.h"
#include "subghz_test_frequency.h"

const uint32_t subghz_frequencies_testing[] = {
/* 300 - 348 */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "../subghz_i.h"
#include "../subghz_test_app_i.h"

extern const uint32_t subghz_frequencies_testing[];
extern const uint32_t subghz_frequencies_count_testing;
Expand Down
18 changes: 18 additions & 0 deletions applications/debug/subghz_test/helpers/subghz_test_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <furi.h>
#include <furi_hal.h>

#define SUBGHZ_TEST_VERSION_APP "0.1"
#define SUBGHZ_TEST_DEVELOPED "SkorP"
#define SUBGHZ_TEST_GITHUB "https://github.com/flipperdevices/flipperzero-firmware"

typedef enum {
SubGhzTestViewVariableItemList,
SubGhzTestViewSubmenu,
SubGhzTestViewStatic,
SubGhzTestViewCarrier,
SubGhzTestViewPacket,
SubGhzTestViewWidget,
SubGhzTestViewPopup,
} SubGhzTestView;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
244 changes: 244 additions & 0 deletions applications/debug/subghz_test/protocol/math.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
#include "math.h"

uint64_t subghz_protocol_blocks_reverse_key(uint64_t key, uint8_t bit_count) {
uint64_t reverse_key = 0;
for(uint8_t i = 0; i < bit_count; i++) {
reverse_key = reverse_key << 1 | bit_read(key, i);
}
return reverse_key;
}

uint8_t subghz_protocol_blocks_get_parity(uint64_t key, uint8_t bit_count) {
uint8_t parity = 0;
for(uint8_t i = 0; i < bit_count; i++) {
parity += bit_read(key, i);
}
return parity & 0x01;
}

uint8_t subghz_protocol_blocks_crc4(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init) {
uint8_t remainder = init << 4; // LSBs are unused
uint8_t poly = polynomial << 4;
uint8_t bit;

while(size--) {
remainder ^= *message++;
for(bit = 0; bit < 8; bit++) {
if(remainder & 0x80) {
remainder = (remainder << 1) ^ poly;
} else {
remainder = (remainder << 1);
}
}
}
return remainder >> 4 & 0x0f; // discard the LSBs
}

uint8_t subghz_protocol_blocks_crc7(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init) {
uint8_t remainder = init << 1; // LSB is unused
uint8_t poly = polynomial << 1;

for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte];
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 0x80) {
remainder = (remainder << 1) ^ poly;
} else {
remainder = (remainder << 1);
}
}
}
return remainder >> 1 & 0x7f; // discard the LSB
}

uint8_t subghz_protocol_blocks_crc8(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init) {
uint8_t remainder = init;

for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte];
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 0x80) {
remainder = (remainder << 1) ^ polynomial;
} else {
remainder = (remainder << 1);
}
}
}
return remainder;
}

uint8_t subghz_protocol_blocks_crc8le(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init) {
uint8_t remainder = subghz_protocol_blocks_reverse_key(init, 8);
polynomial = subghz_protocol_blocks_reverse_key(polynomial, 8);

for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte];
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 1) {
remainder = (remainder >> 1) ^ polynomial;
} else {
remainder = (remainder >> 1);
}
}
}
return remainder;
}

uint16_t subghz_protocol_blocks_crc16lsb(
uint8_t const message[],
size_t size,
uint16_t polynomial,
uint16_t init) {
uint16_t remainder = init;

for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte];
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 1) {
remainder = (remainder >> 1) ^ polynomial;
} else {
remainder = (remainder >> 1);
}
}
}
return remainder;
}

uint16_t subghz_protocol_blocks_crc16(
uint8_t const message[],
size_t size,
uint16_t polynomial,
uint16_t init) {
uint16_t remainder = init;

for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte] << 8;
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 0x8000) {
remainder = (remainder << 1) ^ polynomial;
} else {
remainder = (remainder << 1);
}
}
}
return remainder;
}

uint8_t subghz_protocol_blocks_lfsr_digest8(
uint8_t const message[],
size_t size,
uint8_t gen,
uint8_t key) {
uint8_t sum = 0;
for(size_t byte = 0; byte < size; ++byte) {
uint8_t data = message[byte];
for(int i = 7; i >= 0; --i) {
// XOR key into sum if data bit is set
if((data >> i) & 1) sum ^= key;

// roll the key right (actually the LSB is dropped here)
// and apply the gen (needs to include the dropped LSB as MSB)
if(key & 1)
key = (key >> 1) ^ gen;
else
key = (key >> 1);
}
}
return sum;
}

uint8_t subghz_protocol_blocks_lfsr_digest8_reflect(
uint8_t const message[],
size_t size,
uint8_t gen,
uint8_t key) {
uint8_t sum = 0;
// Process message from last byte to first byte (reflected)
for(int byte = size - 1; byte >= 0; --byte) {
uint8_t data = message[byte];
// Process individual bits of each byte (reflected)
for(uint8_t i = 0; i < 8; ++i) {
// XOR key into sum if data bit is set
if((data >> i) & 1) {
sum ^= key;
}

// roll the key left (actually the LSB is dropped here)
// and apply the gen (needs to include the dropped lsb as MSB)
if(key & 0x80)
key = (key << 1) ^ gen;
else
key = (key << 1);
}
}
return sum;
}

uint16_t subghz_protocol_blocks_lfsr_digest16(
uint8_t const message[],
size_t size,
uint16_t gen,
uint16_t key) {
uint16_t sum = 0;
for(size_t byte = 0; byte < size; ++byte) {
uint8_t data = message[byte];
for(int8_t i = 7; i >= 0; --i) {
// if data bit is set then xor with key
if((data >> i) & 1) sum ^= key;

// roll the key right (actually the LSB is dropped here)
// and apply the gen (needs to include the dropped LSB as MSB)
if(key & 1)
key = (key >> 1) ^ gen;
else
key = (key >> 1);
}
}
return sum;
}

uint8_t subghz_protocol_blocks_add_bytes(uint8_t const message[], size_t size) {
uint32_t result = 0;
for(size_t i = 0; i < size; ++i) {
result += message[i];
}
return (uint8_t)result;
}

uint8_t subghz_protocol_blocks_parity8(uint8_t byte) {
byte ^= byte >> 4;
byte &= 0xf;
return (0x6996 >> byte) & 1;
}

uint8_t subghz_protocol_blocks_parity_bytes(uint8_t const message[], size_t size) {
uint8_t result = 0;
for(size_t i = 0; i < size; ++i) {
result ^= subghz_protocol_blocks_parity8(message[i]);
}
return result;
}

uint8_t subghz_protocol_blocks_xor_bytes(uint8_t const message[], size_t size) {
uint8_t result = 0;
for(size_t i = 0; i < size; ++i) {
result ^= message[i];
}
return result;
}
Loading

0 comments on commit 1164e4d

Please sign in to comment.