Encoder fix

This commit is contained in:
assasinfil 2023-02-11 19:18:42 +03:00
parent 285c324e8d
commit c2545a2f7b
No known key found for this signature in database
GPG key ID: E5C793A4B4737A16

View file

@ -100,7 +100,7 @@ void* subghz_protocol_encoder_nice_flor_s_alloc(SubGhzEnvironment* environment)
TAG, "Loading rainbow table from %s", instance->nice_flor_s_rainbow_table_file_name);
}
instance->encoder.repeat = 10;
instance->encoder.size_upload = 1728; //wrong!! upload 186*16 = 2976 - actual size about 1728
instance->encoder.size_upload = 4096; //wrong!! upload 186*16 = 2976 - actual size about 1728
instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration));
instance->encoder.is_running = false;
return instance;
@ -113,6 +113,8 @@ void subghz_protocol_encoder_nice_flor_s_free(void* context) {
free(instance);
}
static void subghz_protocol_nice_one_get_data(uint8_t* p, uint8_t num_parcel, uint8_t hold_bit);
/**
* Generating an upload from data.
* @param instance Pointer to a SubGhzProtocolEncoderNiceFlorS instance
@ -141,6 +143,11 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload(
uint64_t decrypt = ((uint64_t)instance->generic.serial << 16) | instance->generic.cnt;
uint64_t enc_part = subghz_protocol_nice_flor_s_encrypt(decrypt, file_name);
uint8_t add_data[10] = {0};
for(size_t i = 0; i < 7; i++) {
add_data[i] = (instance->generic.data >> (48 - i * 8)) & 0xFF;
}
for(int i = 0; i < 16; i++) {
static const uint64_t loops[16] = {
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF};
@ -160,8 +167,8 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload(
level_duration_make(false, (uint32_t)subghz_protocol_nice_flor_s_const.te_short * 3);
//Send key data
for(uint8_t i = instance->generic.data_count_bit; i > 0; i--) {
if(bit_read(instance->generic.data, i - 1)) {
for(uint8_t j = 52; j > 0; j--) {
if(bit_read(instance->generic.data, j - 1)) {
//send bit 1
instance->encoder.upload[index++] =
level_duration_make(true, (uint32_t)subghz_protocol_nice_flor_s_const.te_long);
@ -175,6 +182,32 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload(
false, (uint32_t)subghz_protocol_nice_flor_s_const.te_long);
}
}
if(instance->generic.data_count_bit == NICE_ONE_COUNT_BIT) {
add_data[7] = 0;
add_data[8] = 0;
add_data[9] = 0;
subghz_protocol_nice_one_get_data(add_data, i, 0);
for(size_t j = 6; j < 9; j++) {
instance->generic.data_2 = instance->generic.data_2 << 8 | add_data[i];
}
//Send key data
for(uint8_t j = 24; j > 4; j--) {
if(bit_read(instance->generic.data_2, j - 1)) {
//send bit 1
instance->encoder.upload[index++] = level_duration_make(
true, (uint32_t)subghz_protocol_nice_flor_s_const.te_long);
instance->encoder.upload[index++] = level_duration_make(
false, (uint32_t)subghz_protocol_nice_flor_s_const.te_short);
} else {
//send bit 0
instance->encoder.upload[index++] = level_duration_make(
true, (uint32_t)subghz_protocol_nice_flor_s_const.te_short);
instance->encoder.upload[index++] = level_duration_make(
false, (uint32_t)subghz_protocol_nice_flor_s_const.te_long);
}
}
}
//Send stop bit
instance->encoder.upload[index++] =
level_duration_make(true, (uint32_t)subghz_protocol_nice_flor_s_const.te_short * 3);
@ -247,63 +280,63 @@ LevelDuration subghz_protocol_encoder_nice_flor_s_yield(void* context) {
return ret;
}
// /**
// * Read bytes from rainbow table
// * @param p array[10] P0-P1|P2-P3-P4-P5-P6-P7-P8-P9-P10
// * @return crc
// */
// static uint32_t subghz_protocol_nice_one_crc(uint8_t* p) {
// uint8_t crc = 0;
// uint8_t crc_data = 0xff;
// for(uint8_t i = 4; i < 68; i++) {
// if(subghz_protocol_blocks_get_bit_array(p, i)) {
// crc = crc_data ^ 1;
// } else {
// crc = crc_data;
// }
// crc_data >>= 1;
// if((crc & 0x01)) {
// crc_data ^= 0x97;
// }
// }
// crc = 0;
// for(uint8_t i = 0; i < 8; i++) {
// crc <<= 1;
// if((crc_data >> i) & 0x01) crc = crc | 1;
// }
// return crc;
// }
/**
* Read bytes from rainbow table
* @param p array[10] P0-P1|P2-P3-P4-P5-P6-P7-P8-P9-P10
* @return crc
*/
static uint32_t subghz_protocol_nice_one_crc(uint8_t* p) {
uint8_t crc = 0;
uint8_t crc_data = 0xff;
for(uint8_t i = 4; i < 68; i++) {
if(subghz_protocol_blocks_get_bit_array(p, i)) {
crc = crc_data ^ 1;
} else {
crc = crc_data;
}
crc_data >>= 1;
if((crc & 0x01)) {
crc_data ^= 0x97;
}
}
crc = 0;
for(uint8_t i = 0; i < 8; i++) {
crc <<= 1;
if((crc_data >> i) & 0x01) crc = crc | 1;
}
return crc;
}
// /**
// * Read bytes from rainbow table
// * @param p array[10] P0-P1|P2-P3-P4-P5-P6-P7-XX-XX-XX
// * @param num_parcel parcel number 0..15
// * @param hold_bit 0 - the button was only pressed, 1 - the button was held down
// */
// static void subghz_protocol_nice_one_get_data(uint8_t* p, uint8_t num_parcel, uint8_t hold_bit) {
// uint8_t k = 0;
// uint8_t crc = 0;
// p[1] = (p[1] & 0x0f) | ((0x0f ^ (p[0] & 0x0F) ^ num_parcel) << 4);
// if(num_parcel < 4) {
// k = 0x8f;
// } else {
// k = 0x80;
// }
/**
* Read bytes from rainbow table
* @param p array[10] P0-P1|P2-P3-P4-P5-P6-P7-XX-XX-XX
* @param num_parcel parcel number 0..15
* @param hold_bit 0 - the button was only pressed, 1 - the button was held down
*/
static void subghz_protocol_nice_one_get_data(uint8_t* p, uint8_t num_parcel, uint8_t hold_bit) {
uint8_t k = 0;
uint8_t crc = 0;
p[1] = (p[1] & 0x0f) | ((0x0f ^ (p[0] & 0x0F) ^ num_parcel) << 4);
if(num_parcel < 4) {
k = 0x8f;
} else {
k = 0x80;
}
// if(!hold_bit) {
// hold_bit = 0;
// } else {
// hold_bit = 0x10;
// }
// k = num_parcel ^ k;
// p[7] = k;
// p[8] = hold_bit ^ (k << 4);
if(!hold_bit) {
hold_bit = 0;
} else {
hold_bit = 0x10;
}
k = num_parcel ^ k;
p[7] = k;
p[8] = hold_bit ^ (k << 4);
// crc = subghz_protocol_nice_one_crc(p);
crc = subghz_protocol_nice_one_crc(p);
// p[8] |= crc >> 4;
// p[9] = crc << 4;
// }
p[8] |= crc >> 4;
p[9] = crc << 4;
}
/**
* Read bytes from rainbow table
@ -413,7 +446,7 @@ bool subghz_protocol_nice_flor_s_create_data(
SubGhzProtocolEncoderNiceFlorS* instance = context;
instance->generic.serial = serial;
instance->generic.cnt = cnt;
instance->generic.data_count_bit = 52;
// instance->generic.data_count_bit = 52;
uint64_t decrypt = ((uint64_t)instance->generic.serial << 16) | instance->generic.cnt;
uint64_t enc_part = subghz_protocol_nice_flor_s_encrypt(
decrypt, instance->nice_flor_s_rainbow_table_file_name);