Compare commits

...

4 Commits

Author SHA1 Message Date
d4rks1d33 5825020a20 more fixes
Build Dev Firmware / build (push) Failing after 13s
2026-05-08 14:52:08 +00:00
d4rks1d33 91e9a4cbac fix workflow 2026-05-08 14:49:18 +00:00
d4rks1d33 c92b1db8b7 some updates
Build Dev Firmware / build (push) Failing after 20s
2026-05-08 14:43:24 +00:00
D4rk$1d3 a89cb55529 Update README.md
Build Dev Firmware / build (push) Successful in 7m23s
Updated the Special Thanks section to include a table format with contributor images and a message of appreciation.
2026-05-06 21:46:57 -03:00
11 changed files with 2204 additions and 19 deletions
+51 -9
View File
@@ -8,25 +8,62 @@ on:
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get latest semantic version tag
id: version
shell: bash
run: |
git fetch --tags
LAST_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)
if [ -z "$LAST_TAG" ]; then
NEW_TAG="1.0.0"
else
IFS='.' read -r MAJOR MINOR PATCH <<< "$LAST_TAG"
PATCH=$((PATCH + 1))
NEW_TAG="$MAJOR.$MINOR.$PATCH"
fi
echo "Latest tag: $LAST_TAG"
echo "New tag: $NEW_TAG"
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_OUTPUT
- name: Create Git tag
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag ${{ steps.version.outputs.NEW_TAG }}
git push origin ${{ steps.version.outputs.NEW_TAG }}
- name: Build firmware
shell: bash
run: |
export DIST_SUFFIX=Flipper-ARF
chmod +x fbt
./fbt COMPACT=1 DEBUG=0 updater_package
- name: Generate tag name
id: tag
run: echo "TAG=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Detect firmware updater
id: firmware
shell: bash
run: |
DIR=$(ls -d dist/f7-* | head -n 1)
FILE="$DIR/flipper-z-f7-update-Flipper-ARF.tgz"
@@ -36,13 +73,18 @@ jobs:
exit 1
fi
echo "Found firmware: $FILE"
echo "FILE=$FILE" >> $GITHUB_OUTPUT
- name: Create Release
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag.outputs.TAG }}
name: Dev Build ${{ steps.tag.outputs.TAG }}
files: ${{ steps.firmware.outputs.FILE }}
tag_name: ${{ steps.version.outputs.NEW_TAG }}
name: Release ${{ steps.version.outputs.NEW_TAG }}
generate_release_notes: true
make_latest: true
files: |
${{ steps.firmware.outputs.FILE }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+20 -10
View File
@@ -22,6 +22,7 @@ This project may incorporate, adapt, or build upon **other open-source projects*
- [Contribution Policy](#contribution-policy)
- [Citations & References](#citations--references)
- [Disclaimer](#disclaimer)
- [Special Thanks](#special-thanks-to-everyone-who-contributes-to-this-project)
---
@@ -362,13 +363,22 @@ IN NO EVENT SHALL THE AUTHORS, COPYRIGHT HOLDERS, OR CONTRIBUTORS BE LIABLE FOR
## Special Thanks
- 47LeCoste
- Ash
- D4c1
- D4rks1d3
- LTX74
- Leeroy
- lupettohf
- MMX
- RalphWiggum
- zero-mega
<table align="center">
<tr>
<td align="center">
<a href="https://github.com/whatthefxck">
<img src="https://avatars.githubusercontent.com/whatthefxck?s=80" width="80" height="80" alt="whatthefxck"/>
</a>
</td>
<td align="center">
<a href="https://github.com/zero-mega">
<img src="https://avatars.githubusercontent.com/zero-mega?s=80" width="80" height="80" alt="zero-mega"/>
</a>
</td>
</tr>
</table>
<p align="center">
Special thanks to everyone who contributed code, testing, reversing,
research, ideas, captures and documentation.
</p>
@@ -0,0 +1,42 @@
# to use manual settings and prevent them from being deleted on upgrade, rename *_user.example files to *_user
Filetype: Flipper SubGhz Setting File
Version: 1
# Add Standard frequencies included with firmware and place user frequencies after them
#Add_standard_frequencies: true
# Default Frequency: used as default for "Read" and "Read Raw"
#Default_frequency: 433920000
# Frequencies used for "Read", "Read Raw" and "Frequency Analyzer"
#Frequency: 300000000
#Frequency: 310000000
#Frequency: 320000000
# Frequencies used for hopping mode (keep this list small or flipper will miss signal)
#Hopper_frequency: 300000000
#Hopper_frequency: 310000000
#Hopper_frequency: 310000000
# Custom preset
# format for CC1101 "Custom_preset_data:" XX YY XX YY .. 00 00 ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ, where: XX-register, YY - register data, 00 00 - end load register, ZZ - 8 byte Pa table register
#Custom_preset_name: FM95
#Custom_preset_module: CC1101
#Custom_preset_data: 02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 83 10 67 15 24 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00
#2-FSK 200khz BW / 135kHz Filter/ 15.86Khz Deviation + Ramping
#Custom_preset_name: FM15k
#Custom_preset_module: CC1101
#Custom_preset_data: 02 0D 03 47 08 32 0B 06 15 32 14 00 13 00 12 00 11 32 10 A7 18 18 19 1D 1D 92 1C 00 1B 04 20 FB 22 17 21 B6 00 00 00 12 0E 34 60 C5 C1 C0
#Custom_preset_name: Pagers
#Custom_preset_module: CC1101
#Custom_preset_data: 02 0D 07 04 08 32 0B 06 10 64 11 93 12 0C 13 02 14 00 15 15 18 18 19 16 1B 07 1C 00 1D 91 20 FB 21 56 22 10 00 00 C0 00 00 00 00 00 00 00
#Custom_preset_name: AM_1
#Custom_preset_module: CC1101
#Custom_preset_data: 02 0D 03 07 08 32 0B 06 14 00 13 00 12 30 11 32 10 17 18 18 19 18 1D 91 1C 00 1B 07 20 FB 22 11 21 B6 00 00 00 C0 00 00 00 00 00 00
#Custom_preset_name: AM_2
#Custom_preset_module: CC1101
#Custom_preset_data: 02 0D 03 07 08 32 0B 06 14 00 13 00 12 30 11 32 10 17 18 18 19 18 1D 91 1C 00 1B 07 20 FB 22 11 21 B6 00 00 00 C0 00 00 00 00 00 00
+252
View File
@@ -0,0 +1,252 @@
#include "aes_common.h"
static const uint8_t aes_sbox[256] = {
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab,
0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4,
0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71,
0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6,
0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb,
0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45,
0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44,
0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a,
0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49,
0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25,
0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e,
0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1,
0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb,
0x16};
static const uint8_t aes_sbox_inv[256] = {
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7,
0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde,
0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42,
0xfa, 0xc3, 0x4e, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c,
0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15,
0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7,
0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc,
0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad,
0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d,
0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, 0x1f, 0xdd, 0xa8,
0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51,
0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0,
0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c,
0x7d};
static const uint8_t aes_rcon[10] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
static uint8_t gf_mul2(uint8_t x) {
return ((x >> 7) * 0x1b) ^ (x << 1);
}
static void aes_subbytes(uint8_t* state) {
for(uint8_t row = 0; row < 4; row++) {
for(uint8_t col = 0; col < 4; col++) {
state[row + col * 4] = aes_sbox[state[row + col * 4]];
}
}
}
static void aes_subbytes_inv(uint8_t* state) {
for(uint8_t row = 0; row < 4; row++) {
for(uint8_t col = 0; col < 4; col++) {
state[row + col * 4] = aes_sbox_inv[state[row + col * 4]];
}
}
}
static void aes_shiftrows(uint8_t* state) {
uint8_t temp;
temp = state[1];
state[1] = state[5];
state[5] = state[9];
state[9] = state[13];
state[13] = temp;
temp = state[2];
state[2] = state[10];
state[10] = temp;
temp = state[6];
state[6] = state[14];
state[14] = temp;
temp = state[15];
state[15] = state[11];
state[11] = state[7];
state[7] = state[3];
state[3] = temp;
}
static void aes_shiftrows_inv(uint8_t* state) {
uint8_t temp;
temp = state[13];
state[13] = state[9];
state[9] = state[5];
state[5] = state[1];
state[1] = temp;
temp = state[2];
state[2] = state[10];
state[10] = temp;
temp = state[6];
state[6] = state[14];
state[14] = temp;
temp = state[3];
state[3] = state[7];
state[7] = state[11];
state[11] = state[15];
state[15] = temp;
}
static void aes_mixcolumns(uint8_t* state) {
uint8_t a, b, c, d;
for(uint8_t i = 0; i < 4; i++) {
a = state[i * 4];
b = state[i * 4 + 1];
c = state[i * 4 + 2];
d = state[i * 4 + 3];
uint8_t a2 = gf_mul2(a);
uint8_t b2 = gf_mul2(b);
uint8_t c2 = gf_mul2(c);
uint8_t d2 = gf_mul2(d);
state[i * 4] = a2 ^ b2 ^ b ^ c ^ d;
state[i * 4 + 1] = a ^ b2 ^ c2 ^ c ^ d;
state[i * 4 + 2] = a ^ b ^ c2 ^ d2 ^ d;
state[i * 4 + 3] = a2 ^ a ^ b ^ c ^ d2;
}
}
static void aes_mixcolumns_inv(uint8_t* state) {
uint8_t a, b, c, d;
for(uint8_t i = 0; i < 4; i++) {
a = state[i * 4];
b = state[i * 4 + 1];
c = state[i * 4 + 2];
d = state[i * 4 + 3];
uint8_t a2 = gf_mul2(a);
uint8_t a4 = gf_mul2(a2);
uint8_t a8 = gf_mul2(a4);
uint8_t b2 = gf_mul2(b);
uint8_t b4 = gf_mul2(b2);
uint8_t b8 = gf_mul2(b4);
uint8_t c2 = gf_mul2(c);
uint8_t c4 = gf_mul2(c2);
uint8_t c8 = gf_mul2(c4);
uint8_t d2 = gf_mul2(d);
uint8_t d4 = gf_mul2(d2);
uint8_t d8 = gf_mul2(d4);
state[i * 4] = (a8 ^ a4 ^ a2) ^ (b8 ^ b2 ^ b) ^ (c8 ^ c4 ^ c) ^ (d8 ^ d);
state[i * 4 + 1] = (a8 ^ a) ^ (b8 ^ b4 ^ b2) ^ (c8 ^ c2 ^ c) ^ (d8 ^ d4 ^ d);
state[i * 4 + 2] = (a8 ^ a4 ^ a) ^ (b8 ^ b) ^ (c8 ^ c4 ^ c2) ^ (d8 ^ d2 ^ d);
state[i * 4 + 3] = (a8 ^ a2 ^ a) ^ (b8 ^ b4 ^ b) ^ (c8 ^ c) ^ (d8 ^ d4 ^ d2);
}
}
static void aes_addroundkey(uint8_t* state, const uint8_t* round_key) {
for(uint8_t col = 0; col < 4; col++) {
state[col * 4] ^= round_key[col * 4];
state[col * 4 + 1] ^= round_key[col * 4 + 1];
state[col * 4 + 2] ^= round_key[col * 4 + 2];
state[col * 4 + 3] ^= round_key[col * 4 + 3];
}
}
void aes_key_expansion(const uint8_t* key, uint8_t* round_keys) {
for(uint8_t i = 0; i < 16; i++) {
round_keys[i] = key[i];
}
for(uint8_t i = 4; i < 44; i++) {
uint8_t prev_word_idx = (i - 1) * 4;
uint8_t b0 = round_keys[prev_word_idx];
uint8_t b1 = round_keys[prev_word_idx + 1];
uint8_t b2 = round_keys[prev_word_idx + 2];
uint8_t b3 = round_keys[prev_word_idx + 3];
if((i % 4) == 0) {
uint8_t new_b0 = aes_sbox[b1] ^ aes_rcon[(i / 4) - 1];
uint8_t new_b1 = aes_sbox[b2];
uint8_t new_b2 = aes_sbox[b3];
uint8_t new_b3 = aes_sbox[b0];
b0 = new_b0;
b1 = new_b1;
b2 = new_b2;
b3 = new_b3;
}
uint8_t back_word_idx = (i - 4) * 4;
b0 ^= round_keys[back_word_idx];
b1 ^= round_keys[back_word_idx + 1];
b2 ^= round_keys[back_word_idx + 2];
b3 ^= round_keys[back_word_idx + 3];
uint8_t curr_word_idx = i * 4;
round_keys[curr_word_idx] = b0;
round_keys[curr_word_idx + 1] = b1;
round_keys[curr_word_idx + 2] = b2;
round_keys[curr_word_idx + 3] = b3;
}
}
void aes128_encrypt(const uint8_t* expanded_key, uint8_t* data) {
uint8_t state[16];
memcpy(state, data, 16);
aes_addroundkey(state, &expanded_key[0]);
for(uint8_t round = 1; round < 10; round++) {
aes_subbytes(state);
aes_shiftrows(state);
aes_mixcolumns(state);
aes_addroundkey(state, &expanded_key[round * 16]);
}
aes_subbytes(state);
aes_shiftrows(state);
aes_addroundkey(state, &expanded_key[160]);
memcpy(data, state, 16);
}
void aes128_decrypt(const uint8_t* expanded_key, uint8_t* data) {
uint8_t state[16];
memcpy(state, data, 16);
aes_addroundkey(state, &expanded_key[160]);
for(uint8_t round = 9; round > 0; round--) {
aes_shiftrows_inv(state);
aes_subbytes_inv(state);
aes_addroundkey(state, &expanded_key[round * 16]);
aes_mixcolumns_inv(state);
}
aes_shiftrows_inv(state);
aes_subbytes_inv(state);
aes_addroundkey(state, &expanded_key[0]);
memcpy(data, state, 16);
}
void reverse_bits_in_bytes(uint8_t* data, uint8_t len) {
for(uint8_t i = 0; i < len; i++) {
uint8_t byte = data[i];
uint8_t step1 = ((byte & 0x55) << 1) | ((byte >> 1) & 0x55);
uint8_t step2 = ((step1 & 0x33) << 2) | ((step1 >> 2) & 0x33);
data[i] = ((step2 & 0x0F) << 4) | (step2 >> 4);
}
}
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#include "base.h"
#include <furi.h>
void reverse_bits_in_bytes(uint8_t* data, uint8_t len);
void aes128_decrypt(const uint8_t* expanded_key, uint8_t* data);
void aes128_encrypt(const uint8_t* expanded_key, uint8_t* data);
void aes_key_expansion(const uint8_t* key, uint8_t* round_keys);
+376
View File
@@ -0,0 +1,376 @@
/**
* allstar_firefly.c -- Allstar Firefly 318ALD31K native SubGHz protocol
*
* Implements the SubGhzProtocol vtable for the Supertex ED-9 based gate remote.
* Uses subghz_block_generic_serialize / deserialize for standard-format .sub
* files, encoding the 9-position trinary DIP code as a uint64 (base-3, MSB
* first: '+' = 2, '0' = 3, '-' = 0).
*
* Saved file format:
* Filetype: Flipper SubGhz Key File
* Version: 1
* Frequency: 318000000
* Preset: FuriHalSubGhzPresetOok650Async
* Protocol: Allstar Firefly
* Key: 00 00 00 00 00 00 34 B9
* Bit: 18
*
* See allstar_firefly.h for full protocol documentation.
*/
#include "allstar_firefly.h"
#include "../blocks/const.h"
#include "../blocks/decoder.h"
#include "../blocks/encoder.h"
#include "../blocks/generic.h"
#include "../blocks/math.h"
#define TAG "AllstarFirefly"
#define DIP_P 0b11 //(+)
#define DIP_O 0b10 //(0)
#define DIP_N 0b00 //(-)
#define DIP_PATTERN "%c%c%c%c%c%c%c%c%c"
#define SHOW_DIP_P(dip, check_dip) \
((((dip >> 0x10) & 0x3) == check_dip) ? '*' : '_'), \
((((dip >> 0xE) & 0x3) == check_dip) ? '*' : '_'), \
((((dip >> 0xC) & 0x3) == check_dip) ? '*' : '_'), \
((((dip >> 0xA) & 0x3) == check_dip) ? '*' : '_'), \
((((dip >> 0x8) & 0x3) == check_dip) ? '*' : '_'), \
((((dip >> 0x6) & 0x3) == check_dip) ? '*' : '_'), \
((((dip >> 0x4) & 0x3) == check_dip) ? '*' : '_'), \
((((dip >> 0x2) & 0x3) == check_dip) ? '*' : '_'), \
((((dip >> 0x0) & 0x3) == check_dip) ? '*' : '_')
static const SubGhzBlockConst subghz_protocol_allstar_firefly_const = {
.te_short = 600,
.te_long = 4000,
.te_delta = 300,
.min_count_bit_for_found = 18,
};
struct SubGhzProtocolDecoderAllstarFirefly {
SubGhzProtocolDecoderBase base;
SubGhzBlockDecoder decoder;
SubGhzBlockGeneric generic;
};
struct SubGhzProtocolEncoderAllstarFirefly {
SubGhzProtocolEncoderBase base;
SubGhzProtocolBlockEncoder encoder;
SubGhzBlockGeneric generic;
};
typedef enum {
AllstarFireflyDecoderStepReset = 0,
AllstarFireflyDecoderStepSaveDuration,
AllstarFireflyDecoderStepCheckDuration,
} AllstarFireflyDecoderStep;
const SubGhzProtocolDecoder subghz_protocol_allstar_firefly_decoder = {
.alloc = subghz_protocol_decoder_allstar_firefly_alloc,
.free = subghz_protocol_decoder_allstar_firefly_free,
.feed = subghz_protocol_decoder_allstar_firefly_feed,
.reset = subghz_protocol_decoder_allstar_firefly_reset,
.get_hash_data = subghz_protocol_decoder_allstar_firefly_get_hash_data,
.serialize = subghz_protocol_decoder_allstar_firefly_serialize,
.deserialize = subghz_protocol_decoder_allstar_firefly_deserialize,
.get_string = subghz_protocol_decoder_allstar_firefly_get_string,
};
const SubGhzProtocolEncoder subghz_protocol_allstar_firefly_encoder = {
.alloc = subghz_protocol_encoder_allstar_firefly_alloc,
.free = subghz_protocol_encoder_allstar_firefly_free,
.deserialize = subghz_protocol_encoder_allstar_firefly_deserialize,
.stop = subghz_protocol_encoder_allstar_firefly_stop,
.yield = subghz_protocol_encoder_allstar_firefly_yield,
};
const SubGhzProtocol subghz_protocol_allstar_firefly = {
.name = SUBGHZ_PROTOCOL_ALLSTAR_FIREFLY_NAME,
.type = SubGhzProtocolTypeStatic,
.flag = SubGhzProtocolFlag_315 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable |
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
.decoder = &subghz_protocol_allstar_firefly_decoder,
.encoder = &subghz_protocol_allstar_firefly_encoder,
};
void* subghz_protocol_encoder_allstar_firefly_alloc(SubGhzEnvironment* environment) {
UNUSED(environment);
SubGhzProtocolEncoderAllstarFirefly* instance =
malloc(sizeof(SubGhzProtocolEncoderAllstarFirefly));
instance->base.protocol = &subghz_protocol_allstar_firefly;
instance->generic.protocol_name = instance->base.protocol->name;
instance->encoder.repeat = 5;
instance->encoder.size_upload = 256;
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
instance->encoder.is_running = false;
return instance;
}
void subghz_protocol_encoder_allstar_firefly_free(void* context) {
furi_assert(context);
SubGhzProtocolEncoderAllstarFirefly* instance = context;
free(instance->encoder.upload);
free(instance);
}
/**
* Generating an upload from data.
* @param instance Pointer to a SubGhzProtocolEncoderAllstarFirefly instance
*/
static void subghz_protocol_encoder_allstar_firefly_get_upload(
SubGhzProtocolEncoderAllstarFirefly* instance) {
furi_assert(instance);
size_t index = 0;
// Send key and GAP
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
if(bit_read(instance->generic.data, i - 1)) {
// Send bit 1
instance->encoder.upload[index++] =
level_duration_make(true, (uint32_t)subghz_protocol_allstar_firefly_const.te_long);
if(i == 1) {
//Send gap if bit was last
instance->encoder.upload[index++] = level_duration_make(
false, (uint32_t)(subghz_protocol_allstar_firefly_const.te_short * 50) + 400);
} else {
instance->encoder.upload[index++] = level_duration_make(
false, (uint32_t)subghz_protocol_allstar_firefly_const.te_short);
}
} else {
// Send bit 0
instance->encoder.upload[index++] = level_duration_make(
true, (uint32_t)subghz_protocol_allstar_firefly_const.te_short);
if(i == 1) {
//Send gap if bit was last
instance->encoder.upload[index++] = level_duration_make(
false, (uint32_t)(subghz_protocol_allstar_firefly_const.te_short * 50) + 400);
} else {
instance->encoder.upload[index++] = level_duration_make(
false, (uint32_t)subghz_protocol_allstar_firefly_const.te_long);
}
}
}
instance->encoder.size_upload = index;
return;
}
SubGhzProtocolStatus subghz_protocol_encoder_allstar_firefly_deserialize(
void* context,
FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolEncoderAllstarFirefly* instance = context;
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
do {
ret = subghz_block_generic_deserialize_check_count_bit(
&instance->generic,
flipper_format,
subghz_protocol_allstar_firefly_const.min_count_bit_for_found);
if(ret != SubGhzProtocolStatusOk) {
break;
}
// Optional value
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
subghz_protocol_encoder_allstar_firefly_get_upload(instance);
instance->encoder.is_running = true;
} while(false);
return ret;
}
void subghz_protocol_encoder_allstar_firefly_stop(void* context) {
SubGhzProtocolEncoderAllstarFirefly* instance = context;
instance->encoder.is_running = false;
}
LevelDuration subghz_protocol_encoder_allstar_firefly_yield(void* context) {
SubGhzProtocolEncoderAllstarFirefly* instance = context;
if(instance->encoder.repeat == 0 || !instance->encoder.is_running) {
instance->encoder.is_running = false;
return level_duration_reset();
}
LevelDuration ret = instance->encoder.upload[instance->encoder.front];
if(++instance->encoder.front == instance->encoder.size_upload) {
if(!subghz_block_generic_global.endless_tx) instance->encoder.repeat--;
instance->encoder.front = 0;
}
return ret;
}
void* subghz_protocol_decoder_allstar_firefly_alloc(SubGhzEnvironment* environment) {
UNUSED(environment);
SubGhzProtocolDecoderAllstarFirefly* instance =
malloc(sizeof(SubGhzProtocolDecoderAllstarFirefly));
instance->base.protocol = &subghz_protocol_allstar_firefly;
instance->generic.protocol_name = instance->base.protocol->name;
return instance;
}
void subghz_protocol_decoder_allstar_firefly_free(void* context) {
furi_assert(context);
SubGhzProtocolDecoderAllstarFirefly* instance = context;
free(instance);
}
void subghz_protocol_decoder_allstar_firefly_reset(void* context) {
furi_assert(context);
SubGhzProtocolDecoderAllstarFirefly* instance = context;
instance->decoder.parser_step = AllstarFireflyDecoderStepReset;
}
void subghz_protocol_decoder_allstar_firefly_feed(
void* context,
bool level,
volatile uint32_t duration) {
furi_assert(context);
SubGhzProtocolDecoderAllstarFirefly* instance = context;
// Allstar Firefly Decoder
// 2026 - by @jlaughter
// Remake to match other protocols code base - @xMasterX (MMX)
switch(instance->decoder.parser_step) {
case AllstarFireflyDecoderStepReset:
if((!level) &&
(DURATION_DIFF(duration, subghz_protocol_allstar_firefly_const.te_short * 50) <
subghz_protocol_allstar_firefly_const.te_delta * 5)) {
// 30k us
// Found GAP
instance->decoder.decode_data = 0;
instance->decoder.decode_count_bit = 0;
instance->decoder.parser_step = AllstarFireflyDecoderStepSaveDuration;
}
break;
case AllstarFireflyDecoderStepSaveDuration:
if(level) {
instance->decoder.te_last = duration;
instance->decoder.parser_step = AllstarFireflyDecoderStepCheckDuration;
} else {
instance->decoder.parser_step = AllstarFireflyDecoderStepReset;
}
break;
case AllstarFireflyDecoderStepCheckDuration:
if(!level) {
// Bit 1 is long and short timing = 4000us HIGH (te_last) and 600us LOW
if((DURATION_DIFF(
instance->decoder.te_last, subghz_protocol_allstar_firefly_const.te_long) <
subghz_protocol_allstar_firefly_const.te_delta) &&
(DURATION_DIFF(duration, subghz_protocol_allstar_firefly_const.te_short) <
subghz_protocol_allstar_firefly_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
instance->decoder.parser_step = AllstarFireflyDecoderStepSaveDuration;
// Bit 0 is short and long timing = 600us HIGH (te_last) and 4000us LOW
} else if(
(DURATION_DIFF(
instance->decoder.te_last, subghz_protocol_allstar_firefly_const.te_short) <
subghz_protocol_allstar_firefly_const.te_delta) &&
(DURATION_DIFF(duration, subghz_protocol_allstar_firefly_const.te_long) <
subghz_protocol_allstar_firefly_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
instance->decoder.parser_step = AllstarFireflyDecoderStepSaveDuration;
} else if(
// End of the key
DURATION_DIFF(duration, subghz_protocol_allstar_firefly_const.te_short * 50) <
subghz_protocol_allstar_firefly_const.te_delta * 5) {
// Found next GAP and add bit 0 or 1
if((DURATION_DIFF(
instance->decoder.te_last, subghz_protocol_allstar_firefly_const.te_long) <
subghz_protocol_allstar_firefly_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
}
if((DURATION_DIFF(
instance->decoder.te_last,
subghz_protocol_allstar_firefly_const.te_short) <
subghz_protocol_allstar_firefly_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
}
// If got 18 bits key reading is finished
if(instance->decoder.decode_count_bit ==
subghz_protocol_allstar_firefly_const.min_count_bit_for_found) {
instance->generic.data = instance->decoder.decode_data;
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
if(instance->base.callback)
instance->base.callback(&instance->base, instance->base.context);
}
instance->decoder.decode_data = 0;
instance->decoder.decode_count_bit = 0;
instance->decoder.parser_step = AllstarFireflyDecoderStepReset;
} else {
instance->decoder.parser_step = AllstarFireflyDecoderStepReset;
}
} else {
instance->decoder.parser_step = AllstarFireflyDecoderStepReset;
}
break;
}
}
uint8_t subghz_protocol_decoder_allstar_firefly_get_hash_data(void* context) {
furi_assert(context);
SubGhzProtocolDecoderAllstarFirefly* instance = context;
return subghz_protocol_blocks_get_hash_data(
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
}
SubGhzProtocolStatus subghz_protocol_decoder_allstar_firefly_serialize(
void* context,
FlipperFormat* flipper_format,
SubGhzRadioPreset* preset) {
furi_assert(context);
SubGhzProtocolDecoderAllstarFirefly* instance = context;
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
}
SubGhzProtocolStatus subghz_protocol_decoder_allstar_firefly_deserialize(
void* context,
FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderAllstarFirefly* instance = context;
return subghz_block_generic_deserialize_check_count_bit(
&instance->generic,
flipper_format,
subghz_protocol_allstar_firefly_const.min_count_bit_for_found);
}
void subghz_protocol_decoder_allstar_firefly_get_string(void* context, FuriString* output) {
furi_assert(context);
SubGhzProtocolDecoderAllstarFirefly* instance = context;
uint64_t code_found_reverse = subghz_protocol_blocks_reverse_key(
instance->generic.data, instance->generic.data_count_bit);
furi_string_cat_printf(
output,
"%s %db\r\n"
"Key:0x%05lX Yek:0x%05lX\r\n"
" +: " DIP_PATTERN "\r\n"
" o: " DIP_PATTERN "\r\n"
" -: " DIP_PATTERN "\r\n",
instance->generic.protocol_name,
instance->generic.data_count_bit,
(uint32_t)(instance->generic.data & 0xFFFFF),
(uint32_t)(code_found_reverse & 0xFFFFF),
SHOW_DIP_P(instance->generic.data, DIP_P),
SHOW_DIP_P(instance->generic.data, DIP_O),
SHOW_DIP_P(instance->generic.data, DIP_N));
}
+143
View File
@@ -0,0 +1,143 @@
#pragma once
/**
* allstar_firefly.h - Allstar Firefly 318ALD31K native SubGHz protocol
*
* Registers the Allstar Firefly gate remote as a first-class SubGHz protocol,
* supporting decode from air, save/load of .sub files, and retransmit.
*
* Protocol summary (measured from captured remotes):
* Carrier : 318 MHz OOK (FuriHalSubGhzPresetOok650Async)
* Code type : Static 9-bit trinary (Supertex ED-9 encoder IC)
* Frame : 18 symbols (2 per bit), no separate sync pulse
* Repeats : 20 frames per keypress
* Inter-frame gap: ~30 440 us
*
* Symbol encoding - each bit = two (pulse, gap) pairs:
* '+' ON : H H = [4045us HIGH, 607us LOW] x2
* '-' OFF : L L = [530us HIGH, 4139us LOW] x2
* '0' FLOAT : H L = [4045us HIGH, 607us LOW, 530us HIGH, 4139us LOW]
*
* Save file format:
* Filetype: Flipper SubGhz Key File
* Version: 1
* Frequency: 318000000
* Preset: FuriHalSubGhzPresetOok650Async
* Protocol: Allstar Firefly
* Key: +--000++-
*
* To register with the SubGHz app, in protocol_list.c add:
* #include "allstar_firefly.h"
* &subghz_protocol_allstar_firefly, (in the protocol array)
*/
#include "base.h"
/* Protocol name (must match what is written to .sub files) */
#define SUBGHZ_PROTOCOL_ALLSTAR_FIREFLY_NAME "Allstar Firefly"
typedef struct SubGhzProtocolDecoderAllstarFirefly SubGhzProtocolDecoderAllstarFirefly;
typedef struct SubGhzProtocolEncoderAllstarFirefly SubGhzProtocolEncoderAllstarFirefly;
extern const SubGhzProtocolDecoder subghz_protocol_allstar_firefly_decoder;
extern const SubGhzProtocolEncoder subghz_protocol_allstar_firefly_encoder;
extern const SubGhzProtocol subghz_protocol_allstar_firefly;
/**
* Allocate SubGhzProtocolEncoderAllstarFirefly.
* @param environment Pointer to a SubGhzEnvironment instance
* @return SubGhzProtocolEncoderAllstarFirefly* pointer to a SubGhzProtocolEncoderAllstarFirefly instance
*/
void* subghz_protocol_encoder_allstar_firefly_alloc(SubGhzEnvironment* environment);
/**
* Free SubGhzProtocolEncoderAllstarFirefly.
* @param context Pointer to a SubGhzProtocolEncoderAllstarFirefly instance
*/
void subghz_protocol_encoder_allstar_firefly_free(void* context);
/**
* Deserialize and generating an upload to send.
* @param context Pointer to a SubGhzProtocolEncoderAllstarFirefly instance
* @param flipper_format Pointer to a FlipperFormat instance
* @return status
*/
SubGhzProtocolStatus subghz_protocol_encoder_allstar_firefly_deserialize(
void* context,
FlipperFormat* flipper_format);
/**
* Forced transmission stop.
* @param context Pointer to a SubGhzProtocolEncoderAllstarFirefly instance
*/
void subghz_protocol_encoder_allstar_firefly_stop(void* context);
/**
* Getting the level and duration of the upload to be loaded into DMA.
* @param context Pointer to a SubGhzProtocolEncoderAllstarFirefly instance
* @return LevelDuration
*/
LevelDuration subghz_protocol_encoder_allstar_firefly_yield(void* context);
/**
* Allocate SubGhzProtocolDecoderAllstarFirefly.
* @param environment Pointer to a SubGhzEnvironment instance
* @return SubGhzProtocolDecoderAllstarFirefly* pointer to a SubGhzProtocolDecoderAllstarFirefly instance
*/
void* subghz_protocol_decoder_allstar_firefly_alloc(SubGhzEnvironment* environment);
/**
* Free SubGhzProtocolDecoderAllstarFirefly.
* @param context Pointer to a SubGhzProtocolDecoderAllstarFirefly instance
*/
void subghz_protocol_decoder_allstar_firefly_free(void* context);
/**
* Reset decoder SubGhzProtocolDecoderAllstarFirefly.
* @param context Pointer to a SubGhzProtocolDecoderAllstarFirefly instance
*/
void subghz_protocol_decoder_allstar_firefly_reset(void* context);
/**
* Parse a raw sequence of levels and durations received from the air.
* @param context Pointer to a SubGhzProtocolDecoderAllstarFirefly instance
* @param level Signal level true-high false-low
* @param duration Duration of this level in, us
*/
void subghz_protocol_decoder_allstar_firefly_feed(void* context, bool level, uint32_t duration);
/**
* Getting the hash sum of the last randomly received parcel.
* @param context Pointer to a SubGhzProtocolDecoderAllstarFirefly instance
* @return hash Hash sum
*/
uint8_t subghz_protocol_decoder_allstar_firefly_get_hash_data(void* context);
/**
* Serialize data SubGhzProtocolDecoderAllstarFirefly.
* @param context Pointer to a SubGhzProtocolDecoderAllstarFirefly instance
* @param flipper_format Pointer to a FlipperFormat instance
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
* @return status
*/
SubGhzProtocolStatus subghz_protocol_decoder_allstar_firefly_serialize(
void* context,
FlipperFormat* flipper_format,
SubGhzRadioPreset* preset);
/**
* Deserialize data SubGhzProtocolDecoderAllstarFirefly.
* @param context Pointer to a SubGhzProtocolDecoderAllstarFirefly instance
* @param flipper_format Pointer to a FlipperFormat instance
* @return status
*/
SubGhzProtocolStatus subghz_protocol_decoder_allstar_firefly_deserialize(
void* context,
FlipperFormat* flipper_format);
/**
* Getting a textual representation of the received data.
* @param context Pointer to a SubGhzProtocolDecoderAllstarFirefly instance
* @param output Resulting text
*/
void subghz_protocol_decoder_allstar_firefly_get_string(void* context, FuriString* output);
+742
View File
@@ -0,0 +1,742 @@
#include "ditec_gol4.h"
#include "../blocks/const.h"
#include "../blocks/decoder.h"
#include "../blocks/encoder.h"
#include "../blocks/generic.h"
#include "../blocks/math.h"
#include "../blocks/custom_btn_i.h"
#define TAG "SubGhzProtocolDitecGOL4"
#define GOL4_RAW_BYTES 7
static const SubGhzBlockConst subghz_protocol_ditec_gol4_const = {
.te_short = 400,
.te_long = 1100,
.te_delta = 200,
.min_count_bit_for_found = 54,
};
struct SubGhzProtocolDecoderDitecGOL4 {
SubGhzProtocolDecoderBase base;
SubGhzBlockDecoder decoder;
SubGhzBlockGeneric generic;
};
struct SubGhzProtocolEncoderDitecGOL4 {
SubGhzProtocolEncoderBase base;
SubGhzProtocolBlockEncoder encoder;
SubGhzBlockGeneric generic;
};
typedef enum {
DitecGOL4DecoderStepReset = 0,
DitecGOL4DecoderStepStartBit,
DitecGOL4DecoderStepSaveDuration,
DitecGOL4DecoderStepCheckDuration,
} DitecGOL4DecoderStep;
const SubGhzProtocolDecoder subghz_protocol_ditec_gol4_decoder = {
.alloc = subghz_protocol_decoder_ditec_gol4_alloc,
.free = subghz_protocol_decoder_ditec_gol4_free,
.feed = subghz_protocol_decoder_ditec_gol4_feed,
.reset = subghz_protocol_decoder_ditec_gol4_reset,
.get_hash_data = subghz_protocol_decoder_ditec_gol4_get_hash_data,
.serialize = subghz_protocol_decoder_ditec_gol4_serialize,
.deserialize = subghz_protocol_decoder_ditec_gol4_deserialize,
.get_string = subghz_protocol_decoder_ditec_gol4_get_string,
};
const SubGhzProtocolEncoder subghz_protocol_ditec_gol4_encoder = {
.alloc = subghz_protocol_encoder_ditec_gol4_alloc,
.free = subghz_protocol_encoder_ditec_gol4_free,
.deserialize = subghz_protocol_encoder_ditec_gol4_deserialize,
.stop = subghz_protocol_encoder_ditec_gol4_stop,
.yield = subghz_protocol_encoder_ditec_gol4_yield,
};
const SubGhzProtocol subghz_protocol_ditec_gol4 = {
.name = SUBGHZ_PROTOCOL_DITEC_GOL4_NAME,
.type = SubGhzProtocolTypeDynamic,
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable |
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
.decoder = &subghz_protocol_ditec_gol4_decoder,
.encoder = &subghz_protocol_ditec_gol4_encoder,
};
/**
* Defines the button value for the current btn_id
* Basic set | 0x1 | 0x2 | 0x4 | 0x8 | 0x0 PROG
* @return Button code
*/
static uint8_t subghz_protocol_ditec_gol4_get_btn_code(void);
static uint8_t gol4_bit_reverse(uint8_t b) {
b &= 0xFF;
uint8_t result = 0;
for(uint8_t i = 0; i < 8; i++) {
result = (uint8_t)((result << 1) | (b & 1));
b >>= 1;
}
return result;
}
static uint8_t gol4_bit_parity(uint8_t b) {
uint8_t p = 0;
for(uint8_t i = 0; i < 8; i++) {
if((b >> i) & 1u) p ^= 1u;
}
return p;
}
static uint8_t gol4_lcg_step(uint8_t seed, uint8_t steps) {
uint8_t x = seed & 0xFF;
steps &= 0xFF;
for(uint8_t i = 0; i < steps; i++) {
x = (uint8_t)((21 * x + 1) & 0xFF);
}
return x;
}
static uint8_t gol4_lcg_inverse(uint8_t target, uint8_t steps) {
steps &= 0xFF;
if(steps == 0) return target & 0xFF;
return gol4_lcg_step(target, (uint8_t)(256 - steps));
}
static void gol4_decode_rotate_and_bitrev(uint8_t* raw) {
uint8_t carry = 0;
for(uint8_t r = 0; r < 3; r++) {
for(uint8_t i = 2; i < 7; i++) {
uint8_t new_carry = raw[i] & 1;
raw[i] = (uint8_t)(((raw[i] >> 1) | (carry << 7)) & 0xFF);
carry = new_carry;
}
}
raw[0] = gol4_bit_reverse(raw[0]);
raw[1] = gol4_bit_reverse(raw[1]);
raw[3] = gol4_bit_reverse(raw[3]);
raw[4] = gol4_bit_reverse(raw[4]);
uint8_t b2 = raw[2] & 0xDF;
b2 = (uint8_t)(((b2 << 4) | (b2 >> 4)) & 0xFF);
b2 = (uint8_t)((~b2) & 0xFF);
raw[2] = gol4_bit_reverse(b2);
raw[5] = gol4_bit_reverse(raw[5]);
raw[6] = gol4_bit_reverse(raw[6]);
}
static bool gol4_decode_lcg_xor(uint8_t* raw) {
if(raw[6] & 0x80) raw[5] ^= 1;
uint8_t out5 = gol4_lcg_inverse(raw[5], 0xFE);
raw[5] = out5;
uint8_t out6 = gol4_lcg_inverse(raw[6], raw[5]);
raw[6] = out6;
raw[5] ^= 0xA7;
raw[6] ^= 0x69;
return true;
}
static bool gol4_rolling_decode(uint8_t* raw) {
gol4_decode_rotate_and_bitrev(raw);
return gol4_decode_lcg_xor(raw);
}
static bool gol4_encode_lcg_xor(uint8_t* raw) {
uint8_t dec5 = (uint8_t)(raw[5] ^ 0xA7);
uint8_t dec6 = (uint8_t)(raw[6] ^ 0x69);
uint8_t enc6 = gol4_lcg_step(dec6, dec5);
uint8_t enc5 = gol4_lcg_step(dec5, 0xFE);
if(enc6 & 0x80) enc5 ^= 1;
raw[5] = enc5;
raw[6] = enc6;
return true;
}
static void gol4_encode_bitrev_and_rotate(uint8_t* raw) {
raw[0] = gol4_bit_reverse(raw[0]);
raw[1] = gol4_bit_reverse(raw[1]);
raw[3] = gol4_bit_reverse(raw[3]);
raw[4] = gol4_bit_reverse(raw[4]);
if(raw[2] == 0x0) {
raw[2] = 0xF0;
}
uint8_t b2 = gol4_bit_reverse(raw[2]);
b2 = (uint8_t)(~b2);
b2 = (uint8_t)(((b2 << 4) | (b2 >> 4)) & 0xFF);
b2 &= 0xDF;
raw[2] = b2;
raw[5] = gol4_bit_reverse(raw[5]);
raw[6] = gol4_bit_reverse(raw[6]);
uint8_t p5 = gol4_bit_parity(raw[5]);
uint8_t p6 = gol4_bit_parity(raw[6]);
uint8_t carry = 0;
for(uint8_t r = 0; r < 3; r++) {
for(int8_t i = 6; i >= 2; i--) {
uint8_t new_carry = (uint8_t)((raw[i] >> 7) & 1);
raw[i] = (uint8_t)(((raw[i] << 1) | carry) & 0xFF);
carry = new_carry;
}
}
raw[6] = (p5 == p6) ? (uint8_t)(raw[6] & 0xFBu) : (uint8_t)(raw[6] | 0x04u);
}
static bool gol4_rolling_encode(uint8_t* raw) {
if(!raw) return false;
if(!gol4_encode_lcg_xor(raw)) return false;
gol4_encode_bitrev_and_rotate(raw);
return true;
}
static void bits_to_raw(const uint8_t* bits, uint8_t* raw) {
memset(raw, 0, GOL4_RAW_BYTES);
for(uint8_t i = 0; i < subghz_protocol_ditec_gol4_const.min_count_bit_for_found; i++) {
uint8_t byte_idx = i / 8;
uint8_t bit_idx = 7 - (i % 8);
if(bits[i]) raw[byte_idx] |= (1 << bit_idx);
}
}
static void raw_to_bits(const uint8_t* raw, uint8_t* bits) {
for(uint8_t i = 0; i < subghz_protocol_ditec_gol4_const.min_count_bit_for_found; i++) {
uint8_t byte_idx = i / 8;
uint8_t bit_idx = 7 - (i % 8);
bits[i] = (uint8_t)((raw[byte_idx] >> bit_idx) & 1);
}
}
static uint64_t bits_to_data(const uint8_t* bits) {
uint64_t data = 0;
for(uint8_t i = 0; i < subghz_protocol_ditec_gol4_const.min_count_bit_for_found; i++) {
data = (data << 1) | (uint64_t)(bits[i] & 1);
}
return data;
}
static uint32_t serial_to_display(const uint8_t* s) {
if(!s) return 0;
return (uint32_t)((s[0] << 24) | (s[4] << 16) | (s[1] << 8) | s[3]);
}
void* subghz_protocol_encoder_ditec_gol4_alloc(SubGhzEnvironment* environment) {
UNUSED(environment);
SubGhzProtocolEncoderDitecGOL4* instance = malloc(sizeof(SubGhzProtocolEncoderDitecGOL4));
instance->base.protocol = &subghz_protocol_ditec_gol4;
instance->generic.protocol_name = instance->base.protocol->name;
instance->encoder.repeat = 4;
instance->encoder.size_upload = 128; // 110 actual
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
instance->encoder.is_running = false;
return instance;
}
void subghz_protocol_encoder_ditec_gol4_free(void* context) {
furi_assert(context);
SubGhzProtocolEncoderDitecGOL4* instance = context;
free(instance->encoder.upload);
free(instance);
}
/**
* Generating an upload from data.
* @param instance Pointer to a SubGhzProtocolEncoderDitecGOL4 instance
*/
static void
subghz_protocol_encoder_ditec_gol4_get_upload(SubGhzProtocolEncoderDitecGOL4* instance) {
furi_assert(instance);
size_t index = 0;
// Send key and GAP between repeats
//Send gap before data
instance->encoder.upload[index++] =
level_duration_make(false, (uint32_t)subghz_protocol_ditec_gol4_const.te_long * 22);
// Start bit
instance->encoder.upload[index++] =
level_duration_make(true, (uint32_t)subghz_protocol_ditec_gol4_const.te_short * 2);
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
if(bit_read(instance->generic.data, i - 1)) {
// Send bit 1
instance->encoder.upload[index++] =
level_duration_make(false, (uint32_t)subghz_protocol_ditec_gol4_const.te_short);
instance->encoder.upload[index++] =
level_duration_make(true, (uint32_t)subghz_protocol_ditec_gol4_const.te_long);
} else {
// Send bit 0
instance->encoder.upload[index++] =
level_duration_make(false, (uint32_t)subghz_protocol_ditec_gol4_const.te_long);
instance->encoder.upload[index++] =
level_duration_make(true, (uint32_t)subghz_protocol_ditec_gol4_const.te_short);
}
}
instance->encoder.size_upload = index;
return;
}
/**
* Analysis of received data
* @param instance Pointer to a SubGhzBlockGeneric* instance
*/
static void subghz_protocol_ditec_gol4_decode_key(SubGhzBlockGeneric* instance) {
// Ditec GOL4 Decoder
// 2025 - 2026.02 - @xMasterX (MMX) & @zero-mega
//
// RAW Samples
// 0xCCB2F83208122 - btn 1 = 0011001100101100 101111 100000110010000 01000000100100010
//
// Programming mode:
// 0xCCB1F832103B9 - btn 0 = 0011001100101100 011111 100000110010000 10000001110111001
// Regular buttons:
// 0xCCB2F8320ED66 - btn 1 = 0011001100101100 101111 100000110010000 01110110101100110
// 0xCCB37832104A6 - btn 2 = 0011001100101100 110111 100000110010000 10000010010100110
// 0xCCB3B8320DB4E - btn 4 = 0011001100101100 111011 100000110010000 01101101101001110
// 0xCCB3D8320E855 - btn 8 = 0011001100101100 111101 100000110010000 01110100001010101
//
// Regular buttons:
// Decoded array: CC 34 71 83 09 F8 C1
// Decoded array: CC 34 71 83 09 F9 C1
// Decoded array: CC 34 72 83 09 FA C1
// Decoded array: CC 34 74 83 09 FB C1
// Decoded array: CC 34 78 83 09 FC C1
// Programming mode
// Decoded array: CC 34 F0 83 09 FD C1
// Decoded array: CC 34 F0 83 09 FE C1
//
uint8_t bits[subghz_protocol_ditec_gol4_const.min_count_bit_for_found];
uint64_t data = instance->data;
for(int i = subghz_protocol_ditec_gol4_const.min_count_bit_for_found - 1; i >= 0; i--) {
bits[i] = (uint8_t)(data & 1);
data >>= 1;
}
uint8_t decrypted[GOL4_RAW_BYTES];
bits_to_raw(bits, decrypted);
if(gol4_rolling_decode(decrypted)) {
uint8_t temp_serial[5];
memcpy(temp_serial, decrypted, 5);
instance->serial = serial_to_display(temp_serial);
instance->btn = decrypted[2] & 0x0F;
instance->cnt = (uint16_t)((decrypted[5] | (decrypted[6] << 8)) & 0xFFFF);
// Save original button for later use
if(subghz_custom_btn_get_original() == 0) {
subghz_custom_btn_set_original(instance->btn);
}
subghz_custom_btn_set_max(4);
}
}
static void subghz_protocol_ditec_gol4_encode_key(SubGhzBlockGeneric* instance) {
// Encoder crypto part:
//
// TODO: Current issue - last bit at original remote sometimes 0 but we encode as 1, or vice versa.
// This does not affect decoding but may have issue on real receiver
//
uint8_t decrypted[GOL4_RAW_BYTES];
// Save original button for later use
if(subghz_custom_btn_get_original() == 0) {
subghz_custom_btn_set_original(instance->btn);
}
instance->btn = subghz_protocol_ditec_gol4_get_btn_code();
// override button if we change it with signal settings button editor
if(subghz_block_generic_global_button_override_get(&instance->btn))
FURI_LOG_D(TAG, "Button sucessfully changed to 0x%X", instance->btn);
// Check for OFEX (overflow experimental) mode
if(furi_hal_subghz_get_rolling_counter_mult() != -0x7FFFFFFF) {
// standart counter mode. PULL data from subghz_block_generic_global variables
if(!subghz_block_generic_global_counter_override_get(&instance->cnt)) {
// if counter_override_get return FALSE then counter was not changed and we increase counter by standart mult value
if((instance->cnt + furi_hal_subghz_get_rolling_counter_mult()) > 0xFFFF) {
instance->cnt = 0;
} else {
instance->cnt += furi_hal_subghz_get_rolling_counter_mult();
}
}
} else {
if((instance->cnt + 0x1) > 0xFFFF) {
instance->cnt = 0;
} else if(instance->cnt >= 0x1 && instance->cnt != 0xFFFE) {
instance->cnt = 0xFFFE;
} else {
instance->cnt++;
}
}
decrypted[0] = (uint8_t)((instance->serial >> 24) & 0xFF);
decrypted[4] = (uint8_t)((instance->serial >> 16) & 0xFF);
decrypted[1] = (uint8_t)((instance->serial >> 8) & 0xFF);
decrypted[3] = (uint8_t)(instance->serial & 0xFF);
decrypted[2] = (uint8_t)(instance->btn & 0x0F);
uint16_t counter = (uint16_t)(instance->cnt & 0xFFFF);
decrypted[5] = (uint8_t)(counter & 0xFF);
decrypted[6] = (uint8_t)((counter >> 8) & 0xFF);
gol4_rolling_encode(decrypted);
uint8_t bits[subghz_protocol_ditec_gol4_const.min_count_bit_for_found];
raw_to_bits(decrypted, bits);
instance->data = bits_to_data(bits);
}
SubGhzProtocolStatus
subghz_protocol_encoder_ditec_gol4_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolEncoderDitecGOL4* instance = context;
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
do {
ret = subghz_block_generic_deserialize_check_count_bit(
&instance->generic,
flipper_format,
subghz_protocol_ditec_gol4_const.min_count_bit_for_found);
if(ret != SubGhzProtocolStatusOk) {
break;
}
// Optional parameter
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
subghz_protocol_ditec_gol4_decode_key(&instance->generic);
subghz_protocol_ditec_gol4_encode_key(&instance->generic);
subghz_protocol_encoder_ditec_gol4_get_upload(instance);
if(!flipper_format_rewind(flipper_format)) {
FURI_LOG_E(TAG, "Rewind error");
break;
}
uint8_t key_data[sizeof(uint64_t)] = {0};
for(size_t i = 0; i < sizeof(uint64_t); i++) {
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF;
}
if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Unable to update Key");
break;
}
instance->encoder.is_running = true;
} while(false);
return ret;
}
void subghz_protocol_encoder_ditec_gol4_stop(void* context) {
SubGhzProtocolEncoderDitecGOL4* instance = context;
instance->encoder.is_running = false;
}
LevelDuration subghz_protocol_encoder_ditec_gol4_yield(void* context) {
SubGhzProtocolEncoderDitecGOL4* instance = context;
if(instance->encoder.repeat == 0 || !instance->encoder.is_running) {
instance->encoder.is_running = false;
return level_duration_reset();
}
LevelDuration ret = instance->encoder.upload[instance->encoder.front];
if(++instance->encoder.front == instance->encoder.size_upload) {
if(!subghz_block_generic_global.endless_tx) instance->encoder.repeat--;
instance->encoder.front = 0;
}
return ret;
}
void* subghz_protocol_decoder_ditec_gol4_alloc(SubGhzEnvironment* environment) {
UNUSED(environment);
SubGhzProtocolDecoderDitecGOL4* instance = malloc(sizeof(SubGhzProtocolDecoderDitecGOL4));
instance->base.protocol = &subghz_protocol_ditec_gol4;
instance->generic.protocol_name = instance->base.protocol->name;
return instance;
}
void subghz_protocol_decoder_ditec_gol4_free(void* context) {
furi_assert(context);
SubGhzProtocolDecoderDitecGOL4* instance = context;
free(instance);
}
void subghz_protocol_decoder_ditec_gol4_reset(void* context) {
furi_assert(context);
SubGhzProtocolDecoderDitecGOL4* instance = context;
instance->decoder.parser_step = DitecGOL4DecoderStepReset;
}
void subghz_protocol_decoder_ditec_gol4_feed(void* context, bool level, uint32_t duration) {
furi_check(context);
SubGhzProtocolDecoderDitecGOL4* instance = context;
switch(instance->decoder.parser_step) {
case DitecGOL4DecoderStepReset:
if((!level) && (DURATION_DIFF(duration, subghz_protocol_ditec_gol4_const.te_long * 22) <
(subghz_protocol_ditec_gol4_const.te_long * 4))) {
instance->decoder.decode_data = 0;
instance->decoder.decode_count_bit = 0;
instance->decoder.parser_step = DitecGOL4DecoderStepStartBit;
}
break;
case DitecGOL4DecoderStepStartBit:
if((level) && (DURATION_DIFF(duration, subghz_protocol_ditec_gol4_const.te_short * 2) <
subghz_protocol_ditec_gol4_const.te_delta)) {
instance->decoder.parser_step = DitecGOL4DecoderStepSaveDuration;
} else {
instance->decoder.parser_step = DitecGOL4DecoderStepReset;
}
break;
case DitecGOL4DecoderStepSaveDuration:
if(!level) {
instance->decoder.te_last = duration;
instance->decoder.parser_step = DitecGOL4DecoderStepCheckDuration;
} else {
instance->decoder.parser_step = DitecGOL4DecoderStepReset;
}
break;
case DitecGOL4DecoderStepCheckDuration:
if(level) {
if((DURATION_DIFF(
instance->decoder.te_last, subghz_protocol_ditec_gol4_const.te_short) <
subghz_protocol_ditec_gol4_const.te_delta) &&
(DURATION_DIFF(duration, subghz_protocol_ditec_gol4_const.te_long) <
subghz_protocol_ditec_gol4_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
instance->decoder.parser_step = DitecGOL4DecoderStepSaveDuration;
} else if(
(DURATION_DIFF(
instance->decoder.te_last, subghz_protocol_ditec_gol4_const.te_long) <
subghz_protocol_ditec_gol4_const.te_delta) &&
(DURATION_DIFF(duration, subghz_protocol_ditec_gol4_const.te_short) <
subghz_protocol_ditec_gol4_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
instance->decoder.parser_step = DitecGOL4DecoderStepSaveDuration;
}
} else {
if(DURATION_DIFF(
instance->decoder.te_last, subghz_protocol_ditec_gol4_const.te_long * 20) <
(subghz_protocol_ditec_gol4_const.te_long * 3)) {
if(instance->decoder.decode_count_bit ==
subghz_protocol_ditec_gol4_const.min_count_bit_for_found) {
// 54 bits received, save and continue
instance->generic.data = instance->decoder.decode_data;
instance->generic.data_count_bit =
subghz_protocol_ditec_gol4_const.min_count_bit_for_found;
if(instance->base.callback) {
instance->base.callback(&instance->base, instance->base.context);
}
}
instance->decoder.decode_data = 0;
instance->decoder.decode_count_bit = 0;
instance->decoder.parser_step = DitecGOL4DecoderStepReset;
} else {
instance->decoder.parser_step = DitecGOL4DecoderStepReset;
}
}
break;
}
}
uint8_t subghz_protocol_decoder_ditec_gol4_get_hash_data(void* context) {
furi_assert(context);
SubGhzProtocolDecoderDitecGOL4* instance = context;
return subghz_protocol_blocks_get_hash_data(
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
}
SubGhzProtocolStatus subghz_protocol_decoder_ditec_gol4_serialize(
void* context,
FlipperFormat* flipper_format,
SubGhzRadioPreset* preset) {
furi_assert(context);
SubGhzProtocolDecoderDitecGOL4* instance = context;
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
}
SubGhzProtocolStatus
subghz_protocol_decoder_ditec_gol4_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderDitecGOL4* instance = context;
return subghz_block_generic_deserialize_check_count_bit(
&instance->generic,
flipper_format,
subghz_protocol_ditec_gol4_const.min_count_bit_for_found);
}
bool subghz_protocol_ditec_gol4_create_data(
void* context,
FlipperFormat* flipper_format,
uint32_t serial,
uint8_t btn,
uint16_t cnt,
SubGhzRadioPreset* preset) {
furi_assert(context);
SubGhzProtocolEncoderDitecGOL4* instance = context;
instance->generic.btn = btn;
instance->generic.serial = serial;
instance->generic.cnt = cnt;
instance->generic.data_count_bit = subghz_protocol_ditec_gol4_const.min_count_bit_for_found;
subghz_protocol_ditec_gol4_encode_key(&instance->generic);
return SubGhzProtocolStatusOk ==
subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
}
static uint8_t subghz_protocol_ditec_gol4_get_btn_code(void) {
uint8_t custom_btn_id = subghz_custom_btn_get();
uint8_t original_btn_code = subghz_custom_btn_get_original();
uint8_t btn = original_btn_code;
// Set custom button
if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) {
// Restore original button code
btn = original_btn_code;
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) {
switch(original_btn_code) {
case 0x1:
btn = 0x2;
break;
case 0x2:
btn = 0x1;
break;
case 0x4:
btn = 0x1;
break;
case 0x8:
btn = 0x1;
break;
case 0x0:
btn = 0x1;
break;
default:
break;
}
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) {
switch(original_btn_code) {
case 0x1:
btn = 0x4;
break;
case 0x2:
btn = 0x4;
break;
case 0x4:
btn = 0x2;
break;
case 0x8:
btn = 0x4;
break;
case 0x0:
btn = 0x4;
break;
default:
break;
}
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) {
switch(original_btn_code) {
case 0x1:
btn = 0x8;
break;
case 0x2:
btn = 0x8;
break;
case 0x4:
btn = 0x8;
break;
case 0x8:
btn = 0x2;
break;
case 0x0:
btn = 0x2;
break;
default:
break;
}
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_RIGHT) {
switch(original_btn_code) {
case 0x1:
btn = 0x0;
break;
case 0x2:
btn = 0x0;
break;
case 0x4:
btn = 0x0;
break;
case 0x8:
btn = 0x0;
break;
case 0x0:
btn = 0x8;
break;
default:
break;
}
}
return btn;
}
void subghz_protocol_decoder_ditec_gol4_get_string(void* context, FuriString* output) {
furi_assert(context);
SubGhzProtocolDecoderDitecGOL4* instance = context;
subghz_protocol_ditec_gol4_decode_key(&instance->generic);
// push protocol data to global variable
subghz_block_generic_global.cnt_is_available = true;
subghz_block_generic_global.cnt_length_bit = 16;
subghz_block_generic_global.current_cnt = instance->generic.cnt;
subghz_block_generic_global.btn_is_available = true;
subghz_block_generic_global.current_btn = instance->generic.btn;
subghz_block_generic_global.btn_length_bit = 4;
//
furi_string_cat_printf(
output,
"%s %db\r\n"
"Key:0x%0lX%08lX\r\n"
"Serial:0x%08lX\r\n"
"Btn:%01X %s\r\n"
"Cnt:%04lX",
instance->generic.protocol_name,
instance->generic.data_count_bit,
(uint32_t)(instance->generic.data >> 32),
(uint32_t)(instance->generic.data & 0xFFFFFFFF),
instance->generic.serial,
instance->generic.btn,
(instance->generic.btn == 0x0) ? "- Prog" : "",
instance->generic.cnt);
}
+109
View File
@@ -0,0 +1,109 @@
#pragma once
#include "base.h"
#define SUBGHZ_PROTOCOL_DITEC_GOL4_NAME "Ditec GOL4"
typedef struct SubGhzProtocolDecoderDitecGOL4 SubGhzProtocolDecoderDitecGOL4;
typedef struct SubGhzProtocolEncoderDitecGOL4 SubGhzProtocolEncoderDitecGOL4;
extern const SubGhzProtocolDecoder subghz_protocol_ditec_gol4_decoder;
extern const SubGhzProtocolEncoder subghz_protocol_ditec_gol4_encoder;
extern const SubGhzProtocol subghz_protocol_ditec_gol4;
/**
* Allocate SubGhzProtocolEncoderDitecGOL4.
* @param environment Pointer to a SubGhzEnvironment instance
* @return SubGhzProtocolEncoderDitecGOL4* pointer to a SubGhzProtocolEncoderDitecGOL4 instance
*/
void* subghz_protocol_encoder_ditec_gol4_alloc(SubGhzEnvironment* environment);
/**
* Free SubGhzProtocolEncoderDitecGOL4.
* @param context Pointer to a SubGhzProtocolEncoderDitecGOL4 instance
*/
void subghz_protocol_encoder_ditec_gol4_free(void* context);
/**
* Deserialize and generating an upload to send.
* @param context Pointer to a SubGhzProtocolEncoderDitecGOL4 instance
* @param flipper_format Pointer to a FlipperFormat instance
* @return status
*/
SubGhzProtocolStatus
subghz_protocol_encoder_ditec_gol4_deserialize(void* context, FlipperFormat* flipper_format);
/**
* Forced transmission stop.
* @param context Pointer to a SubGhzProtocolEncoderDitecGOL4 instance
*/
void subghz_protocol_encoder_ditec_gol4_stop(void* context);
/**
* Getting the level and duration of the upload to be loaded into DMA.
* @param context Pointer to a SubGhzProtocolEncoderDitecGOL4 instance
* @return LevelDuration
*/
LevelDuration subghz_protocol_encoder_ditec_gol4_yield(void* context);
/**
* Allocate SubGhzProtocolDecoderDitecGOL4.
* @param environment Pointer to a SubGhzEnvironment instance
* @return SubGhzProtocolDecoderDitecGOL4* pointer to a SubGhzProtocolDecoderDitecGOL4 instance
*/
void* subghz_protocol_decoder_ditec_gol4_alloc(SubGhzEnvironment* environment);
/**
* Free SubGhzProtocolDecoderDitecGOL4.
* @param context Pointer to a SubGhzProtocolDecoderDitecGOL4 instance
*/
void subghz_protocol_decoder_ditec_gol4_free(void* context);
/**
* Reset decoder SubGhzProtocolDecoderDitecGOL4.
* @param context Pointer to a SubGhzProtocolDecoderDitecGOL4 instance
*/
void subghz_protocol_decoder_ditec_gol4_reset(void* context);
/**
* Parse a raw sequence of levels and durations received from the air.
* @param context Pointer to a SubGhzProtocolDecoderDitecGOL4 instance
* @param level Signal level true-high false-low
* @param duration Duration of this level in, us
*/
void subghz_protocol_decoder_ditec_gol4_feed(void* context, bool level, uint32_t duration);
/**
* Getting the hash sum of the last randomly received parcel.
* @param context Pointer to a SubGhzProtocolDecoderDitecGOL4 instance
* @return hash Hash sum
*/
uint8_t subghz_protocol_decoder_ditec_gol4_get_hash_data(void* context);
/**
* Serialize data SubGhzProtocolDecoderDitecGOL4.
* @param context Pointer to a SubGhzProtocolDecoderDitecGOL4 instance
* @param flipper_format Pointer to a FlipperFormat instance
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
* @return status
*/
SubGhzProtocolStatus subghz_protocol_decoder_ditec_gol4_serialize(
void* context,
FlipperFormat* flipper_format,
SubGhzRadioPreset* preset);
/**
* Deserialize data SubGhzProtocolDecoderDitecGOL4.
* @param context Pointer to a SubGhzProtocolDecoderDitecGOL4 instance
* @param flipper_format Pointer to a FlipperFormat instance
* @return status
*/
SubGhzProtocolStatus
subghz_protocol_decoder_ditec_gol4_deserialize(void* context, FlipperFormat* flipper_format);
/**
* Getting a textual representation of the received data.
* @param context Pointer to a SubGhzProtocolDecoderDitecGOL4 instance
* @param output Resulting text
*/
void subghz_protocol_decoder_ditec_gol4_get_string(void* context, FuriString* output);
+350
View File
@@ -0,0 +1,350 @@
#include "nord_ice.h"
#include "../blocks/const.h"
#include "../blocks/decoder.h"
#include "../blocks/encoder.h"
#include "../blocks/generic.h"
#include "../blocks/math.h"
#define TAG "SubGhzProtocolNord_Ice"
static const SubGhzBlockConst subghz_protocol_nord_ice_const = {
.te_short = 300,
.te_long = 800,
.te_delta = 150,
.min_count_bit_for_found = 33,
};
struct SubGhzProtocolDecoderNord_Ice {
SubGhzProtocolDecoderBase base;
SubGhzBlockDecoder decoder;
SubGhzBlockGeneric generic;
};
struct SubGhzProtocolEncoderNord_Ice {
SubGhzProtocolEncoderBase base;
SubGhzProtocolBlockEncoder encoder;
SubGhzBlockGeneric generic;
};
typedef enum {
Nord_IceDecoderStepReset = 0,
Nord_IceDecoderStepSaveDuration,
Nord_IceDecoderStepCheckDuration,
} Nord_IceDecoderStep;
const SubGhzProtocolDecoder subghz_protocol_nord_ice_decoder = {
.alloc = subghz_protocol_decoder_nord_ice_alloc,
.free = subghz_protocol_decoder_nord_ice_free,
.feed = subghz_protocol_decoder_nord_ice_feed,
.reset = subghz_protocol_decoder_nord_ice_reset,
.get_hash_data = subghz_protocol_decoder_nord_ice_get_hash_data,
.serialize = subghz_protocol_decoder_nord_ice_serialize,
.deserialize = subghz_protocol_decoder_nord_ice_deserialize,
.get_string = subghz_protocol_decoder_nord_ice_get_string,
};
const SubGhzProtocolEncoder subghz_protocol_nord_ice_encoder = {
.alloc = subghz_protocol_encoder_nord_ice_alloc,
.free = subghz_protocol_encoder_nord_ice_free,
.deserialize = subghz_protocol_encoder_nord_ice_deserialize,
.stop = subghz_protocol_encoder_nord_ice_stop,
.yield = subghz_protocol_encoder_nord_ice_yield,
};
const SubGhzProtocol subghz_protocol_nord_ice = {
.name = SUBGHZ_PROTOCOL_NORD_ICE_NAME,
.type = SubGhzProtocolTypeStatic,
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable |
SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send,
.decoder = &subghz_protocol_nord_ice_decoder,
.encoder = &subghz_protocol_nord_ice_encoder,
};
void* subghz_protocol_encoder_nord_ice_alloc(SubGhzEnvironment* environment) {
UNUSED(environment);
SubGhzProtocolEncoderNord_Ice* instance = malloc(sizeof(SubGhzProtocolEncoderNord_Ice));
instance->base.protocol = &subghz_protocol_nord_ice;
instance->generic.protocol_name = instance->base.protocol->name;
instance->encoder.repeat = 3;
instance->encoder.size_upload = 128;
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
instance->encoder.is_running = false;
return instance;
}
void subghz_protocol_encoder_nord_ice_free(void* context) {
furi_assert(context);
SubGhzProtocolEncoderNord_Ice* instance = context;
free(instance->encoder.upload);
free(instance);
}
/**
* Generating an upload from data.
* @param instance Pointer to a SubGhzProtocolEncoderNord_Ice instance
*/
static void subghz_protocol_encoder_nord_ice_get_upload(SubGhzProtocolEncoderNord_Ice* instance) {
furi_assert(instance);
size_t index = 0;
// Send key and GAP
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
if(bit_read(instance->generic.data, i - 1)) {
// Send bit 1
instance->encoder.upload[index++] =
level_duration_make(true, (uint32_t)subghz_protocol_nord_ice_const.te_long);
if(i == 1) {
//Send gap if bit was last
instance->encoder.upload[index++] = level_duration_make(
false, (uint32_t)subghz_protocol_nord_ice_const.te_short * 25);
} else {
instance->encoder.upload[index++] =
level_duration_make(false, (uint32_t)subghz_protocol_nord_ice_const.te_short);
}
} else {
// Send bit 0
instance->encoder.upload[index++] =
level_duration_make(true, (uint32_t)subghz_protocol_nord_ice_const.te_short);
if(i == 1) {
//Send gap if bit was last
instance->encoder.upload[index++] = level_duration_make(
false, (uint32_t)subghz_protocol_nord_ice_const.te_short * 25);
} else {
instance->encoder.upload[index++] =
level_duration_make(false, (uint32_t)subghz_protocol_nord_ice_const.te_long);
}
}
}
instance->encoder.size_upload = index;
return;
}
/**
* Analysis of received data
* @param instance Pointer to a SubGhzBlockGeneric* instance
*/
static void subghz_protocol_nord_ice_check_remote_controller(SubGhzBlockGeneric* instance) {
instance->serial = (instance->data >> 15) << 9 |
(instance->data & 0x1FF); // 26 bits for serial
instance->btn = (instance->data >> 9) & 0x3F; // 6 bits for button
}
SubGhzProtocolStatus
subghz_protocol_encoder_nord_ice_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolEncoderNord_Ice* instance = context;
SubGhzProtocolStatus ret = SubGhzProtocolStatusError;
do {
ret = subghz_block_generic_deserialize_check_count_bit(
&instance->generic,
flipper_format,
subghz_protocol_nord_ice_const.min_count_bit_for_found);
if(ret != SubGhzProtocolStatusOk) {
break;
}
// Optional value
flipper_format_read_uint32(
flipper_format, "Repeat", (uint32_t*)&instance->encoder.repeat, 1);
subghz_protocol_nord_ice_check_remote_controller(&instance->generic);
subghz_protocol_encoder_nord_ice_get_upload(instance);
instance->encoder.is_running = true;
} while(false);
return ret;
}
void subghz_protocol_encoder_nord_ice_stop(void* context) {
SubGhzProtocolEncoderNord_Ice* instance = context;
instance->encoder.is_running = false;
}
LevelDuration subghz_protocol_encoder_nord_ice_yield(void* context) {
SubGhzProtocolEncoderNord_Ice* instance = context;
if(instance->encoder.repeat == 0 || !instance->encoder.is_running) {
instance->encoder.is_running = false;
return level_duration_reset();
}
LevelDuration ret = instance->encoder.upload[instance->encoder.front];
if(++instance->encoder.front == instance->encoder.size_upload) {
if(!subghz_block_generic_global.endless_tx) instance->encoder.repeat--;
instance->encoder.front = 0;
}
return ret;
}
void* subghz_protocol_decoder_nord_ice_alloc(SubGhzEnvironment* environment) {
UNUSED(environment);
SubGhzProtocolDecoderNord_Ice* instance = malloc(sizeof(SubGhzProtocolDecoderNord_Ice));
instance->base.protocol = &subghz_protocol_nord_ice;
instance->generic.protocol_name = instance->base.protocol->name;
return instance;
}
void subghz_protocol_decoder_nord_ice_free(void* context) {
furi_assert(context);
SubGhzProtocolDecoderNord_Ice* instance = context;
free(instance);
}
void subghz_protocol_decoder_nord_ice_reset(void* context) {
furi_assert(context);
SubGhzProtocolDecoderNord_Ice* instance = context;
instance->decoder.parser_step = Nord_IceDecoderStepReset;
}
void subghz_protocol_decoder_nord_ice_feed(void* context, bool level, volatile uint32_t duration) {
furi_assert(context);
SubGhzProtocolDecoderNord_Ice* instance = context;
// Nord ICE Decoder
// 2026.03 - @xMasterX (MMX)
// Key samples
//
// Serial Btn Serial
// 0x9467688A btn 1 = 10010100011001110 110100 010001010
// 0x9467308A btn 2 = 10010100011001110 011000 010001010
// 0x9467628A btn 3 = 10010100011001110 110001 010001010
// 0x9467648A btn 4 = 10010100011001110 110010 010001010
switch(instance->decoder.parser_step) {
case Nord_IceDecoderStepReset:
if((!level) && (DURATION_DIFF(duration, subghz_protocol_nord_ice_const.te_short * 25) <
subghz_protocol_nord_ice_const.te_delta * 11)) {
//Found GAP
instance->decoder.decode_data = 0;
instance->decoder.decode_count_bit = 0;
instance->decoder.parser_step = Nord_IceDecoderStepSaveDuration;
}
break;
case Nord_IceDecoderStepSaveDuration:
if(level) {
instance->decoder.te_last = duration;
instance->decoder.parser_step = Nord_IceDecoderStepCheckDuration;
} else {
instance->decoder.parser_step = Nord_IceDecoderStepReset;
}
break;
case Nord_IceDecoderStepCheckDuration:
if(!level) {
// Bit 0 is short and long timing = 300us HIGH (te_last) and 800us LOW
if((DURATION_DIFF(instance->decoder.te_last, subghz_protocol_nord_ice_const.te_short) <
subghz_protocol_nord_ice_const.te_delta) &&
(DURATION_DIFF(duration, subghz_protocol_nord_ice_const.te_long) <
subghz_protocol_nord_ice_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
instance->decoder.parser_step = Nord_IceDecoderStepSaveDuration;
// Bit 1 is long and short timing = 800us HIGH (te_last) and 300us LOW
} else if(
(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_nord_ice_const.te_long) <
subghz_protocol_nord_ice_const.te_delta) &&
(DURATION_DIFF(duration, subghz_protocol_nord_ice_const.te_short) <
subghz_protocol_nord_ice_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
instance->decoder.parser_step = Nord_IceDecoderStepSaveDuration;
} else if(
// End of the key
DURATION_DIFF(duration, subghz_protocol_nord_ice_const.te_short * 25) <
subghz_protocol_nord_ice_const.te_delta * 11) {
//Found next GAP and add bit 0 or 1 (only bit 0 was found on the remotes)
if((DURATION_DIFF(
instance->decoder.te_last, subghz_protocol_nord_ice_const.te_short) <
subghz_protocol_nord_ice_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 0);
}
if((DURATION_DIFF(
instance->decoder.te_last, subghz_protocol_nord_ice_const.te_long) <
subghz_protocol_nord_ice_const.te_delta)) {
subghz_protocol_blocks_add_bit(&instance->decoder, 1);
}
// If got 33 bits key reading is finished
if(instance->decoder.decode_count_bit ==
subghz_protocol_nord_ice_const.min_count_bit_for_found) {
instance->generic.data = instance->decoder.decode_data;
instance->generic.data_count_bit = instance->decoder.decode_count_bit;
if(instance->base.callback)
instance->base.callback(&instance->base, instance->base.context);
}
instance->decoder.decode_data = 0;
instance->decoder.decode_count_bit = 0;
instance->decoder.parser_step = Nord_IceDecoderStepReset;
} else {
instance->decoder.parser_step = Nord_IceDecoderStepReset;
}
} else {
instance->decoder.parser_step = Nord_IceDecoderStepReset;
}
break;
}
}
uint8_t subghz_protocol_decoder_nord_ice_get_hash_data(void* context) {
furi_assert(context);
SubGhzProtocolDecoderNord_Ice* instance = context;
return subghz_protocol_blocks_get_hash_data(
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
}
SubGhzProtocolStatus subghz_protocol_decoder_nord_ice_serialize(
void* context,
FlipperFormat* flipper_format,
SubGhzRadioPreset* preset) {
furi_assert(context);
SubGhzProtocolDecoderNord_Ice* instance = context;
return subghz_block_generic_serialize(&instance->generic, flipper_format, preset);
}
SubGhzProtocolStatus
subghz_protocol_decoder_nord_ice_deserialize(void* context, FlipperFormat* flipper_format) {
furi_assert(context);
SubGhzProtocolDecoderNord_Ice* instance = context;
return subghz_block_generic_deserialize_check_count_bit(
&instance->generic,
flipper_format,
subghz_protocol_nord_ice_const.min_count_bit_for_found);
}
void subghz_protocol_decoder_nord_ice_get_string(void* context, FuriString* output) {
furi_assert(context);
SubGhzProtocolDecoderNord_Ice* instance = context;
subghz_protocol_nord_ice_check_remote_controller(&instance->generic);
uint64_t code_found_reverse = subghz_protocol_blocks_reverse_key(
instance->generic.data, instance->generic.data_count_bit);
// for future use
// // push protocol data to global variable
// subghz_block_generic_global.btn_is_available = false;
// subghz_block_generic_global.current_btn = instance->generic.btn;
// subghz_block_generic_global.btn_length_bit = 4;
// //
furi_string_cat_printf(
output,
"%s %db\r\n"
"Key: 0x%08llX\r\n"
"Yek: 0x%08llX\r\n"
"Serial: 0x%07lX\r\n"
"Btn: %02X",
instance->generic.protocol_name,
instance->generic.data_count_bit,
(uint64_t)(instance->generic.data & 0xFFFFFFFFF),
(code_found_reverse & 0xFFFFFFFFF),
instance->generic.serial,
instance->generic.btn);
}
+109
View File
@@ -0,0 +1,109 @@
#pragma once
#include "base.h"
#define SUBGHZ_PROTOCOL_NORD_ICE_NAME "Nord ICE"
typedef struct SubGhzProtocolDecoderNord_Ice SubGhzProtocolDecoderNord_Ice;
typedef struct SubGhzProtocolEncoderNord_Ice SubGhzProtocolEncoderNord_Ice;
extern const SubGhzProtocolDecoder subghz_protocol_nord_ice_decoder;
extern const SubGhzProtocolEncoder subghz_protocol_nord_ice_encoder;
extern const SubGhzProtocol subghz_protocol_nord_ice;
/**
* Allocate SubGhzProtocolEncoderNord_Ice.
* @param environment Pointer to a SubGhzEnvironment instance
* @return SubGhzProtocolEncoderNord_Ice* pointer to a SubGhzProtocolEncoderNord_Ice instance
*/
void* subghz_protocol_encoder_nord_ice_alloc(SubGhzEnvironment* environment);
/**
* Free SubGhzProtocolEncoderNord_Ice.
* @param context Pointer to a SubGhzProtocolEncoderNord_Ice instance
*/
void subghz_protocol_encoder_nord_ice_free(void* context);
/**
* Deserialize and generating an upload to send.
* @param context Pointer to a SubGhzProtocolEncoderNord_Ice instance
* @param flipper_format Pointer to a FlipperFormat instance
* @return status
*/
SubGhzProtocolStatus
subghz_protocol_encoder_nord_ice_deserialize(void* context, FlipperFormat* flipper_format);
/**
* Forced transmission stop.
* @param context Pointer to a SubGhzProtocolEncoderNord_Ice instance
*/
void subghz_protocol_encoder_nord_ice_stop(void* context);
/**
* Getting the level and duration of the upload to be loaded into DMA.
* @param context Pointer to a SubGhzProtocolEncoderNord_Ice instance
* @return LevelDuration
*/
LevelDuration subghz_protocol_encoder_nord_ice_yield(void* context);
/**
* Allocate SubGhzProtocolDecoderNord_Ice.
* @param environment Pointer to a SubGhzEnvironment instance
* @return SubGhzProtocolDecoderNord_Ice* pointer to a SubGhzProtocolDecoderNord_Ice instance
*/
void* subghz_protocol_decoder_nord_ice_alloc(SubGhzEnvironment* environment);
/**
* Free SubGhzProtocolDecoderNord_Ice.
* @param context Pointer to a SubGhzProtocolDecoderNord_Ice instance
*/
void subghz_protocol_decoder_nord_ice_free(void* context);
/**
* Reset decoder SubGhzProtocolDecoderNord_Ice.
* @param context Pointer to a SubGhzProtocolDecoderNord_Ice instance
*/
void subghz_protocol_decoder_nord_ice_reset(void* context);
/**
* Parse a raw sequence of levels and durations received from the air.
* @param context Pointer to a SubGhzProtocolDecoderNord_Ice instance
* @param level Signal level true-high false-low
* @param duration Duration of this level in, us
*/
void subghz_protocol_decoder_nord_ice_feed(void* context, bool level, uint32_t duration);
/**
* Getting the hash sum of the last randomly received parcel.
* @param context Pointer to a SubGhzProtocolDecoderNord_Ice instance
* @return hash Hash sum
*/
uint8_t subghz_protocol_decoder_nord_ice_get_hash_data(void* context);
/**
* Serialize data SubGhzProtocolDecoderNord_Ice.
* @param context Pointer to a SubGhzProtocolDecoderNord_Ice instance
* @param flipper_format Pointer to a FlipperFormat instance
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
* @return status
*/
SubGhzProtocolStatus subghz_protocol_decoder_nord_ice_serialize(
void* context,
FlipperFormat* flipper_format,
SubGhzRadioPreset* preset);
/**
* Deserialize data SubGhzProtocolDecoderNord_Ice.
* @param context Pointer to a SubGhzProtocolDecoderNord_Ice instance
* @param flipper_format Pointer to a FlipperFormat instance
* @return status
*/
SubGhzProtocolStatus
subghz_protocol_decoder_nord_ice_deserialize(void* context, FlipperFormat* flipper_format);
/**
* Getting a textual representation of the received data.
* @param context Pointer to a SubGhzProtocolDecoderNord_Ice instance
* @param output Resulting text
*/
void subghz_protocol_decoder_nord_ice_get_string(void* context, FuriString* output);