XN297DUMP: dynamic address search

The dump process is now looking for addresses with different length (3..5) additonnaly to the packet length.
Untested...
This commit is contained in:
Pascal Langer 2019-05-17 17:00:08 +02:00
parent 443e1cec75
commit ccdf60d525
2 changed files with 26 additions and 21 deletions

View File

@ -19,7 +19,7 @@
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_REVISION 1
#define VERSION_PATCH_LEVEL 47
#define VERSION_PATCH_LEVEL 48
//******************
// Protocols

View File

@ -18,7 +18,6 @@
#include "iface_nrf24l01.h"
// Parameters which can be modified
#define XN297DUMP_ADDRESS_LENGTH 5 // Default address length is 5, valid address length is between 3 and 5
#define XN297DUMP_PERIOD_DUMP 2000 // Multiplied by 50, default 2000=100ms
#define XN297DUMP_MAX_RF_CHANNEL 84 // Default 84
@ -27,6 +26,8 @@
#define XN297DUMP_MAX_PACKET_LEN 32
#define XN297DUMP_CRC_LENGTH 2
uint8_t address_length;
static void __attribute__((unused)) XN297Dump_init()
{
NRF24L01_Initialize();
@ -41,7 +42,7 @@ static void __attribute__((unused)) XN297Dump_init()
NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, (uint8_t*)"\x55\x0F\x71", 3); // set up RX address to xn297 preamble
NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, XN297DUMP_MAX_PACKET_LEN); // Enable rx pipe 0
debug("XN297 dump, scramble=%c, address length=%d, speed=",RX_num?'N':'Y', XN297DUMP_ADDRESS_LENGTH);
debug("XN297 dump, scramble=%c, speed=",RX_num?'N':'Y');
switch(sub_protocol)
{
case 0:
@ -67,17 +68,18 @@ static void __attribute__((unused)) XN297Dump_init()
static boolean __attribute__((unused)) XN297Dump_process_packet(void)
{
uint16_t crcxored;
uint8_t packet_ori[XN297DUMP_MAX_PACKET_LEN];
memcpy(packet_ori,packet,XN297DUMP_MAX_PACKET_LEN);
packet_length=XN297DUMP_MAX_PACKET_LEN-XN297DUMP_CRC_LENGTH;
address_length=5;
while(packet_length > XN297DUMP_ADDRESS_LENGTH)
while(address_length >= 3)
{
// init crc
crc = 0xb5d2;
// unscramble address
for (uint8_t i = 0; i < XN297DUMP_ADDRESS_LENGTH; i++)
for (uint8_t i = 0; i < address_length; i++)
{
crc = crc16_update(crc, packet[i], 8);
rx_id[i]=packet[i];
@ -85,26 +87,29 @@ static boolean __attribute__((unused)) XN297Dump_process_packet(void)
rx_id[i] ^= xn297_scramble[i];
}
// reverse address order
for (uint8_t i = 0; i < XN297DUMP_ADDRESS_LENGTH; i++)
packet[i]=rx_id[XN297DUMP_ADDRESS_LENGTH-1-i];
for (uint8_t i = 0; i < address_length; i++)
packet[i]=rx_id[address_length-1-i];
// unscramble payload
for (uint8_t i = XN297DUMP_ADDRESS_LENGTH; i < packet_length; i++)
for (uint8_t i = address_length; i < XN297DUMP_MAX_PACKET_LEN-XN297DUMP_CRC_LENGTH; i++)
{
crc = crc16_update(crc, packet[i], 8);
if (!RX_num)
packet[i] ^= xn297_scramble[i];
packet[i] = bit_reverse(packet[i]);
}
// check crc
if (RX_num)
crc ^= pgm_read_word(&xn297_crc_xorout[packet_length - 3]);
crcxored = crc ^ pgm_read_word(&xn297_crc_xorout[i - 3]);
else
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[packet_length - 3]);
if( (crc >> 8) == packet[packet_length] && (crc & 0xff) == packet[packet_length + 1])
crcxored = crc ^ pgm_read_word(&xn297_crc_xorout_scrambled[i - 3]);
if( (crcxored >> 8) == packet[i + 1] && (crcxored & 0xff) == packet[i + 2])
{
packet_length=i+1;
return true;
packet_length--;
}
}
address_length--;
memcpy(packet,packet_ori,XN297DUMP_MAX_PACKET_LEN);
}
return false;
@ -145,12 +150,12 @@ static uint16_t XN297Dump_callback()
if(XN297Dump_process_packet())
{ // valid crc found
debug("A=");
for(uint8_t i=0; i<XN297DUMP_ADDRESS_LENGTH; i++)
for(uint8_t i=0; i<address_length; i++)
{
debug(" %02X",packet[i]);
}
debug(" P(%d)=",packet_length-XN297DUMP_ADDRESS_LENGTH);
for(uint8_t i=XN297DUMP_ADDRESS_LENGTH; i<packet_length; i++)
debug(" P(%d)=",packet_length-address_length);
for(uint8_t i=address_length; i<packet_length; i++)
{
debug(" %02X",packet[i]);
}