Merge remote-tracking branch 'upstream/master' into hf_mf_sim

This commit is contained in:
vratiskol 2019-03-19 16:48:45 +01:00
commit 49f0b35ffd
6 changed files with 56 additions and 18 deletions

View file

@ -231,7 +231,7 @@ void HfSniff(int, int);
//felica.c
extern void felica_sendraw(UsbCommand *c);
extern void felica_sniff(uint32_t samples, uint32_t triggers);
extern void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip);
extern void felica_sim_lite(uint64_t uid);
extern void felica_dump_lite_s();

View file

@ -611,13 +611,13 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
#define R_READBLK_LEN 0x21
//simulate NFC Tag3 card - for now only poll response works
// second half (4 bytes) of NDEF2 goes into nfcid2_0, first into nfcid2_1
void felica_sim_lite(uint64_t nfcid) {
void felica_sim_lite(uint64_t uid) {
int i, curlen = 0;
uint8_t *curresp = 0;
uint8_t ndef[8];
num_to_bytes(nfcid, 8, ndef);
num_to_bytes(uid, 8, ndef);
//prepare our 3 responses...
uint8_t resp_poll0[R_POLL0_LEN] = { 0xb2, 0x4d, 0x12, FELICA_POLL_ACK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x43, 0x00, 0xb3, 0x7f};

View file

@ -458,7 +458,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
sscanf(Cmd, "%i %i %i %i %c", &clk, &invert, &maxErr, &maxLen, &amp);
if (!maxLen) maxLen = BIGBUF_SIZE;
if (invert != 0 && invert != 1) {
@ -485,14 +485,13 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
if (amp == 'a')
askAmp(bits, BitLen);
bool st = false;
size_t ststart = 0, stend = 0;
if (*stCheck)
st = DetectST(bits, &BitLen, &foundclk, &ststart, &stend);
// if (*stCheck)
bool st = DetectST(bits, &BitLen, &foundclk, &ststart, &stend);
clk = (clk == 0) ? foundclk : clk;
if (st) {
*stCheck = st;
clk = (clk == 0) ? foundclk : clk;
CursorCPos = ststart;
CursorDPos = stend;
if (verbose)
@ -1607,8 +1606,7 @@ int CmdLoad(const char *Cmd) {
break;
}
if (f)
fclose(f);
fclose(f);
PrintAndLogEx(SUCCESS, "loaded %d samples", GraphTraceLen);

View file

@ -113,8 +113,8 @@ char *mtostr(const model_t *model) {
+ strlen(strbuf)
+ (polystr && *polystr ? strlen(polystr) : 6)
+ (initstr && *initstr ? strlen(initstr) : 6)
+ (model->flags & P_REFIN ? 4 : 5)
+ (model->flags & P_REFOUT ? 4 : 5)
+ ((model->flags & P_REFIN) ? 4 : 5)
+ ((model->flags & P_REFOUT) ? 4 : 5)
+ (xorotstr && *xorotstr ? strlen(xorotstr) : 6)
+ (checkstr && *checkstr ? strlen(checkstr) : 6)
+ (magicstr && *magicstr ? strlen(magicstr) : 6)

View file

@ -1207,7 +1207,7 @@ prhex(char **spp, bmp_t bits, int flags, int bperhx) {
* Set P_UPPER in flags to write A-F in uppercase.
*/
static const char hex[] = "0123456789abcdef0123456789ABCDEF";
const int upper = (flags & P_UPPER ? 0x10 : 0);
const int upper = ((flags & P_UPPER) ? 0x10 : 0);
while (bperhx > 0) {
bperhx -= ((bperhx + 3) & 3) + 1;
*(*spp)++ = hex[(bits >> bperhx & BMP_C(0xf)) | upper];

View file

@ -480,12 +480,25 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo
size_t startwave;
size_t i = 100;
size_t minClk = 512;
int shortestWaveIdx = 0;
uint16_t shortestWaveIdx = 0;
// get to first full low to prime loop and skip incomplete first pulse
getNextHigh(dest, size, high, &i);
getNextLow(dest, size, low, &i);
// clock, numoftimes, first idx
uint16_t tmpclk[9][3] = {
{8, 0, 0},
{16, 0, 0},
{32, 0, 0},
{40, 0, 0},
{50, 0, 0},
{64, 0, 0},
{128, 0, 0},
{256, 0, 0},
{384, 0, 0},
};
// loop through all samples (well, we don't want to go out-of-bounds)
while (i < size - 512) {
// measure from low to low
@ -499,11 +512,38 @@ int DetectStrongAskClock(uint8_t *dest, size_t size, int high, int low, int *clo
minClk = i - startwave;
shortestWaveIdx = startwave;
}
int foo = getClosestClock(minClk);
if (foo > 0 ) {
for (uint8_t i = 0; i < 9; i++) {
if ( tmpclk[i][0] == foo ) {
tmpclk[i][1]++;
if ( tmpclk[i][2] == 0) {
tmpclk[i][2] = shortestWaveIdx;
}
break;
}
}
}
}
// set clock
if (g_debugMode == 2) prnt("DEBUG ASK: DetectStrongAskClock smallest wave: %d", minClk);
*clock = getClosestClock(minClk);
// find the clock with most hits and it the first index it was encountered.
int max = 0;
for (uint8_t i = 0; i < 9; i++) {
if (g_debugMode == 2) {
prnt("DEBUG, ASK, clocks %u | hits %u | idx %u"
, tmpclk[i][0]
, tmpclk[i][1]
, tmpclk[i][2]
);
}
if ( max < tmpclk[i][1] ) {
*clock = tmpclk[i][0];
shortestWaveIdx = tmpclk[i][2];
max = tmpclk[i][1];
}
}
if (*clock == 0)
return -1;