mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
sub carrier and fsk clock
This commit is contained in:
parent
1e37d548c2
commit
2065d7a2c6
3 changed files with 52 additions and 23 deletions
|
@ -2313,11 +2313,34 @@ static int CmdDataNDEF(const char *Cmd) {
|
|||
typedef struct {
|
||||
t55xx_modulation modulation;
|
||||
int bitrate;
|
||||
int carrier;
|
||||
uint8_t fc1;
|
||||
uint8_t fc2;
|
||||
} lf_modulation_t;
|
||||
|
||||
static int print_modulation(lf_modulation_t b) {
|
||||
PrintAndLogEx(INFO, " Modulation... " _GREEN_("%s"), GetSelectedModulationStr(b.modulation));
|
||||
PrintAndLogEx(INFO, " Bit Rate..... " _GREEN_("RF/%u"), b.bitrate);
|
||||
PrintAndLogEx(INFO, " Modulation.... " _GREEN_("%s"), GetSelectedModulationStr(b.modulation));
|
||||
PrintAndLogEx(INFO, " Bit clock..... " _GREEN_("RF/%d"), b.bitrate);
|
||||
switch (b.modulation) {
|
||||
case DEMOD_PSK1:
|
||||
case DEMOD_PSK2:
|
||||
case DEMOD_PSK3:
|
||||
PrintAndLogEx(SUCCESS, " Carrier rate.. %d", b.carrier);
|
||||
break;
|
||||
case DEMOD_FSK:
|
||||
case DEMOD_FSK1:
|
||||
case DEMOD_FSK1a:
|
||||
case DEMOD_FSK2:
|
||||
case DEMOD_FSK2a:
|
||||
PrintAndLogEx(SUCCESS, " Field Clocks.. FC/%u, FC/%u", b.fc1, b.fc2);
|
||||
break;
|
||||
case DEMOD_NRZ:
|
||||
case DEMOD_ASK:
|
||||
case DEMOD_BI:
|
||||
case DEMOD_BIa:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
@ -2326,7 +2349,8 @@ static int try_detect_modulation(void) {
|
|||
|
||||
lf_modulation_t tests[6];
|
||||
int clk = 0, firstClockEdge = 0;
|
||||
uint8_t hits = 0, fc1 = 0, fc2 = 0, ans = 0;
|
||||
uint8_t hits = 0, ans = 0;
|
||||
uint8_t fc1 = 0, fc2 = 0;
|
||||
bool st = false;
|
||||
|
||||
ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, &firstClockEdge);
|
||||
|
@ -2335,11 +2359,15 @@ static int try_detect_modulation(void) {
|
|||
|
||||
if ((FSKrawDemod(0, 0, 0, 0, false) == PM3_SUCCESS)) {
|
||||
tests[hits].modulation = DEMOD_FSK;
|
||||
if (fc1 == 8 && fc2 == 5)
|
||||
if (fc1 == 8 && fc2 == 5) {
|
||||
tests[hits].modulation = DEMOD_FSK1a;
|
||||
else if (fc1 == 10 && fc2 == 8)
|
||||
} else if (fc1 == 10 && fc2 == 8) {
|
||||
tests[hits].modulation = DEMOD_FSK2;
|
||||
}
|
||||
|
||||
tests[hits].bitrate = clk;
|
||||
tests[hits].fc1 = fc1;
|
||||
tests[hits].fc2 = fc2;
|
||||
++hits;
|
||||
}
|
||||
|
||||
|
@ -2380,13 +2408,11 @@ static int try_detect_modulation(void) {
|
|||
}
|
||||
}
|
||||
clk = GetNrzClock("", false);
|
||||
if (clk > 8) { //clock of rf/8 is likely a false positive, so don't use it.
|
||||
if ((NRZrawDemod(0, 0, 1, false) == PM3_SUCCESS)) {
|
||||
tests[hits].modulation = DEMOD_NRZ;
|
||||
tests[hits].bitrate = clk;
|
||||
++hits;
|
||||
}
|
||||
}
|
||||
|
||||
clk = GetPskClock("", false);
|
||||
if (clk > 0) {
|
||||
|
@ -2398,6 +2424,9 @@ static int try_detect_modulation(void) {
|
|||
tests[hits].modulation = DEMOD_PSK1;
|
||||
tests[hits].bitrate = clk;
|
||||
++hits;
|
||||
|
||||
// get psk carrier
|
||||
tests[hits].carrier = GetPskCarrier(false);
|
||||
}
|
||||
//undo trim samples
|
||||
save_restoreGB(GRAPH_RESTORE);
|
||||
|
|
|
@ -190,12 +190,10 @@ int GetAskClock(const char *str, bool printAns) {
|
|||
return clock1;
|
||||
}
|
||||
|
||||
uint8_t GetPskCarrier(const char *str, bool printAns) {
|
||||
int GetPskCarrier(bool verbose) {
|
||||
if (getSignalProperties()->isnoise)
|
||||
return -1;
|
||||
|
||||
uint8_t carrier = 0;
|
||||
|
||||
uint8_t *bits = calloc(MAX_GRAPH_TRACE_LEN, sizeof(uint8_t));
|
||||
if (bits == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
|
@ -211,16 +209,18 @@ uint8_t GetPskCarrier(const char *str, bool printAns) {
|
|||
|
||||
uint16_t fc = countFC(bits, size, false);
|
||||
free(bits);
|
||||
carrier = fc & 0xFF;
|
||||
|
||||
uint8_t carrier = fc & 0xFF;
|
||||
if (carrier != 2 && carrier != 4 && carrier != 8) return 0;
|
||||
if ((fc >> 8) == 10 && carrier == 8) return 0;
|
||||
// Only print this message if we're not looping something
|
||||
if (printAns)
|
||||
if (verbose)
|
||||
PrintAndLogEx(SUCCESS, "Auto-detected PSK carrier rate: %d", carrier);
|
||||
|
||||
return carrier;
|
||||
}
|
||||
|
||||
int GetPskClock(const char *str, bool printAns) {
|
||||
int GetPskClock(const char *str, bool verbose) {
|
||||
|
||||
if (getSignalProperties()->isnoise)
|
||||
return -1;
|
||||
|
@ -251,14 +251,14 @@ int GetPskClock(const char *str, bool printAns) {
|
|||
setClockGrid(clock1, firstPhaseShiftLoc);
|
||||
|
||||
// Only print this message if we're not looping something
|
||||
if (printAns)
|
||||
if (verbose)
|
||||
PrintAndLogEx(SUCCESS, "Auto-detected clock rate: %d", clock1);
|
||||
|
||||
free(bits);
|
||||
return clock1;
|
||||
}
|
||||
|
||||
int GetNrzClock(const char *str, bool printAns) {
|
||||
int GetNrzClock(const char *str, bool verbose) {
|
||||
|
||||
if (getSignalProperties()->isnoise)
|
||||
return -1;
|
||||
|
@ -285,7 +285,7 @@ int GetNrzClock(const char *str, bool printAns) {
|
|||
clock1 = DetectNRZClock(bits, size, 0, &clkStartIdx);
|
||||
setClockGrid(clock1, clkStartIdx);
|
||||
// Only print this message if we're not looping something
|
||||
if (printAns)
|
||||
if (verbose)
|
||||
PrintAndLogEx(SUCCESS, "Auto-detected clock rate: %d", clock1);
|
||||
|
||||
free(bits);
|
||||
|
@ -294,7 +294,7 @@ int GetNrzClock(const char *str, bool printAns) {
|
|||
|
||||
//by marshmellow
|
||||
//attempt to detect the field clock and bit clock for FSK
|
||||
int GetFskClock(const char *str, bool printAns) {
|
||||
int GetFskClock(const char *str, bool verbose) {
|
||||
|
||||
int clock1 = param_get32ex(str, 0, 0, 10);
|
||||
if (clock1 != 0)
|
||||
|
@ -307,7 +307,7 @@ int GetFskClock(const char *str, bool printAns) {
|
|||
return 0;
|
||||
|
||||
if ((fc1 == 10 && fc2 == 8) || (fc1 == 8 && fc2 == 5)) {
|
||||
if (printAns)
|
||||
if (verbose)
|
||||
PrintAndLogEx(SUCCESS, "Detected Field Clocks: FC/%d, FC/%d - Bit Clock: RF/%d", fc1, fc2, rf1);
|
||||
|
||||
setClockGrid(rf1, firstClockEdge);
|
||||
|
|
|
@ -27,11 +27,11 @@ void convertGraphFromBitstream(void);
|
|||
void convertGraphFromBitstreamEx(int hi, int low);
|
||||
bool isGraphBitstream(void);
|
||||
|
||||
int GetAskClock(const char *str, bool printAns);
|
||||
int GetPskClock(const char *str, bool printAns);
|
||||
uint8_t GetPskCarrier(const char *str, bool printAns);
|
||||
int GetNrzClock(const char *str, bool printAns);
|
||||
int GetFskClock(const char *str, bool printAns);
|
||||
int GetAskClock(const char *str, bool verbose);
|
||||
int GetPskClock(const char *str, bool verbose);
|
||||
int GetPskCarrier(bool verbose);
|
||||
int GetNrzClock(const char *str, bool verbose);
|
||||
int GetFskClock(const char *str, bool verbose);
|
||||
bool fskClocks(uint8_t *fc1, uint8_t *fc2, uint8_t *rf1, int *firstClockEdge);
|
||||
|
||||
#define MAX_GRAPH_TRACE_LEN (40000 * 8)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue