Compare commits

...

1677 commits

Author SHA1 Message Date
pwpiwi
6116334485
Merge pull request #969 from pwpiwi/gcc10_fixes
Gcc10 fixes
2021-03-30 08:59:58 +02:00
pwpiwi
cbecb8a209 gcc10 compiler fixes:
- Check for availability of getenv_s() in argtable3.c
2021-03-18 08:25:16 +01:00
pwpiwi
d3f8d76d6c Fix gcc10 compiler warnings
- update argtable3 to latest versions
2021-03-18 08:23:17 +01:00
pwpiwi
8ac5d5cba1 Fix gcc10 compiler warnings
- fix attribute format for MINGW in tinycbor/cbor.h
- add pragma to prevent "unaligned pointer" warning in cmddata.c. We know what we are doing there.
- whitespace fixes
2021-01-29 08:26:33 +01:00
pwpiwi
ad326d84ad Fix gcc 10 link issues
- avoid linker error by providing string.[ch] in bootrom
2021-01-28 09:00:08 +01:00
pwpiwi
555fa19773
Cleanup armsrc/string.c and string.h (#964)
- remove unnecessary memxor(), strreverse(), and itoa() functions
- Use correct types in function declarations and definitions
- add memmove() function. Gcc may generate calls to memcmp(), memcpy(), memset() and memmove()
2021-01-25 09:27:38 +01:00
pwpiwi
efd0327132
Avoid link error due to duplicate definition of blocknr in hitag.c and hitagS.c (#963) 2021-01-25 09:26:27 +01:00
pwpiwi
622dd1af3b
Merge pull request #938 from pwpiwi/fix_printf_scanf
Fix some printf/scanf format strings
2021-01-22 17:34:42 +01:00
Iceman
e6158a48ec
Update README.md
added link to Proxmark3 community discord server
2020-07-29 17:33:56 +02:00
pwpiwi
4b27ca5cf6
Merge pull request #943 from dgorbunov/patch-1
Compile Error: Add string.h to ui.c
2020-07-14 09:00:27 +02:00
Daniel Gorbunov
79d9ddc584
Add string.h
Failed to compile without this line on MacOS Big Sur Beta.
2020-07-12 10:13:15 -04:00
pwpiwi
98a67bc908 Fix some printf/scanf format strings 2020-05-11 14:46:22 +02:00
pwpiwi
ebf1404a81
Merge pull request #926 from pwpiwi/fix_iso15693_fpga
* make fpga_version_info.c phony and delete it on 'make clean'
* wait for transfer to complete before returning from FpgaSendCommand()
* log correct tag times in iclass simulation
* shorten pulse from TC1 to TC0 in StartCountSspClk()
* shorten ssp_frame pulse in fpga/hi_reader.v
* some reformatting and whitespace fixes
* NOISE_THRESHOLD /= 2 (starting with c41dd5f it became a relative threshold)
* remove superfluous reader initialization
2020-04-11 08:56:14 +02:00
pwpiwi
c85805b8a2
update CI/.travis.yml (#929)
* drop checks for MacOS 10.11 and 10.12
* add checks for Ubuntu 16.04 and 18.04
* add libnewlib-arm-none-eabi as prerequisite on Ubuntu
2020-04-09 09:19:25 +02:00
pwpiwi
852ecedc16
compatibility fix: get_clocktime() is not always available 2020-04-07 09:04:47 +02:00
pwpiwi
6792435739 fixing iso15693
* NOISE_THRESHOLD /= 2 (starting with c41dd5f it became a relative threshold)
* remove superfluous reader initialization
2020-04-03 17:42:38 +02:00
pwpiwi
f66d28afcc Merge branch 'master' into fix_iso15693_fpga 2020-03-31 08:55:35 +02:00
pwpiwi
7a53739728 fixing some fpga and iclass issues
* make fpga_version_info.c phony and delete it on 'make clean'
* wait for transfer to complete before returning from FpgaSendCommand()
* log correct tag times in iclass simulation
* shorten pulse from TC1 to TC0 in StartCountSspClk()
* shorten ssp_frame pulse in fpga/hi_reader.v
* some reformatting and whitespace fixes
2020-03-31 08:39:16 +02:00
pwpiwi
5bc3841ad1
fix 'hf mf perso' result feedback (#920) 2020-03-16 13:33:19 +01:00
pwpiwi
aa8ff592ae
add a specific check function for static nonces (used in 'hf mf nested') (#911)
* add a specific check function for static nonces in 'hf mf nested'
* uses a fixed nr_enc and does all the crypto operations on client
* for all possible keys calculate par_enc and ar_enc and send them to device
* CHANGELOG update
2020-03-16 13:32:00 +01:00
pwpiwi
bedae7768c
Merge pull request #913 from 0x2b3bfa0/patch-1
Fix #912: ukbhit() false positive
2020-02-13 08:37:17 +01:00
Helio Machado
8f831ceb0b Fix #912 2020-02-09 18:04:46 +01:00
pwpiwi
d6e1d48284
Merge pull request #910 from pwpiwi/small_USB_response
Improve USB communications
2020-02-06 21:49:15 +01:00
pwpiwi
df7b80fecc fix WaitForResponse (without timeout) 2020-02-06 07:59:18 +01:00
pwpiwi
01aa068b6f reenable intermediate "Waiting for a response from the proxmark..." message 2020-02-04 08:21:17 +01:00
pwpiwi
3458bb279b replace msleep() by thread signalling in comms.c 2020-01-27 14:55:40 -05:00
pwpiwi
d2ca5dbfe8 uart_posix.c rework
* added some LED handling in appmain.c (helped with debugging)
* finally replaced the infamous device unlink by msleep(1000)
* fixed some format strings in comms.c (with -DCOMMS_DEBUG)
* made uart_receive() and uart_send() behave as described in header
* some formating
2020-01-27 14:14:40 -05:00
pwpiwi
fd66752193 cleaning up uart_posix.c
* whitespace fixes
* sorting out #includes
2020-01-24 03:24:39 -05:00
pwpiwi
ac37ee816b Add missing includes 2020-01-23 17:02:33 -05:00
pwpiwi
929b61c670 Always enable fast response mode (was enabled for flasher only)
* ensure that CMD_ACK is used exclusively for the very last response of each PM3 operation. All Dbprintf() must be before.
* always switch off field before exiting
* append null packet for USB transfers % 64 bytes
* reformatting and whitespace fixes
2020-01-23 22:18:51 +01:00
pwpiwi
b8ed9975e5 modify USB communications
* use different data types for commands and responses
* use variable length responses
* maintain client/flasher compatibility with old format (e.g. when using old bootloader)
* maintain bootloader compatibility with old format (e.g. when using old or RRG flasher.exe)
* fix length of version string in appmain.c
2020-01-17 09:31:14 +01:00
pwpiwi
867e10a5fd usb communication (device side) refactoring
* merge cmd.c into usb_cdc.c
* move back usb_cdc.[ch] to common/
* declare low level functions usb_read() and usb_write() and more functions as static
* use cmd_receive() in bootrom.c and appmain.c
* remove unused memory wasting csrTab[100] in usb_cdc.c
* replace more byte_t by uint8_t
* more whitespace fixes
2020-01-15 18:49:28 +01:00
pwpiwi
72622d6429 usb communication (device side) housekeeping
* move cmd.[ch] and usb_cdc.[ch] to armsrc
* sorting out #includes
* replace byte_t by uint8_t
* some reformatting
* whitespace fixes
* (no functional changes)
2020-01-15 18:46:09 +01:00
pwpiwi
d00a30d56f
Merge pull request #909 from pwpiwi/fix_button_break
Fix "Sending bytes to proxmark failed" with BUTTON_PRESS()
2020-01-15 18:31:56 +01:00
pwpiwi
6b34699adc fix "Sending bytes to proxmark failed" after BUTTON_PRESS() 2020-01-10 08:45:45 +01:00
pwpiwi
1d04b933df appmain.c cleanup
* reformatting
* whitespace fixes
* replace byte_t by uint8_t
2020-01-10 08:21:07 +01:00
pwpiwi
a749b1e58b
speedup 'hf mf chk' (#901)
* add separate timeout for tag response to nr_ar
* measure response time and use it for response timeout
* don't drop field between keyblocks
* some reformatting
* some whitespace fixes
* fishing for microseconds in TransmitFor14443a()
* allow arbitrary number of keys in MifareChkKeys()
* and move progress printing to MifareChkKeys()

Co-authored-by: uzlonewolf <github_com@hacker-nin.com>
2020-01-09 15:42:31 +01:00
pwpiwi
f0c48553cb
fix hf search (#908)
* fix memory access violation in HF14B_Other_Reader()
2020-01-07 22:33:55 +01:00
pwpiwi
fef3084ec2
fix gcc8 compiler warnings on string overflows (#905) 2020-01-03 07:17:21 +01:00
pwpiwi
a4ff62be63
fix 'hf iclass writebl' and 'hf iclass clone' (#896)
* check for correct responses after block updates
* reduce number of tries from 10 to 3
* Allow to override warning on attempt to clone blocks < 5
* add same warning and override option to 'hf iclass writebl'
* some reformatting and minor refactoring
* Drop field after dump and clone functions
* If dumping AA1 with Credit Key, authenticate as Debit Key
* Initialize reader when beginning to clone
2019-12-28 17:03:20 +01:00
Phil
1d4b67cb3d "hf mf ekeyprn d" doesn't works properly (#904)
FIX: command "hf mf ekeyprn  d" doesn't use the correct offset to locate the A key in data[] array and record the 2 last bytes followed by 4 0x00 instead of the 6 good bytes (All the A keys are corrupted in file dumpkeys.bin). B keys are not affected.
2019-12-28 14:04:46 +01:00
uzlonewolf
5a03ea993f Nested loop fix for static nonces
* add detection of static tag nonces
* add tag nonce to error message
* modify mfCheckKeys() to pass button press events upstream
* don't abort nested when a static nonce is encountered
* modify nested to try multiple keys in a single operation
* Print keys remaining only every 10 seconds, and add estimated worst-case time
2019-12-23 16:08:23 +01:00
pwpiwi
1f4789fe53
fix 'hf 15 csetuid' (#890)
* fix 'hf 15 csetuid'
* check for error codes, prevent client crash
* some include file refactoring
* some whitespace fixes
* allow longer timeout for write commands
* add function to send EOF only
* modify 'hf list 15' to display "<EOF>"
* add tracing of Reader commands
* if REQ_OPTION is set on write commands, send separate EOF to request tag response
* use #defines instead of hex constants
* switch off field after UID update
* return last tag response (if there is any)
* iso15693: decode WRITE_MULTI_BLOCK in 'hf list 15'
2019-12-20 08:25:14 +01:00
pwpiwi
e73c9f1bd4
fix 'hf iclass chk' (#894)
* Check for Credidt Keys as well
* reduce authentication tries from 6 to 3
* correct text in 'hf iclass clone' for 'l' parameter
* some reformatting and whitespace fixes
2019-12-09 08:27:42 +01:00
grauerfuchs
763d1befc1 Bugfix: Output typing on print of HID card formats (#895)
* Bugfix: Output typing on print of HID card formats

The 'PrintAndLog' calls were using signed types and sometimes too few bits in width for formatting/outputting the data as was revealed in the forums. This commit will correct the printf-formatted output typing on display of the fields.

* Update hidcardformats.c

Updated to use macros as requested by @pwpiwi
2019-12-06 16:06:24 +01:00
pwpiwi
28ae37b746
fix 'hf iclass replay' (#888)
* implement option -n for authentication with replayed NR/MAC pairs in 'dump' and 'readbl'
* delete 'hf iclass replay'
2019-12-04 18:34:53 +01:00
pwpiwi
00848e096b
Hitag fixes (#887)
* don't display error message during 'lf search' when no Hitag tag is present
* remove superfluous options in 'lf hitag read'
* fix setting of default threshold when selecting FPGA_CMD_SET_EDGE_DETECT_THRESHOLD major mode
* some refactoring
2019-11-25 08:38:23 +01:00
pwpiwi
e938f71011
Merge pull request #884 from pwpiwi/fix_iclass_snoop
* determine and write meaningful times into trace
* code deduplication: use ISO15693 snoop function
* speed up SnoopIso15693(), reduce DMA buffer size
* add jamming option '-j' to 'hf iclass snoop'
* fix issue #882
* whitespace fixes
* make room for one more bit for FPGA minor mode
* new mode FPGA_HF_READER_MODE_SEND_JAM
* implement jamming in Handle15693SampleFromReader
2019-11-19 18:11:26 +01:00
pwpiwi
cd028159be implement 'hf iclass snoop -j'
* fix long option --jam
* make room for one more bit for FPGA minor mode
* new mode FPGA_HF_READER_MODE_SEND_JAM
* implement jamming in Handle15693SampleFromReader
2019-11-13 18:03:40 +01:00
pwpiwi
be09ea8603 fix 'hf iclass snoop'
* code deduplication: use ISO15693 snoop function
* speed up SnoopIso15693(), reduce DMA buffer size
* add jamming option '-j' to 'hf iclass snoop'
* fix issue #882
* whitespace fixes
2019-11-13 18:03:39 +01:00
pwpiwi
1ce689684f fix 'hf iclass snoop'
* 'hf 15 snoop': determine and write meaningful times into trace
2019-11-13 18:03:37 +01:00
pwpiwi
d3bcdbdabf
mod 'hf list' (#881)
* switch to argtable command line parsing (i.e. options must now be preceded by '-')
* add option '-r' to display relative times
* add option '-u' to display times in microseconds
* fix: graceful exit if trace is requested from offline PM3
2019-11-13 18:00:51 +01:00
pwpiwi
496bb4be33
fix 'hf iclass' (#879)
* add loooong timeout for UPDATE command
* add flags FLAG_ICLASS_READER_INIT and FLAG_ICLASS_READER_CLEARTRACE
* don't overwrite trace buffer during 'hf iclass dump'
* fix long waiting time when start_time==0 in TransmitTo15693Tag()
* remove some additional debug prints
* refactoring: move helper functions from protocols.c to cmdhficlass.c
* add 'h' and '1' options to 'hf iclass reader' (from RRG repository)
* use correct key when only CreditKey is given in 'hf iclass dump'
* separate select_and_auth
* DropField() on errors
* dump last block in 'hf iclass dump'
* display correct memory size (number of blocks) in 'hf iclass reader' and dump
* more whitespace fixes
2019-11-13 18:00:33 +01:00
pwpiwi
ea5e5d042e
fix 'hf 14b sriwrite' (#880) 2019-11-05 11:43:03 +01:00
pwpiwi
e55b441992
Merge pull request #876 from pwpiwi/fix_iclass_reader
fix 'hf iclass reader'
* code deduplication. Use functions from iso15693.c
* speedup CodeIso15693AsReader()
* invert reader command coding. 0 now means 'unmodulated' ( = field on)
* decode SOF only as a valid tag response in Handle15693SamplesFromTag()
* complete decoding of EOF in Handle15693SamplesFromTag()
* determine and write correct times to trace
* FPGA-change: generate shorter frame signal to allow proper sync in StartCountSspClk()
* modify StartCountSspClk() for 16bit SSC transfers
* whitespace in util.c
* add specific LogTrace_ISO15693() with scaled down duration. Modify cmdhflist.c accordingly.
* allow 'hf 15 raw' with single byte commands
* check for buffer overflow, card timeout and single SOF in 'hf 15 raw'
* decode and handle SOF only responses in Handle14443bSamplesDemod()
* allow 1 byte commands with 'hf 14b raw'
* don't do READCHECK when not trying to authenticate
* standard LED handling
* remove unused FLAG_ICLASS_READER_ONLY_ONCE and FLAG_ICLASS_READER_ONE_TRY
* sanity check for negative times in TransmitTo15693Tag()
* increase reader timeout for 'hf 15' functions to be enough for slot 7 answers to ACTALL
* add 'hf iclass permute' inspired by RRG repository
* whitespace in cmdhficlass.c
2019-10-30 18:55:13 +01:00
pwpiwi
ece38ef311 fix 'hf iclass reader' and 'hf iclass readblk'
* don't do READCHECK when not trying to authenticate
* standard LED handling
* remove unused FLAG_ICLASS_READER_ONLY_ONCE and FLAG_ICLASS_READER_ONE_TRY
* sanity check for negative times in TransmitTo15693Tag()
* increase reader timeout for 'hf 15' functions to be enough for slot 7 answers to ACTALL
* add 'hf iclass permute' inspired by RRG repository
* whitespace fixes
2019-10-27 17:32:22 +01:00
pwpiwi
a3bef9863b iso14443b: trying to approach iClass
* decode and handle SOF only responses in Handle14443bSamplesDemod()
* allow 1 byte commands with 'hf 14b raw'
2019-10-23 09:09:13 +02:00
pwpiwi
a334de73d2 'hf 14b' formatting
* renaming a few functions
* whitespace
* moving a bit towards RRG repo
2019-10-22 21:02:02 +02:00
pwpiwi
c41dd5f9f6 fix 'hf iclass reader'
* code deduplication. Use functions from iso15693.c
* speedup CodeIso15693AsReader()
* invert reader command coding. 0 now means 'unmodulated' ( = field on)
* decode SOF only as a valid tag response in Handle15693SamplesFromTag()
* complete decoding of EOF in Handle15693SamplesFromTag()
* determine and write correct times to trace
* FPGA-change: generate shorter frame signal to allow proper sync in StartCountSspClk()
* modify StartCountSspClk() for 16bit SSC transfers
* whitespace in util.c
* add specific LogTrace_ISO15693() with scaled down duration. Modify cmdhflist.c accordingly.
* allow 'hf 15 raw' with single byte commands
* check for buffer overflow, card timeout and single SOF in 'hf 15 raw'
2019-10-21 21:48:08 +02:00
pwpiwi
b41be3cb11
Merge pull request #862 from pwpiwi/fix_iclass_sim
fix hf iclass sim:
* sim 2: add responses to read(1) (Config) and read(5) (AIA)
* sim 2/3: don't restrict CC to 00 bytes only
* sim 3: add responding to read block commands
* sim 2/3: add responding to READ_CHECK_KC
* fix sizes of pre-encoded tag answers
* sim 2: change default card challenge
* remove commented code
* use #defines instead of numerical constants for simulation modes
* some reformatting and whitespace fixes
* fix debug print on unhandled commands
* deduplicate: use sim functions from iso15693.c
* fix times in tracelog and 'hf list iclass' (sim only)
* don't check parity in 'hf list iclass'
* fix timing in TransmitTo15693Reader()
* add simulation of block 3 and 4 (Kd and Kc) reads
* add simulation of READ4 (4 blocks read)
* FPGA change (hi_simulate.v): avoid spp_clk phase changes
* chg to reader command decoder in iso15693.c (require no modulation before SOF)
* add 'has_been_low_for' logic to hi_simulate.v (same as in other FPGA modes, default to "no modulation")
* add simulation of chip status (IDLE, ACTIVE, SELECTED, HALTED)
* check ACSN on SELECT
* add simulation of RESELECT
* always check length of reader commands
* fix printing of NR, MAC in sim 2 mode
* fix response length to CHECK command
* implement UPDATE and CHECK[Kc]
* add simulation of multiple pages (PAGESEL by @sherhannn9)
* maintain cipher states per page
* update cipher state after UPDATE commands (@sherhannn9)
* add simulation of personalization mode
* respond with SOF on HALT
* display "\<SOF\>" instead of "0f" in 'hf list iclass'
* standard LED handling
* speedup CodeIso15693AsTag()
* TransmitTo15693Tag(): don't send unmodulated start of SOF
* reduce modulation depth in hi_simulate.v
2019-10-21 21:25:44 +02:00
Iceman
3fb6e1fa40
Merge pull request #873 from quantum-x/patch-2
Update README.md
2019-10-08 14:47:17 +02:00
quantum-x
5eacacfd9a
Update README.md
Updated as per PR discussion thead
2019-10-08 14:40:11 +02:00
quantum-x
a534629505
Update README.md
Updated reference to Lab401 as an EU reseller, not a HK reseller.
2019-10-08 13:24:25 +02:00
pwpiwi
f31b4cd888 Merge branch 'master' into fix_iclass_sim 2019-10-08 11:54:22 +02:00
pwpiwi
f784539dfb
fix iclass reader functions
* remove unused CMD_ICLASS_READCHECK
* fix wrong command coding in CodeIClassCommand()
* switch field off at end of commands to avoid RDV4 overheating
2019-10-08 11:48:49 +02:00
pwpiwi
8efd0b80f2 fix 'hf iclass sim'
* fix tag response timing. iClass differs from ISO15693 in this respect.
* speedup CodeIso15693AsTag()
* TransmitTo15693Tag(): don't send unmodulated start of SOF
* reduce modulation depth in hi_simulate.v
* calculate CRC for configuration block when simulating
* Show real response time instead of planned response time in 'hf list iclass'
2019-10-08 11:04:30 +02:00
pwpiwi
ae60ceca92 fix 'hf iclass sim'
* add simulation of multiple pages (PAGESEL by @sherhannn9)
* maintain cipher states per page
* update cipher state after UPDATE commands (@sherhannn9)
* add simulation of personalization mode
* respond with SOF on HALT
* display "<SOF>" instead of "0f" in 'hf list iclass'
* standard LED handling
2019-10-02 08:20:17 +02:00
pwpiwi
26d0156a46
fix 'hf iclass eload' (thanks to @sherhannn79) 2019-09-30 07:29:20 +01:00
pwpiwi
8ddb81a217 fix 'hf iclass sim':
* implement CHECK[Kc] based on @sherhannn79
* implement UPDATE based on @sherhannn79
2019-09-25 18:40:05 +02:00
pwpiwi
e49d31c0e7 fix 'hf iclass sim':
* ignore standard iso15693 INVENTORY commands silently
* make iso15693 command decoder more strict (prevent decoding rubbish)
* re-enable sim 3
2019-09-25 14:24:36 +02:00
pwpiwi
1963cc9fe0 Merge branch 'master' into fix_iclass_sim 2019-09-24 19:34:05 +02:00
pwpiwi
5b12974a7f fix 'hf iclass sim':
* chg to reader command decoder in iso15693.c (require no modulation before SOF)
* add 'has_been_low_for' logic to hi_simulate.v (same as in other FPGA modes, default to "no modulation")
* add simulation of chip status (IDLE, ACTIVE, SELECTED, HALTED)
* check ACSN on SELECT
* add simulation of RESELECT
* always check length of reader commands
* fix printing of NR, MAC in sim 2 mode
* fix response length to CHECK command
2019-09-24 19:23:21 +02:00
pwpiwi
70dbfc3fc7
fix compile issue with gcc 9.1.0 (issue #868) 2019-09-21 13:56:01 +01:00
pwpiwi
d8ecc98a8e
'hf iclass loclass': fix error handling (#865)
* fix handling of "BEING_CRACKED" flag
* don't try to calculate KCus when some bytes couldn't be brute forced
* whitespace fixes
2019-09-12 09:21:10 +02:00
pwpiwi
a66f26da18 fix 'hf iclass sim':
* add simulation of block 3 and 4 reads
* add simulation of READ4 (4 blocks read)
* fixing TransmitTo15693Reader()  (again)
* FPGA change (hi_simulate.v): avoid spp_clk phase changes
* some whitespace fixes
2019-09-11 07:54:56 +02:00
pwpiwi
3d2c9c9b06 fix 'hf iclass sim'
* fix debug print on unhandled commands
* deduplicate: use sim functions from iso15693.c
* fix times in tracelog and 'hf list iclass' (sim only)
* don't check parity in 'hf list iclass'
* fix timing in TransmitTo15693Reader()
2019-09-10 08:42:59 +02:00
pwpiwi
0ab9002f36 fix hf iclass sim
* sim 2: add responses to read(1) (Config) and read(5) (AIA)
* sim 2/3: don't restrict CC to 00 bytes only
* sim 3: add responding to read block commands
* sim 2/3: add responding to READ_CHECK_KC
* fix sizes of pre-encoded tag answers
* change default card challenge
* remove commented code
* use #defines instead of numerical constants for simulation modes
* some reformatting
2019-08-31 17:53:14 +02:00
pwpiwi
8b2dd94e88
Merge pull request #861 from pwpiwi/iclass_MAC_speedup
iClass MAC calculation speedup (optimized_cipher.c)
2019-08-30 17:14:26 +02:00
pwpiwi
deb965b54d add iclass.h 2019-08-25 14:03:11 +02:00
pwpiwi
a1ff338bd5 Merge branch 'master' into iclass_MAC_speedup 2019-08-24 18:27:01 +02:00
pwpiwi
1477ba8a3c iclass.c: speeding up MAC calculation 2019-08-24 18:21:01 +02:00
pwpiwi
f2dbf3d2aa
'lf hitag writer': add Hitag2 password auth
* (PRs 233, 303, 304 by @ViRb3 on https://github.com/RfidResearchGroup/proxmark3)
* replace byte_t by uint8_t
* note that Hitag1 commands are not yet available
* whitespace fixes
* #define Hitag2 commands
* whitespace
* add EOF wait time
* add powerup wait time
2019-08-22 07:54:55 +02:00
pwpiwi
0b4efbdef2
add: 'hf mf personalize' (personalize UID on Mifare Classic EV1 7byte UID cards)
* add/use some #defines
* whitespace fixes
* #include refactoring
* add line to CHANGELOG.md
2019-08-22 07:53:17 +02:00
Samuele
cfa9c98d57 PCF7931: Print found single/consecutive block(s), fixes to block 1 check 2019-08-22 07:51:46 +02:00
pwpiwi
17505ce2a7 cleaning up iclass.c and optimized_cipher.c
* add iclass.h
* reformatting
* whitespace fixes
* (no functional changes)
2019-08-22 07:44:02 +02:00
pwpiwi
f98702bace
chg 'hf mf chk':
* don't repeatedly clear trace while running (PR 243 by @mceloff from https://github.com/RfidResearchGroup/proxmark3)
* standard LED handling
* better check for key file syntax
* get rid of "res" column when printing the result. Show unknown keys more prominent as "     ?     "
2019-08-10 23:30:47 +02:00
pwpiwi
5a446cb212
'hf 14a apdu' improvement
(PR 249 by @merlokk on https://github.com/RfidResearchGroup/proxmark3)
* add option to print APDU (if it can be decoded)
* add option to cconstruct extended and normal size APDUs
2019-08-01 11:01:56 -04:00
pwpiwi
ca24170fd4
fix emv search behavior
(taken from PRs 261 and 262 by @merlokk on https://github.com/RfidResearchGroup/proxmark3)
+ whitespace fixes
2019-08-01 10:58:22 -04:00
pwpiwi
faa35ae029
fix 'hf mf sim': access conditions to write Key B were not decoded correctly
(from PR 279 https://github.com/RfidResearchGroup/proxmark3)
2019-08-01 10:55:47 -04:00
pwpiwi
3a5ffba7c1
Implement Originality Signature Check in 'hf mfu info'
* add support for elliptic curve 'secp128r1' to mbedtls library
* change ecdsa_signature_verify() to allow different curves, signature lengths, and skipping hash
* add another public key for Mifare Ultralight EV1
2019-08-01 10:53:26 -04:00
mwalker33
88b3dada70 Fix Issue #843 - hf mf chk - t Doesnt save to emulator memory 2019-07-23 20:47:29 +02:00
t0m4
096dee1784 Add 'hf 15 csetuid' command to set UID on ISO15693 Magic tags (#842) 2019-07-14 12:31:33 +02:00
marshmellow42
817611f565 update em4x05 timing (#846)
See @mwalker33 issue #838
2019-07-11 20:31:51 +02:00
marshmellow42
4d8a07c829
Merge pull request #837 from mwalker33/master
lf t55xx downlink modes support added
2019-07-11 13:17:36 -04:00
jmorsch
347efc1274 whitespace cleaning 2019-07-11 13:01:36 -04:00
mwalker33
bdc9779645 Update lfops.c
boundary length check
2019-07-07 05:00:08 +10:00
mwalker33
dcd936a1da Update lfops.c
Fixed lf t55 reset
2019-07-06 15:20:25 +10:00
mwalker33
d7569065cb Code tidy
removed commented code
2019-07-03 19:58:49 +10:00
mwalker33
28597bb6c7 Update lfops.c
moved wakeup and reset to call T55xx_SendCMD.  Small code improvements
2019-06-27 16:57:28 +10:00
mwalker33
7db36608a2 Code improved for less memory 2019-06-26 11:34:31 +10:00
pwpiwi
59f75a7895
Update CHANGELOG.md 2019-06-25 18:37:25 +02:00
mwalker33
2994ab10d6 Update CHANGELOG.md 2019-06-25 20:52:29 +10:00
mwalker33
5a9964829e Resolved Conflicts 2019-06-25 20:46:10 +10:00
mwalker33
50764caadc Update lfops.c 2019-06-25 19:28:06 +10:00
mwalker33
644493821c
Merge branch 'master' into master 2019-06-25 19:01:13 +10:00
mwalker33
e220fc63aa Update lfops.c 2019-06-25 18:56:32 +10:00
pwpiwi
d3521ae609
Update CHANGELOG.md 2019-06-24 08:42:57 +02:00
mwalker33
99c52f9d85 Update CHANGELOG.md
Change Log Update
2019-06-23 22:23:08 +10:00
marshmellow42
2de26056ce add lf em 4x05protect plus lf config s option (#833)
* add "samples to skip" for lf config (mainly for lf snoop)
* add lf em 4x05protect command to write protection on em4x05 chips
* fix spacing
* and remove old comment git added back in..
* update changelog
* fix flags - only need 1 bit
2019-06-23 13:43:55 +02:00
mwalker33
4be71814b4 T55xx Downlink - Updates
Improved code.
2019-06-22 15:26:56 +10:00
mwalker33
6763dc17a3 Cleanup Code
Update downlink option from e to r
fixed long leading reference
added downling option to original bruteforce
2019-06-18 21:17:12 +10:00
mwalker33
be1b97d81f Update cmdlft55xx.c
Fixed bruteforce filename
2019-06-17 22:01:25 +10:00
mwalker33
6dd0ff3035 Update cmdlft55xx.c
Minor Cleanup
2019-06-17 21:37:50 +10:00
mwalker33
dd8e451330 T55xx downlink Modes
Changes :
- Added t55xx downlink protocols (long leading reference, leading 0 and 1 of 4)
- Added function to all read to call differnet downlink functions (to match write)
- Update functions to support using differnet downlink modes.
- Added support for calling downlink modes for lf t55 read, write and detect
- Added new function lf t55 bruteforcedl to support downlink modes as well as try each mode
	for each password in password file.

for functions with downlink mode extenstion.

 e <mode>     - OPTIONAL downlink encoding '0' fixed-bit-length (default),
					   '1' Long Zero Reference,
					   '2' Leading Zero,
					   '3' 1 of 4
2019-06-16 15:35:10 +10:00
pwpiwi
b8dd1ef649
upgrading 'hf mfu' (#830)
* chg: write new dump file format by @mceloff
* chg: rename 'hf mfu dump' option 'n' to 'f' to align with other commands and RRG repo
* chg: replace ISO14443A_CMD_READBLOCK by MIFARE_CMD_READBLOCK, same for WRITEBLOCK
* fix: mifare_ultra_readblock() returned 14 bytes instead of 16
* chg: param_gethex_ex() now checks maximum output buffer length
* chg: ul_comp_write() was incomplete and for magic testing only
* fix: 16bit ULC counter had been displayed as 32bit
* chg: add check for 7 Byte UID, drop check for ATQA in type identification GetHF14AMfU_Type()
* fix: send HALT instead of dropping field in order to maintain a defined state
* chg: DropField() when command ends
* chg: check for invalid page ranges in 'hf mfu dump'
* fix: print correct lock bits when page range is used
* fix: do not write (incomplete) dumpfile when page range is used
* add: use UID for filename when no filename is given (RRG repo)
* chg: don't clear trace on each ULC authentication, clear trace at beginning of each command
* fix: don't send (DESFire?) deselect command after authentication
2019-06-06 07:33:12 +02:00
Vladimir Serbinenko
d38bb3acc3 Specify that we need TCP and not UDP connection (#828) 2019-05-29 18:57:17 +02:00
pwpiwi
caaa4293ad
fix 'lf pcf7931 bruteforce' (bug reported in http://www.proxmark.org/forum/viewtopic.php?id=6490) (#824)
(and whitespace fixes)
2019-05-28 07:50:58 +02:00
pwpiwi
4be9f36ebe
start updating 'hf mfu' commands (#818)
* use PrintAndLogEx()
* fix some printouts
* some #include refactoring
* whitespace
2019-05-28 07:48:55 +02:00
pwpiwi
5f18b0c45d
add: Home (Pos1) and End key bindings in graph GUI (based on @mcd1992 change on RRG repo) (#823) 2019-05-27 07:58:09 +02:00
pwpiwi
2378bb24c3
fix compiler warning in cmdhflegic.c (and whitespace fixes) (#826) 2019-05-27 07:57:40 +02:00
pwpiwi
a39af1cb9c
Add: new option 'd' in 'hf mf ekeyprn' to create dumpkeys.bin from emulator memory (#822)
(and whitespace fixes)
2019-05-22 19:02:58 +02:00
Iceman
9ebbfd898c
Update README.md 2019-04-22 18:25:52 +02:00
marshmellow42
905d2975dc
Merge pull request #817 from Fl0-0/Fix_typo_cmdlf
Fix typo lf config usage
2019-04-19 07:31:54 -04:00
Fl0-0
131c44883c
Fix typo lf config usage 2019-04-19 13:14:41 +02:00
pwpiwi
a8561e356b
fix hf mf sim (#812)
* fix parity encryption (thanks to Eloff, http://www.proxmark.org/forum/viewtopic.php?id=6347)
* add support to simulate Mifare Mini, Mifare 2K and Mifare 4K
* change to standard LED handling (A: PM is working, B: reader is sending, C: tag is responding, D: HF field is on)
* NAK on unknown commands
* allow unencrypted HALT
* don't display messages during simulation (or we will miss next reader command)
* use DMA to receive reader command
* switch earlier from send to listen mode
* move ADC initializer to iso14443_setup
* remove remainders of incomplete Mifare 10Byte UID simulation
* show 'short' bytes (7Bits or 8Bits without parity) in 'hf list mf' and 'hf list 14a'
* whitespace
2019-04-19 10:22:10 +02:00
András Veres-Szentkirályi
bad582468f Added support for Legic tags to hf search command (#815)
* hf legic: use CMD_ACK instead of Dbprintf
* hf search: add support for Legic tags
2019-04-12 08:52:18 +02:00
marshmellow42
1f61f19767
Merge pull request #808 from MalteHillmann/master
Fixed bugs for FDX-B demod
2019-03-28 19:15:44 -04:00
Malte F. Hillmann
3f306c6ded Bugfixes for LF FDX
Changed CmdBiphaseDecodeRaw to allow 7 digits
Changed CmdFdxRead to read 39999 samples instead of 10000 to improve reading from small tags
2019-03-28 22:40:29 +01:00
Malte F. Hillmann
4306de8277 fixed bug in CmdFdxDemod 2019-03-27 14:36:39 +01:00
Malte F. Hillmann
7361a18f7a fixed bug in ASKbiphaseDemod() 2019-03-27 14:34:42 +01:00
Malte F. Hillmann
9c1d59ce69 fixed bug in CmdBiphaseDecodeRaw() 2019-03-27 14:04:01 +01:00
pwpiwi
ba778bc3c4
fix FpgaSetupSsc() (#807)
* ouch! Be aware that same major modes are used in LF and HF!
2019-03-26 21:50:41 +01:00
pwpiwi
5ea2a24839
FPGA changes (#803)
* merge hf_rx_xcorr and hf_tx modes into one module with common ssp_clk and ssp_frame
* get rid of most of the warnings when compiling the HF verilog sources
* refactoring the constants in Verilog sources
2019-03-24 18:11:41 +01:00
pwpiwi
ca8a3478d9
iso14443b modifications (#804)
* LED handling
* improve 'hf plot' support
2019-03-24 18:04:42 +01:00
Oleg Moiseenko
fdd9395d1a Ndef and MAD (#801)
* move mifare stuff to separate folder
* add mad and ndef
2019-03-19 07:51:10 +01:00
Samson Gama
3d057cfb91 Added some LED utility functions (#802) 2019-03-15 07:41:07 +01:00
pwpiwi
5866c187ef
fix hitag functions (issue #798) (#800)
* ... and whitespace formating
2019-03-13 10:53:40 +01:00
pwpiwi
1523527f94
fix LED signalling in hf 15 snoop and hf 14a snoop (#797)
* LED_A (yellow): PM3 is active (snooping)
* LED_B (green): reader is sending a command
* LED_C (red): tag is sending a reply
2019-03-12 07:49:23 +01:00
pwpiwi
189b817740
add 14a apdu send framing (based on RRG repo PR86 by Merlokk) (#795) 2019-03-12 07:46:49 +01:00
pwpiwi
1338d245c2
chip manufacturer and type identification: (#796)
* add more manufacturers
* refactor chipID decoding
* move to separate file taginfo.[ch]
2019-03-03 11:59:38 +01:00
pwpiwi
b6851c194e
fix ATR length (#790)
* TS, T0, T[A-D][1-4], max. 15 HB, TCK = 34 Bytes
2019-02-26 19:48:25 +01:00
Oleg Moiseenko
0b6efd01ec Emv scan via contact interface (#789)
* share getATR from smartcard.h/c
* remove duplicates in tlv.h and add get_uint_8
* check ATS/ATR length
2019-02-21 22:02:22 +01:00
pwpiwi
fc52fbd42f
Add raw HF signal plotting (#786)
* Add raw HF signal plotting
* new fpga module hi_get_trace.v - store A/D converter output to circular buffer on FPGA
* new command 'hf plot' - pull data from FPGA and display it in Graph Window
2019-02-20 19:18:12 +01:00
Oleg Moiseenko
7527c2bdd8 fix rare bug in tlv.c (#788) 2019-02-20 18:35:39 +01:00
Fl0-0
7afa751a96 Fix for USB uart slowness since PR #720 (#787) 2019-02-17 14:43:40 +01:00
pwpiwi
53fb848a0a
add tracing functions (#784)
* add trace buffer for PCSC smartcard readers
* new option 'p' in 'hf list' to select PCSC trace buffer
* 'sc list' now supports PCSC smartcard readers
* add 'hf list 14-4' for ISO 14443-4 protocol
2019-02-16 17:51:04 +01:00
pwpiwi
3783c45af1
fix emv roca hash error (#781)
* fix ICC Public Key Hash calculation
* add -a option to 'emv roca'
* replace print() by PrintAndLogEx() in emv_pki.c
2019-02-12 09:06:30 +01:00
Oleg Moiseenko
c719d385ef fix endless loop (#782) 2019-02-09 22:38:09 +01:00
pwpiwi
41bdfce385
emv/sc fixes and modifications: (#780)
* print selected Smartcard Reader in PrintChannel()
* implement 'sc sel <readername>'. Readername can include wildcards * and ?
* fixing EMV APDU exchange (again)
* use EMVExchangeEx() instead of EMVExchange() in fidocore.c
2019-02-09 15:15:17 +01:00
pwpiwi
fbf77474f5
Update list of Certificate Authorities Public Keys (source: https://www.eftlab.co.uk/index.php/site-map/knowledge-base/243-ca-public-keys) (#777)
* allow tabs in client/emv/capk.txt
* fix issue with printing RID and CSN of certificates
2019-02-06 07:51:49 +01:00
pwpiwi
4cdd63b245
EVM fixes and additions (RRG repository PRs 78-82 by @merlokk) (#776) 2019-02-06 07:50:57 +01:00
Oleg Moiseenko
fb27c73313 added SoloKey certificate (#778) 2019-02-04 19:53:04 +01:00
Oleg Moiseenko
3962dce565 fido fix (#775) 2019-02-04 08:03:44 +01:00
pwpiwi
97096af62b
Update list of known EMV AIDs. Source: https://www.eftlab.co.uk/index.php/site-map/knowledge-base/211-emv-aid-rid-pix (#770) 2019-02-01 21:13:00 +01:00
pwpiwi
6b5105bea9
Adding support for standard USB Smartcard Readers (#769)
* add PCSC reader support to 'sc raw' and all 'emv' commands
* move all APDU -> TPDU mapping to ExchangeAPDUSC()
* print "PSE" instead of "PPSE" when using contact interface
* fix some #defines in protocols.h
* DropField only when using contactless
* some refactoring
2019-02-01 21:12:20 +01:00
AntiCat
437035a75b Legic TagSim: increased reader timeout (#771)
Bug reports from @raphCode and @uhei over at the
RfidResearchGroup have shown that the tag to rwd
timeout is too short.
2019-01-30 22:20:57 +01:00
pwpiwi
a9104f7e31
Add support for standard USB Smartcard Readers (#765)
* add PCSC interface (pcsc.c and pcsc.h)
* new command 'sc select' to choose an USB Smartcard Reader
* updated CI/.travis.yml accordingly
* remove TCK CRC check in i2c.c It is done in PrintATR() anyway
* Fix TCK CRC check in PrintATR()
* Add PCSC reader support to 'sc info'
2019-01-28 21:54:34 +01:00
pwpiwi
1511ea28a8
Add ROCA vulnerability test (RRG repository PR 76 by @merlokk) (#762) 2019-01-21 19:26:54 +01:00
Fl0-0
d3c606574f restore #755 reverted after #757 (#761) 2019-01-17 09:13:38 +01:00
pwpiwi
151a33c027
Add smartcard protocol T=0 (RRG repository PRs 71,72,74,75 by @merlokk) (#757) 2019-01-17 07:50:01 +01:00
pwpiwi
0d2624a0cc
Add hf list 15 (#754)
and refactoring: move all of hf list code to cmdhflist.c
2019-01-16 09:54:19 +01:00
Fl0-0
c0e7527ddd Increase threshold to 160, fix for issue 756 (#760) 2019-01-16 09:52:20 +01:00
Michael Farrell
4309ef8fee Allow skipping or trying different keys in hf mf dump (#759) 2019-01-16 09:51:55 +01:00
pwpiwi
d04516a652
adjust CI testscript for new emv commands (#758) 2019-01-16 09:40:35 +01:00
Fl0-0
e59481c119 Fix CmdSmartUpgrade GCC8 strncpy specified bound depends on the length of the source argument warning (#755) 2019-01-13 16:53:09 +01:00
pwpiwi
d9de20fa4b
Fix 15 snoop (#752)
* fixing hf 15: implement hf 15 snoop
* rename hf 15 record to hf 15 snoop
* speedup sampling / decoding:
*   new FPGA mode FPGA_HF_READER_RX_XCORR_AMPLITUDE implements amplitude(ci, cq) on FPGA
*   inlining the decoders in iso15693.c
*   inlining memcpy/memset in LogTrace()
*   giving up the moving correlator for SOF in Handle15693SamplesFromTag
* decode more of EOF in Handle15693SamplesFromTag()
* some refactoring
2019-01-12 13:28:26 +01:00
pwpiwi
9f596ec7ac
RDV4.0 Smartcard Slot Firmware Upgrade (#751)
* RDV4.0 Smartcard Slot Firmware Upgrade
* new firmware in client/sc_upgrade_firmware directory
* improved sc upgrade:
   * check SHA-512 of firmware file
   * search and find firmware file in predefined directory
   * more sanity checks
* fixed offline indicators of sc commands
2019-01-12 13:26:53 +01:00
pwpiwi
6b6c3be6b9
Added ATR decoding (RfidResearchGroup PRs 67/68 by @merlokk) (#749)
... and fixed merge errors in cmdsmartcard.c
2019-01-12 13:24:22 +01:00
Fl0-0
786ad91c85 Fix CMD_PCF7931_BRUTEFORCE duplicate case value (#750) 2019-01-07 08:55:04 +01:00
Samuele
818e15b0c8 PCF7931: improved read code and implemented a simple password bruteforce (#745)
* Improved PCF 7931 read code and implemented a simple PCF7931 password bruteforce
* Warning on the PCF7931 bruteforce command
2019-01-06 18:33:06 +01:00
Fl0-0
5a28b51036 Fix PrintAndLogEx ERR (#748) 2019-01-05 18:41:51 +01:00
☃ Stephen Shkardoon ☃
5f84531b82 Paradox clone functionality implemented (#747)
This involves a refactor to the arm HID code to allow for arbitrary
preambles (such as HID Proximity and Paradox).
The client also borrows from the HID code, but is not shared, so could
use a significant refactor in the future.
2019-01-05 09:48:59 +01:00
pwpiwi
8d7d7b6187
Emv commands work with smartcard interface (RfidResearchGroup PR67 by @Merlokk) (#743)
* replace 'hf emv' commands by 'emv' commands
* Enable smartcard commands by default (-DWITH_SMARTCARD)
* update i2c.c from RfidResearchGroup repository
* update smartcard.c from RfidResearchGroup repository
2019-01-05 09:47:12 +01:00
pwpiwi
968ad67280
avoid compiler warning in client/cliparser/argtable3.c (#746) 2019-01-04 08:53:30 +01:00
Oleg Moiseenko
0d5545cee0 delete travis. it plaed in folder CI (#736) 2018-12-07 18:55:35 +01:00
Oleg Moiseenko
0bb514502a Fido2 (#727)
* add tinycbor
* add client/fido
* add test file with options for fido2
* hf fido commands
* add changelog
2018-12-07 16:42:37 +01:00
ralik
27d06e0447 Update default_pwd.dic (#735) 2018-12-07 14:10:08 +01:00
Fl0-0
daccbcdc8d Added mifare trailer block decoding for sector commands (#734) 2018-12-07 14:09:41 +01:00
pwpiwi
aa0b1c431f
Change mbedtls initializers to be compatible with older versions of gcc (#732)
* fix issue #731
2018-12-06 07:53:25 +01:00
Jean-Michel Picod
a015ef3733 Fix compilation error on OS X (#730) 2018-12-04 08:12:05 +01:00
Vladimir Serbinenko
d664113aee Support TCP ports for proxmark (#720)
On ChromeOS Linux apps can't access serial port but they can connect to TCP,
so I wrote a simple app to forward TCP to serial. I suppose this can
have other uses as well.
2018-12-03 08:53:26 +01:00
Oleg Moiseenko
ac4ecfe353 added mifare trailer block decoding (#726) 2018-12-03 08:29:13 +01:00
florianrock
383f4e2479 Update hitagS.c (#729)
Bugfix for #605 - wrong compare for tag.LKP
2018-12-03 08:23:53 +01:00
Fl0-0
9c87879e36 Fix public key lenght to 65 bytes (#725) 2018-11-30 18:44:52 +01:00
florianrock
7b6e320533 HitagS Improvements (#721)
* support of HITAG S standard communication mode
* fixed wrong AC (Anti Collision) decoding
* support of block read mode
* fixed wrong uid send when using simulation
* support of communication mode parameter  (client is backward compatible)
* support of start-page parameter (important for some weird tags) (client is backward compatible)
* also expect pages if tag memory size in con0 is 11 (we got some tags)
* corrected hitagS reader cmd help
2018-11-30 17:42:22 +01:00
Fl0-0
994f21fe01 Fix format-truncation warning, missing string.h inclusion and strnlen warning (#723)
* Fix format-truncation warning, missing string.h inclusion and strnlen warning

* Dynamic string width field
2018-11-30 09:03:44 +01:00
Oleg Moiseenko
6a2bd85719 jansson update. 2.11 to 2.12 (#724) 2018-11-30 08:43:46 +01:00
pwpiwi
5594c6215e
fix "hf mf chk" <t|d|s|ss> flags (based on PR #700) (#718) 2018-11-30 07:45:01 +01:00
Fl0-0
03439be30f Fix util.c:116:2: error: unknown type name ‘va_list’ (#722) 2018-11-26 08:11:11 +01:00
Oleg Moiseenko
6b882a3918 Fido U2F complete (#716)
* add pkwrite
* asn1print
* asn1dump and CA
* added PrintAndLogEx for merge commits between repo easier than now
* changelog
2018-11-25 16:56:12 +01:00
Oleg Moiseenko
e0991f6aa7 Get rid of polarssl (#717) 2018-11-23 19:03:46 +01:00
Oleg Moiseenko
700d868794 move from polarssl to mbedtls (#708)
* update polarssl to mbedtls
* fix a warning in armsrc/iso15693
* added random generator and ecdsa test
* added signature check to test
* move crypto lib to client directory
2018-11-19 09:02:38 +01:00
Oleg Moiseenko
39cc1c879e FIDO U2F NFC authenticators (#697)
* `hf fido` command
* detects FIDO tag
* add new commands for fido u2f
* added changelog
* added fido2 info
2018-11-17 20:22:21 +02:00
Oleg Moiseenko
8fa6838476 fix - some card cant reset so quick. (#713) 2018-11-17 19:04:56 +02:00
Oleg Moiseenko
1429030854 fix get length in tlv (#714) 2018-11-17 19:04:25 +02:00
pwpiwi
bdf96aae39 fix hf 15 reader (merge error) 2018-10-31 22:00:36 +01:00
Oleg Moiseenko
6eeb5f1c29 fix warning under linux (#709) 2018-10-31 19:47:37 +01:00
drhatson
4b5d696c17 changes to mifare plus code (#706) 2018-10-31 19:46:12 +01:00
Oleg Moiseenko
c8a0f55031 Mfp read plain (#704)
* added aes-cmac-128
* aes-cmac added to cryptosystem. not works(
2018-10-26 19:18:53 +02:00
Oleg Moiseenko
cdc9a7562d inc timeouts (#705) 2018-10-26 14:43:06 +02:00
Oleg Moiseenko
ae3340a0fb Mfp commands (#698)
* add write perso from https://github.com/Proxmark/proxmark3/blob/master/client/scripts/mifarePlus.lua
* commit perso from https://github.com/Proxmark/proxmark3/blob/master/client/scripts/mifarePlus.lua#L184
* added errors https://github.com/Proxmark/proxmark3/blob/master/client/scripts/mifarePlus.lua#L91
* fix bug in CLIParamHexToBuf
* added init card command
* auth4 refactoring
* add changelog
2018-10-24 18:58:12 +02:00
pwpiwi
3685f89cbd small fix to please @dmaij's compiler (issue #703) 2018-10-23 19:50:37 +02:00
pwpiwi
8c6cca0ba1
Fix hf 15 sim (#696)
* added ISO15693 coding for tag messages (CodeIso15693AsTag())
* added ISO15693 decoding for reader commands (Handle15693SampleFromReader())
* send tag inventory response in either high or low speed
* some refactoring and formatting
2018-10-23 08:22:13 +02:00
Oleg Moiseenko
666fa6e1cf deploy in msys2 and proxspace (#702) 2018-10-22 22:27:37 +02:00
Oleg Moiseenko
dc3e2acf33 mf plus info with detect sl mode (#695) 2018-10-17 20:55:04 +02:00
Oleg Moiseenko
95b697f017 Emv scan (#691)
* added `hf emv scan` command and options
* add tlv tag save to json
* added tlv tree navigation
* added kernel id and moved some parts of code in ppse
* save gpo result
* added read records
* extract childs from tlv works
* added application data list
* added work with application data section
* flag --extract works
* refactoring: move json functions to emvjson.h/c
* added path.c to jansson
* refactoring: move ParamLoadFromJson
* refactoring: move defparams.json to tag-name-value structure
* refactoring and add key recovering
* added some codes to appdata list
* refactoring: process response format 1 from GPO
* added save mode
* added RID to app data
* add file name handling and small refactoring in argtable string processing
* added finalization logic to `emv scan` and option to remove hash checking in key recovery
2018-10-17 20:53:34 +02:00
Oleg Moiseenko
54e3cfcb74 small improvements in auth (#694) 2018-10-12 14:13:58 +02:00
Oleg Moiseenko
ae027818ac small fix in auth (#693) 2018-10-11 19:28:29 +02:00
Oleg Moiseenko
7dadcc959f auth 14443-4 (#692)
* AES authentication
2018-10-10 22:34:04 +02:00
pwpiwi
9f38391395 Update CHANGELOG for 3.1.0 release 2018-10-10 08:35:03 +02:00
Oleg Moiseenko
92479429c2 Added loading parameters from json to several emv commands (#686)
* added loading params from GPO
* `hf emv pdol` added help and warning
* started `hf emv ac`
* dol calculation implemented in genac and intauth
* help fix
2018-10-08 07:48:37 +02:00
AntiCat
b742ab8cc3 osx: fix annoying focus behaviour (#689)
OS X has a global menu bar and a per app dock icon. Therefore, all
GUI applications launched from a terminal will become focused - even
if they don’t show any windows. Thereby the terminal loses focus.

Since is it very annoying to re-focus the terminal after each proxmark
client launch, this change makes the client unfocusable during launch
and restores the regular behaviour when a window is created.
2018-10-08 07:20:21 +02:00
AntiCat
2a53731106 osx: disable app-nap during serial comm (#687)
Apple introduced app-nap with OS X 10.10. This feature
saves power by throttling apps running in background.
However, it also less accurate timers in systemcalls. In
our case a 30ms select timeout would take up to 10s.

This patch uses an API also added with 10.10 to disable
app-nap as long as the serial port is polled.
2018-10-08 07:15:29 +02:00
pwpiwi
70b2fc0abd
start fixing hf 15: (#684)
* implement a real time Decoder for tag responses (will be required for sniffing)
* switch off field after each command (protect rdv40)
* correctly signal field status with LED D
2018-10-07 17:32:03 +02:00
AntiCat
351d6d17b3 Fix: ControlWidget placement (#690)
* ui: code cleanup
* ui: move control widget below plot
2018-10-07 17:30:47 +02:00
pwpiwi
eed83b910c Add another #ifdef for the __BIONIC__ fix (the effect of setting p_thread to 0 is undefined for other libs) 2018-10-06 17:48:43 +02:00
pwpiwi
a025b74606 Merge branch 'master' of https://github.com/Proxmark/proxmark3 2018-10-06 17:35:40 +02:00
Michael Farrell
7b2cd970ec FIX: crash on Bionic libc if CloseProxmark is called twice. (#672)
In Android O and later, if an invalid pthread_t is passed to pthread_join,
it calls fatal().

ed16b344e7/libc/bionic/pthread_internal.cpp (L116-L128)

This patch addresses it by:

1. Always memset(0) on USB_communications_thread at the end of
   CloseProxmark.

2. On Bionic, only call pthread_join on USB_communications_thread if it is
   not equal to 0.
2018-10-06 17:33:44 +02:00
pwpiwi
b49aec796c Merge branch 'master' of https://github.com/Proxmark/proxmark3 2018-10-06 09:06:13 +02:00
Oleg Moiseenko
11146fc1e1 modify argtable parser to parse ints with spaces (#683)
* modify argtable parser to parse ints with spaces
* added arg_strx1 and arg_strx0 for x str arguments in one
* added option to clue data in arg parser
* add new argtable logic to emv commands and small fix
* small fix in GPO help
* small GPO fix
2018-10-01 20:12:14 +02:00
Oleg Moiseenko
f23565c38b Added to hf emv commands: gpo, readrec, genac, challenge, intauth (#671)
* move `hf emv search` to argtable
* `hf emv select`
* delete old help
* `hf emv pse` and sketch for the other commands
* `hf emv gpo` 
* `hf emv readrec`
* `hf emv challenge` works
* added `intauth` and `genac` commands.
* added CDA transaction to `hf emv genac`
* add terminal decision to `genac`
* added changelog
2018-09-28 18:03:21 +02:00
pwpiwi
48354ddb54 Merge branch 'emv_argtable' of https://github.com/merlokk/proxmark3 2018-09-28 17:59:14 +02:00
pwpiwi
b8a92318be Merge branch 'master' of https://github.com/Proxmark/proxmark3 2018-09-24 13:04:21 +02:00
pwpiwi
c13afca1f5 Fix: accidentially deleted line in fpgaloader.c 2018-09-24 13:03:13 +02:00
Oleg Moiseenko
2d4db38754 FIX: APDUCodeTable has more items than 100 (#682)
4fa0835d5f
2018-09-24 12:48:07 +02:00
Oleg Moiseenko
16cdfa6355
Merge branch 'master' into emv_argtable 2018-09-24 13:27:30 +03:00
Fl0-0
a7e1b46d51 Jansson gcc8 fix (#679)
* Fix error in error.c
* Fix error in load.c
2018-09-22 17:51:13 +02:00
pwpiwi
050aa18b13
RDV40 compatibility fixes (#678)
* detect and use RDV40 higher voltage ADC channel for hw tune, hf tune, hw detectreader
* fix mode switching in hw detectreader
* detect Smartcard Slot in hw version
* i2c changes from https://github.com/RfidResearchGroup/proxmark3
* some formatting in proxmark3.h
2018-09-21 08:27:35 +02:00
marshmellow42
2758d83652
Merge pull request #658 from grauerfuchs/master
rework of 'lf hid' commands for better card format handling
2018-09-18 22:23:47 -04:00
marshmellow42
161c40fb52
Merge branch 'master' into master 2018-09-18 22:12:11 -04:00
Oleg Moiseenko
696e863078 added EMV tag #9F6E (#676) 2018-09-18 18:52:41 +02:00
merlokk
57548f275a hf emv exec works with argtable 2018-09-18 19:06:59 +03:00
merlokk
61ad070f56 delete unused procedure after merge 2018-09-18 18:36:03 +03:00
Oleg Moiseenko
654b6ae3f4
Merge branch 'master' into emv_argtable 2018-09-18 18:29:59 +03:00
Oleg Moiseenko
556826b5d5 Added loading EMV transaction parameters from json file (#659)
* added default params file
* added jansson
* added test function.
* added tlv tree to function
* add params from json works
* added to `hf emv exec`: load params from json and some refactoring
* added `scan` command
2018-09-18 07:15:34 +02:00
Michael Farrell
82258709f6 Remove unused functions le32toh, le24toh, hextobinstring, binarraytobinstring, print_hex, print_hex_break, sprint_hex_ascii, sprint_ascii, SwapEndian64ex (#667)
* Remove unused method le32toh.
* Delete unused function le24toh
* Remove unused functions hextobinstring, binarraytobinstring
* Remove unused functions print_hex, print_hex_break
* Delete unused functions sprint_hex_ascii, sprint_ascii
* Remove unused function SwapEndian64ex
2018-09-17 08:35:45 +02:00
AntiCat
2dedd5eaec Update changelog and fix build error (#674)
* Update CHANGELOG.md
2018-09-17 07:56:53 +02:00
uhei
b4ba1eeabe fpgaloader: fix function accordingly to #669 (#673)
FpgaSetupSscDma uses uint16_t and not int with #669
2018-09-17 07:55:51 +02:00
pwpiwi
6a5d4e17f4
rework iso14443b device functions including FPGA I/Q signal transfer (#669)
* rework iso14443b device functions
* hf_read_rx_xcorr.v: transfer i/q pair in one 16bit frame
* hi_read_tx.v: invert ssp_dout. When nothing is transferred (ssp_dout=0), this results in no modulation (carrier on)
* adjust arm sources accordingly
* iso14443b.c: switch off carrier after hf 14b sri512read and hf 14b srix4kread
* iso14443b.c: fix DMA circular buffer handling
2018-09-16 00:53:28 +02:00
grauerfuchs
0d7ee55f9d
Adding new Kastle 32-bit format from @xilni
As approved by @0xFFFF on RfidResearchGroup/proxmark3 and provided by @xilni, this commit adds the format into the official repo as well. As I don't have any of the cards available for testing, I have been unable to personally verify the format encodes/decodes as intended.
2018-09-14 06:32:29 -04:00
grauerfuchs
173ba1e1a2
Merge branch 'master' into master 2018-09-13 21:30:24 -04:00
grauerfuchs
fc7a78f2d1 Changes requested by @marshmellow42
Added CHANGELOG details for new lf hid commands
Restored basic ARM-side decoding of 26-bit and 35-bit cards
2018-09-13 21:05:11 -04:00
merlokk
8c2ae2176d added changelog 2018-09-13 20:03:10 +03:00
merlokk
0c4750c3ba small fixes in helps 2018-09-13 19:58:26 +03:00
merlokk
02ab5afa87 add terminal decision to genac and small fixes 2018-09-13 19:53:14 +03:00
merlokk
48c32f0436 added CDA transaction to hf emv genac 2018-09-13 18:44:20 +03:00
merlokk
11a78e048c added intauth and genac commands. works. 2018-09-13 18:38:03 +03:00
grauerfuchs
53e2f2fad1
Correction to Samyrun offline mode
update to Samyrun offline mode to support changes to HID ARM-side commands

This code has not yet been tested
2018-09-13 06:30:26 -04:00
merlokk
ad23886a6f small fix 2018-09-12 20:22:24 +03:00
merlokk
8ffdccffa0 hf emv challenge works 2018-09-12 20:20:27 +03:00
merlokk
ab2d91f86d hf emv readrec works and some changes in help 2018-09-12 20:08:16 +03:00
merlokk
cd2f1acd1b hf emv gpo works 2018-09-12 19:51:20 +03:00
merlokk
626e650fbf added new functions to hf emv 2018-09-11 17:02:22 +03:00
merlokk
a4662ca9f9 hf emv pse and sketch for the other commands 2018-09-11 16:11:58 +03:00
merlokk
24e0d538d1 delete old help 2018-09-11 14:58:15 +03:00
merlokk
7d4ba60e8e hf emv select some refactoring 2018-09-11 14:56:33 +03:00
merlokk
3668df05ec hf emv select 2018-09-11 14:49:50 +03:00
merlokk
6d31653c44 move hf emv search to argtable 2018-09-11 12:21:29 +03:00
wllm-rbnt
53edb044c0 Allow clean Legic simulation exit without button press (#668) 2018-09-10 18:19:31 +02:00
AntiCat
1b902aa01a Legic Tag Simulator (#666)
* FPGA Hi-Simulate: Formatted code
* FPGA Hi-Simulate: Fixed documantation
* FPGA Hi-Simulate: Freed up 4 LUTs
* FPGA Hi-Simulate: Added 212kHz SSP-Clock option
* Legic: Moved card simulator into separate file & cleaned interface.
Reader and card simulation have almost no common code. Moreover the sim
uses an SSP Clock at 212kHz for all timings to prevent any drifting from
the PRNG. This clock speed is not available in reader simulation mode (SSP
runs at up to 3.4MHz, and changes speed between TX and RX). For these
reasons having the code in separate files makes it significantly cleaner.
* Legic: Implemented RX and TX for card simulation
* Legic: Implemented setup phase for card simulation
* Legic: Implemented read command for card simulation
* Legic: Implemented write command for card simulation
2018-09-09 16:40:20 +02:00
Oleg Moiseenko
6e3d8d671a implement argtable in hf 14a apdu (#490)
* added `hf 14a reader` to source and added functionality to exec empty commands
* added `hf 14a raw`
* added samples to command's help
* added some help
* added changelog
* update to new argtable3 --- https://github.com/argtable/argtable3
* changed included getopt to `https://github.com/freebsd/freebsd/blob/master/include/getopt.h` (getopt from freebsd with simplified BSD license)
2018-09-06 07:48:54 +02:00
Oleg Moiseenko
f3c8131a0d update travis config (#662) 2018-09-06 07:38:38 +02:00
grauerfuchs
be59094de9 lf hid improvements - encoding and long tag simulation
**DEVICE FIRMWARE UPDATE**
The code changes needed to support long tag emulation required an update to the device firmware. As of this patch, devices running older firmware will not be able to read or emulate HID tags until the firmware is updated. Additionally, devices with the firmware from this update or newer will not properly read or encode HID tags with a prior version client.

The 'lf hid encode' command has been further refined, and is now entirely parameterized to support use of fields other than facility code and card number. The client help data has been updated to show the correct syntax.
2018-08-30 21:01:21 -04:00
grauerfuchs
5d643cc033 lf hid: Added encode/decode support for Issue Level
Issue Level added to encode/decode support
By default, invalid parity will not show on decode (with option to show)
Added two new 36-bit formats including first format to use issue level
2018-08-28 13:34:21 -04:00
grauerfuchs
b5a5fc4d9f Redesign of lf hid card format handler as discussed with @marshmellow42
The new handler accepts multiple formats of the same length.
Because of this, the existing pack/unpack commands are unsupported
and have been removed and replaced with 'lf hid encode' and 'lf hid decode'.
The decode command will test a packed Prox ID against all programmed
formats and return results for all matching formats.
The encode command takes the parameter of format name instead of
bit length (as per the old pack command). Additionally, an 'lf hid write'
command has been added as a single-command combination of encode and clone.

To support easier addition of new formats, a library for handling card
fields has been added. This will allow direct access to the card bits,
to linear fields, and to non-linear (jumping) fields in a single line
of code without having to resort to managing bit positions or masks
on the underlying data. A number of new formats have been added as working
examples of the new support functions.
2018-08-27 14:03:46 -04:00
grauerfuchs
18a3bf6119
Merge pull request #9 from Proxmark/master
Pulling in most recent changes in official code tree
2018-08-22 18:57:48 -04:00
marshmellow42
d62f7bad20
Merge pull request #649 from grauerfuchs/master
client: lf hid - parity completed, native long-tag support in pack/unpack/clone
2018-08-22 11:21:50 -04:00
marshmellow42
43591e6464 Add Smartcard functions (RDV4.0) (#646)
* allow common makefile options-defines

* remove non-existing file references

* Uncomment lcd option (still) not enabled by default

use Makefile_Enabled_Options.common
to enable lcd if desired.

* Add Smartcard Functions

* add smartcard to menu + make get atr work

sc is now functioning as far as my limited knowledge takes me

* sc cleanup - add init to all sc commands...

because cmds won't work until the first init happens.  (multiple inits
don't appear to affect it negatively)

* default options to exclude Smartcard

for main repo

* update changelog
2018-08-21 05:08:49 +02:00
AntiCat
f684231796 Legic: fixed write (#655)
Due to an oversight the bytes to be written were fetched
from the wrong location. This is fixed now.
2018-08-21 05:08:06 +02:00
AntiCat
da05bc6eca Legic: rewrite reader to use xcorrelation and precise timing (#654)
* Legic: rewrite reader to use xcorrelation and precise timing
 - Even tough Legic tags transmit just AM, receiving using
   xcorrelation results in a significantly better signal
   quality.
 - Switching from bit bang to a hardware based ssc frees
   up CPU time for other tasks e.g. prng and demodulation
 - Having all times based on a fixed ts, results in perfect
   rwd-tag synchronization without magic +/- calculations.
* hi_read_tx: remove jerry-riged hysteresis based receiver
- This feature got obsolete by a x-correlation based receiver.
* Legic: adjusted sampling to new ssp clock speed
- Sampling is 4 times faster and pipeline daly reduced to 1/4.
 The new code samples each bit earyler to account for the
 shorter pipeline. That introduced bit errors by leeking the
 next bit into the current one.
* Legic: average 8 samples for better noise rejection.
* Update CHANGELOG.md
2018-08-20 22:29:34 +02:00
grauerfuchs
1ee624fe6a Adding native support for HID long-format
Removal of "l" flag for long writes; not needed anymore.
    Added HID Corporate 1000 48-bit format to known formats list
    Simulation not yet updated; need to modify ARM commands to support it
    Completed parity support on all included HID formats
2018-08-19 11:14:52 -04:00
pwpiwi
315e18e66c
ISO15693 device side improvements (#652)
* ISO15693 device side improvements
* increase accuracy by doubling the sample frequency (hi_read_rx_xcorr.v)
* adjust armsrc/iso15693.c and client/cmdhf15.c accordingly
* use more accurate approximation for sqrt(ci^2 + cq^2)
* improve EOF detection (was often mistaken for Logic0, resulting in "error, uneven octet! (extra bits!)")
* hi_read_r_xcorr.v: avoid overflows during accumulation and truncation
* explicitely cast unsigned ADC samples to signed
2018-08-15 14:03:20 +02:00
Oleg Moiseenko
c80eb8ba79 some cards need to have Le=0x00, some need to not have... (#651) 2018-08-14 10:15:51 +02:00
AntiCat
8ff31e935d fix: 32bit tick timer based on TC0 and TC1 (#653)
TC1 counts the number of TC0 overflows (carry bits).
In random conditions TC1 would return or stay at zero,
instead of counting up. This due to the behavior of the
reset signal.

SAM7S Series Datasheet, 33.5.6 Trigger:
Regardless of the trigger used, it will be taken into account
at the following active edge of the selected clock. This means
that the counter value can be read differently from zero just
after a trigger, especially when a low frequency signal is
selected as the clock.

The new code first prepares TC1 and asserts TC1 trigger and
then prepares TC0 and asserts TC0 trigger. The TC0 start-up
will reset TC1.
2018-08-14 09:24:02 +02:00
Fl0-0
6a0915eac2 Bootrom version fix + .gitignore (#645)
* Fix bootrom Makefile

* Add armsrc/fpga_version_info.c to .gitignore
2018-08-07 09:23:11 +02:00
marshmellow42
dfdca20c6c fix option comments to be more clear 2018-08-06 07:39:39 -04:00
marshmellow42
a2937cea8d Separate WITH_LF and WITH_LF_StandAlone 2018-08-06 07:27:37 -04:00
pwpiwi
472345daee
mod hw version: (#631)
* create fpga version info at compile time (by additional functionality in fpgacompress)
* remove hw version caching (prepare USB reconnect)
* fix calculation of available compressed bytes in fpga_loader.c
2018-08-05 18:15:03 +02:00
marshmellow42
5125e4263c allow common makefile options-defines (#635) 2018-08-05 18:13:44 +02:00
marshmellow42
f366aea3e1
Merge pull request #638 from grauerfuchs/master
fix truncation issue on "lf t55 config d"
2018-08-04 07:43:27 -04:00
grauerfuchs
b6a04aff48
fix truncation issue on "lf t55 config" modulation
Fix for issue #637
2018-08-04 06:26:36 -04:00
Michael Farrell
ab20cc35b7 Adds lf hid pack and lf hid unpack offline commands. (#614)
* These are used to pack and unpack the bit length, facility code and card number from "short" HID Prox IDs.
* This also simplifies some repeated code that is used to parse hex digits in lfhid, and adds basic client-side validation to the `lf hid clone` and `lf hid sim` commands, for when an ID that is too long is entered.
* Implements parity checks/calculation for 26-bit H10301 cards.
* Adds links to useful resources for HID Prox cards.
* Adds an explicit warning about the lack of parities on non-26-bit cards.
* Changes all the examples to use 26-bit IDs that have a parity bit set.
2018-07-30 19:33:06 +02:00
pwpiwi
913a54a86a
save 2.3K flash-memory by avoiding a single floating point operation (#630) 2018-07-26 17:18:10 +02:00
Fl0-0
00349d8204 Fix Gcc 8 warnings (#632) 2018-07-26 17:17:11 +02:00
pwpiwi
b2e0ac5d3b fix: array index out of range in mfkeys.log (thanks to @TomHarkness) 2018-07-19 18:01:18 +02:00
Michael Farrell
577b1c27f5 Allow disabling unlink() with -DNO_UNLINK. (#625) 2018-07-09 09:49:03 +02:00
stuiterveer
fdee1ffa84 Ignore DS_Store (#620)
Prevent further commits containing DS_Store files
2018-06-20 06:34:00 +02:00
pwpiwi
44964fd181
Code cleanup (#616)
* coverity fixes (including a real bug in cmdhftopaz.c)
* Typo fix
* replace TRUE/FALSE by stdbool true/false
2018-06-13 08:13:20 +02:00
Michael Farrell
2bb7f7e327 Fixes a double-free issue in CloseProxmark: (#617)
- CloseProxmark now clears global state.

- CloseProxmark now checks for a non-null serial_port before calling uart_close, to avoid unintentional double-free'ing serial_port.

- main now calls CloseProxmark once.
2018-06-04 13:54:41 +02:00
pwpiwi
ad939de501
USB comms: part 4 towards @micolous PR #463
* make uart_communication(), storeCommand() and getCommand() static in comms.c
* move receiver thread creation and respective mutexes to comms.c
* add mutex and signal for tx buffer
* use comms.c for flasher as well
* remove comm functions from client/proxmark3.h
* this completes isolating all USB communication related functions in comms.c
* don't assume a port to be defined by a name. Change parameter in OpenProxmark() to void*
* comms.c: set sp and serial_port_name to NULL when offline
2018-06-03 14:25:20 +02:00
Fl0-0
9b4661c53b Delete .DS_Store (#613)
Mac hidden file accidentally merged in PR #593.
2018-05-29 18:05:32 +02:00
Dominic Celiano
803674b2d6 Added mifarePlus.lua script for communication with Mifare Plus. (#593)
Personalize MifarePlus EV1 cards
2018-05-28 21:32:48 +02:00
marshmellow42
e8924be8ba fix gui (plot) bugs (#604)
G keypress event would cause a crash if no data
Q keypress didn't work.

Thanks to @iceman1001 for identifying and providing the fixes.
2018-05-15 08:19:49 +02:00
pwpiwi
0000a4cda2
fix HitagS simulation erors (issue #605) (#606) 2018-05-11 05:24:02 +02:00
pwpiwi
babca445ff
rework of GetFromBigBuf() (#597)
* this should fix crashes reported in issue #497
* don't allow receiver thread to write directly into arbitrary main thread's memory
* instead use cmdBuffer[] for CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K as well
* add timeout and warning options to GetFromBigBuf(), same as in WaitForResponseTimeoutW()
* move GetFromBigBuf() from data.c to comms.c
* remove data.c and data.h
2018-05-08 07:54:49 +02:00
Iceman
03cdcca03f
Merge pull request #600 from marshmellow42/master
more graceful exit to lf search if no signal found
2018-05-05 06:59:39 +02:00
marshmellow42
a468b4277a more graceful exit to lf search if no signal found 2018-05-04 23:54:01 -04:00
pwpiwi
e475fce44d
Update CHANGELOG.md 2018-05-04 08:25:08 +02:00
pwpiwi
dbac9ffb40
Change driver file proxmark3.inf to support both old and new Vendor/Product IDs
(see http://www.proxmark.org/forum/viewtopic.php?pid=32072#p32072)
2018-05-04 08:19:37 +02:00
marshmellow42
854fdf15e0 fix bug if -DWITH_ISO14443a_StandAlone is removed from makefile (#598) 2018-05-03 19:36:51 +02:00
pwpiwi
818efbebb8
USB comms: part 3 towards @micolous PR#463
* change variable 'sp' from global to static
* move code to open and close USB port to comms.c (OpenProxmark() and CloseProxmark())
* change scope of USBCommandReceived() to static
* (flasher still unchanged)
2018-04-28 10:09:16 +02:00
pwpiwi
61aaee35cc
USB comms: part 2 towards @micolous PR#463 (#595)
* change variable 'offline' from global to static
* change variable 'FlushAfterWrite' from global to static
* remove unused global variable 'current_command'
* WaitForResponseTimeoutW(CMD_UNKNOWN, ...) waits for any command
* #include "printf.h" or <stdio.h> in iso15693tools.c to define sprintf()
* and some minor changes/comments
2018-04-24 08:27:29 +02:00
Tom Harkness
e069547c27 Fix for swapped parity when using lf_bulk_program.lua (#591) 2018-04-03 08:14:51 +02:00
pwpiwi
f5ecd97b15
USB comm: prepare for @micolous change (PR#463) (#587)
* move communication related code from proxmark3.c and cmdmain.c to new file comms.c
* replace byte_t by uint8_t in uart_posix.c and uart_win32.c
* move OpenProxmark() and CloseProxmark() from flasher.c to flash.c
* move print_lock mutex including initializer to ui.c
* minor changes in printing help texts
* no changes in comms functionality yet
2018-03-31 09:52:43 +02:00
pwpiwi
3bcc4d77e1
add: save and load options in hf list (#577) 2018-03-30 17:55:41 +02:00
AnthraX1
53c7a7053d Fix empty key list bug in mfkeys.lua (#579)
When input key list size is greater than 85, table.concat() returns empty because the last parameter is the end offset not the increment value.
2018-03-30 17:54:45 +02:00
pwpiwi
3316fc1d11
Merge pull request #589 from Proxmark/revert-588-indala-preamble-fix
Revert "Fix offset Indala UID display"
2018-03-28 14:58:46 +02:00
marshmellow42
7ecf7cf6cc
Revert "Fix offset Indala UID display" 2018-03-28 08:50:08 -04:00
Iceman
6c7a3bd7ce
Merge pull request #588 from megabug/indala-preamble-fix
Fix offset Indala UID display
2018-03-28 13:10:33 +02:00
Matthew Daley
b05611a30b Fix offset Indala UID display
Commit 1dae9811f2 extended the amount of
fixed bits searched for when decoding 64-bit Indala. These additional
bits come from the end of one UID, and therefore need to be skipped past
when actually retrieving the UID.
2018-03-28 23:43:57 +13:00
James Chambers
b24930c764 mfu read block: retry block with bad CRC (#584)
* mfu read block: retry block with bad CRC, command timeout, or unknown response.
2018-03-23 20:26:30 +01:00
Michael Farrell
a5a830168f OSX: Multiple libedit/readline fixes (#585)
* OSX: Multiple libedit/readline fixes.
2018-03-21 16:05:03 +01:00
W8M2Hg9lLmWqXSGC
51d51c6782
Merge pull request #580 from Proxmark/iceman1001-patch-1
Update README.md
2018-02-26 17:25:21 +11:00
Iceman
d4d439a8aa
Update README.md
Added hackerwarehouse
2018-02-26 07:16:08 +01:00
Iceman
c50e55a4a5
Merge pull request #578 from Tom5ive/master
fix for swapped parity bits
2018-02-22 14:08:33 +01:00
Tom Harkness
f43b1038a2 fix for swapped parity bits 2018-02-22 23:38:53 +11:00
Iceman
b8196bf8ee
Merge pull request #565 from Proxcloud/usb_android
Allow non-root access on Android devices
2018-02-17 12:39:19 +01:00
Iceman
d6e5b54f40
Merge pull request #572 from merlokk/hflistms_fix
`hf list mf` fix key length in printf
2018-02-14 23:36:41 +01:00
merlokk
738ed6e476 small fix 2018-02-15 00:20:00 +02:00
merlokk
6dec58aa44 small fix hf list mf 2018-02-15 00:18:02 +02:00
Iceman
902c470d38
Merge pull request #571 from merlokk/hf_list_mf
added command `hf list mf`
2018-02-14 22:06:29 +01:00
Iceman
f69f1de80c
Merge pull request #570 from marshmellow42/master
improve lf cmdread
2018-02-14 22:06:00 +01:00
marshmellow42
2896e490d9 update changelog
+fix a comment typo
+ move clear bigbuf after fpgadownloadandgo...
2018-02-14 15:41:39 -05:00
merlokk
079563a092 small fix and added line to changelog. 2018-02-14 12:36:22 +02:00
merlokk
868deeb783 move annotate* functions 2018-02-13 17:14:51 +02:00
merlokk
45b4ac09c9 added hardnested sketch. final cleaning. 2018-02-13 17:07:49 +02:00
merlokk
0113dcf3fd nested works 2018-02-13 15:12:41 +02:00
merlokk
8253ca0e1b code cleaning 2018-02-13 12:35:33 +02:00
merlokk
597fca4ff1 check parity works 2018-02-13 12:33:15 +02:00
merlokk
2d7bdee30b added parity check of deciphered command 2018-02-12 18:53:12 +02:00
Oleg Moiseenko
bf52d74adc small fix 2018-02-11 00:45:12 +02:00
Oleg Moiseenko
856da9a1c0 added cipherstream recovery 2018-02-11 00:44:24 +02:00
Oleg Moiseenko
e01bc7942c move ks to authdata 2018-02-11 00:40:24 +02:00
marshmellow42
779d9a0e90 reconfigure lf cmdread ...
to use lf config settings instead of it's own settings.  (now allows
full options of lf config...)

also it will now run `data samples` when the command completes making it
not necessary to run manually...

note: adjusted client wait message as it was confusing.
2018-02-10 17:30:32 -05:00
Oleg Moiseenko
7bea15816e added some cone in nested. not tested. 2018-02-11 00:28:23 +02:00
Oleg Moiseenko
e0158d3373 added destroy 2018-02-10 23:28:15 +02:00
Oleg Moiseenko
dca8220f72 mock of key checking 2018-02-10 23:25:28 +02:00
Oleg Moiseenko
c6a886fb4f added mock of key check 2018-02-10 23:06:01 +02:00
Oleg Moiseenko
747885a6ed hf list mf 1st auth works 2018-02-10 22:33:32 +02:00
Oleg Moiseenko
edd4c8385b small fix util.c 2018-02-10 22:10:38 +02:00
Oleg Moiseenko
28ee794f59 fix appearance 2018-02-10 20:41:56 +02:00
Oleg Moiseenko
7b215d149a correct 1st key calculation 2018-02-10 20:28:30 +02:00
Oleg Moiseenko
b957bcd382 added get parity 2018-02-10 19:19:56 +02:00
Oleg Moiseenko
a31f7f899b small fix 2018-02-10 19:06:34 +02:00
Oleg Moiseenko
aadc6bf1e1 combine all auth data to single struct and fill it 2018-02-10 19:03:29 +02:00
marshmellow42
61e96805ad add bitbang option to lf cmdread
by setting delay to 0 we can use cmd binary to bitbang the antenna.

note that the timing isn't perfect (especially on the off periods) but
is fairly close. worst i've seen it off is 8us on a large off period.
but i don't have the best test equipment...
2018-02-09 15:51:20 -05:00
merlokk
fb30f5a101 added check reader/tag 2018-02-09 19:40:39 +02:00
merlokk
6c30a244eb added some get auth data 2018-02-09 19:32:17 +02:00
merlokk
6612a5a201 moved some functions and added auth sequence annotation 2018-02-09 18:23:04 +02:00
merlokk
4f131b53ea added cmdhflist file 2018-02-09 17:37:31 +02:00
Oleg Moiseenko
a37725facf add nested auth decoding to hf mf sniff 2018-02-09 15:50:55 +01:00
Iceman
9e40bad2e3
Merge pull request #569 from pwpiwi/fix_WDT_crash
fix hf mf mifare (WDT crash)
2018-02-08 19:02:16 +01:00
Proxcloud
f3dc6d59f4 make product string even length 2018-02-08 22:32:08 +08:00
pwpiwi
664e132f88 hf mf mifare:
* prevent WDT crash on repeated tries
* comes with faster execution as side effect
* use uint8_t instead of byte_t
* populate ar instead of (correctly) assuming that it is zero
* remove the "will take a few seconds longer" message because it is no longer true
2018-02-08 14:51:24 +01:00
Proxcloud
d03a573eee change product desc to 9 and add extra null byte 2018-02-08 20:40:57 +08:00
Proxcloud
13c25f892e remove debug change 2018-02-08 19:43:03 +08:00
Proxcloud
c179e7b1f8 remove old Manufacturer description code. fix Product description length 2018-02-08 19:37:55 +08:00
Proxcloud
8b9de94afe Remove BOS descriptor, leave just manufacturer descriptor for Android 2018-02-08 17:47:40 +08:00
Iceman
02515642bc fix: hf mf mifare - populate keylist (#568)
This will solve the long running of the attack, since all candidate keys will be tested.
2018-02-08 04:15:42 +01:00
Proxcloud
948b49c407 Add BOS USB descriptor. This allows non-root access on Android devices 2018-02-07 01:07:48 +08:00
Iceman
2ef3a5e99c
Merge pull request #560 from pwpiwi/fix_hfmfmif
fix: prevent hf mf mifare from always running twice
2018-02-06 08:15:03 +01:00
pwpiwi
d86ee73da5 fix: prevent hf mf mifare from always running twice
(issue #510)
2018-02-03 18:26:09 +01:00
Iceman
c839fa2c25
Merge pull request #558 from pwpiwi/fix_alignment
add force_align_arg_pointer attribute to all callback functions
2018-02-01 09:49:43 +01:00
Arnie97
32e6891a05 hf mf nested: use bitwise or instead. (#556) 2018-02-01 08:09:14 +01:00
pwpiwi
f921c113c9 add force_align_arg_pointer attribute to all callback functions
* inspired by issue #404 and respective fix PR #538
* possible fix for mysterious crashes, e.g. issue #497 and http://www.proxmark.org/forum/viewtopic.php?id=5388
2018-01-31 18:31:51 +01:00
pwpiwi
298e1a2d0d
update license conditions in armsrc/optimized_cipher.[ch] (#554) 2018-01-31 08:14:56 +01:00
Iceman
365627e2f1
Merge pull request #555 from Arnie97/master
hf mf nested: transfer keys to the correct block in one sector mode.
2018-01-26 19:31:23 +01:00
Arnie97
7b7416bd3b hf mf nested: transfer keys to the correct block in one sector mode. 2018-01-27 01:55:38 +08:00
Arnie97
36545f0a56 hf mf eset: reuse mfEmlSetMem(). 2018-01-27 01:09:56 +08:00
Iceman
380e0d086c
Merge pull request #553 from Arnie97/master
Minor fixes
2018-01-25 09:50:47 +01:00
Arnie97
b5cf8b07e2 mfkeys.lua: Remove trailing whitespaces. 2018-01-25 14:52:30 +08:00
Arnie97
f88fa399bc mfkeys.lua: Align empty cells in the table. 2018-01-25 14:48:12 +08:00
Arnie97
392301aaab mfkeys.lua: Remove the user input helpers (now in lualibs/utils.lua) 2018-01-25 14:46:00 +08:00
Arnie97
4e002980af hf mf ecfill: Add the missing line break. 2018-01-25 14:39:27 +08:00
Arnie97
e98389b355 Fix typo in lua scripts: 1443a -> 14443a. 2018-01-25 13:43:01 +08:00
Iceman
fb69dd881a
Merge pull request #551 from pwpiwi/remove_reveng
Remove reveng
2018-01-24 10:47:59 +01:00
pwpiwi
757221f5d6 Remove reveng
(its license was not compatible with PM3 license, see issue #527)
2018-01-24 08:38:01 +01:00
Iceman
940b282f54
Merge pull request #550 from pwpiwi/fix_warnings
fix clang compiler warnings
2018-01-23 17:43:07 +01:00
pwpiwi
ec0872181b fix clang compiler warnings
identified in http://www.proxmark.org/forum/viewtopic.php?id=5388
2018-01-23 16:55:48 +01:00
Iceman
acaa71ffe3
Merge pull request #549 from rkblackfire/master
Debug&Improvement of HW TUNE
2018-01-22 19:33:41 +01:00
rkblackfire
f3ffd5a24f Revert "dbg: Watchdog resets while 'hw tune lf'"
This reverts commit fc175230f4.
2018-01-22 19:25:22 +01:00
rkblackfire
095173f72d chg: print only valid tuning data
only print the ranges which were tuned, thus not showing an error for
'lf antenna' when called 'hw tune hf' and vice versa
2018-01-22 18:59:48 +01:00
rkblackfire
fc175230f4 dbg: Watchdog resets while 'hw tune lf'
loop does not finish, u_int is always '>=0'
2018-01-22 18:54:29 +01:00
Iceman
30bb6d6591
Merge pull request #548 from merlokk/mfsniff_fix
`hf mf sniff` not a small fix
2018-01-17 23:16:08 +01:00
merlokk
2ba37081ec added nested authentication "not implemented" warning 2018-01-17 18:16:37 +02:00
Iceman
af1940a5d8
Merge pull request #546 from pwpiwi/fix_tune
hw tune improvements (based on issue #544)
2018-01-17 16:11:56 +01:00
merlokk
a034948363 fix eml file format 2018-01-17 16:12:50 +02:00
merlokk
f7887fa82e added magic cards 2018-01-17 16:01:56 +02:00
merlokk
3e77c7a7b4 ignore SELECT ALL 2018-01-17 15:57:24 +02:00
merlokk
543a6ed3c9 SNF_WUPREQ and SNF_SAK harmonized) 2018-01-17 15:48:01 +02:00
merlokk
968cb35498 deleted save UID from card 2018-01-17 14:14:36 +02:00
merlokk
35cc71b075 delete opposite states fix 2018-01-17 14:10:26 +02:00
merlokk
3544b99715 fixed #541 2018-01-16 17:54:54 +02:00
merlokk
feb328c90a hf mf sniff small fix 2018-01-16 14:34:04 +02:00
Iceman
138a0e7a6b
Merge pull request #503 from merlokk/travis
Travis
2018-01-15 16:06:37 +01:00
pwpiwi
d1f9ec06ae
Revert changes in hardnested nonces collection. Sacrifice some speed in favor of stability for some card types (#547) 2018-01-15 15:29:14 +01:00
Oleg Moiseenko
8ec06f5ef3 hf mf sniff: small fixes 2018-01-12 22:37:55 +01:00
Oleg Moiseenko
078e2bd238 fix: SIMD instruction set detection on non-x86 hardware
should fix issue #542
2018-01-12 22:04:16 +01:00
pwpiwi
d040cb9024 hw tune:
* scale results to allow higher LF voltages
* remove historic comments
2018-01-12 21:48:42 +01:00
pwpiwi
9b32625c2c hw tune minor fix, comments updated 2018-01-11 08:32:01 +01:00
Iceman
2d51da38f3 HW TUNE adapting for powerful antennas. (#540)
CHG:  'hw tune'  adapting LF measuring from ( >> 8) max 65v,  to ( >>9 ) max 130v in the graph data.   Max LF voltage is 140.8v to measure.

Added a delay for antenna coil and caps to power up before measuring,
removed a variable in ReadAdc
2018-01-10 13:56:27 +01:00
merlokk
84e86ed9e3 move appveyor.yml 2018-01-07 23:23:35 +02:00
Iceman
932af56ea0
Merge pull request #538 from merlokk/hardnestedsetsimd
hardnested SIMD select
2018-01-06 18:54:27 +01:00
Iceman
91ca74f0ed
Merge pull request #534 from pwpiwi/fix_printf
Minor fixes
2018-01-06 18:54:09 +01:00
merlokk
ab0582d672 fix another way 2018-01-06 19:14:34 +02:00
merlokk
4ed45d444b fix #404 2018-01-05 18:36:00 +02:00
merlokk
7421ab0b43 fix readme 2018-01-05 13:04:17 +02:00
merlokk
314a9b9cdd Merge branch 'master' of github.com:Proxmark/proxmark3 into travis 2018-01-05 11:57:11 +02:00
merlokk
58f0ae45c1 move travis files 2018-01-05 11:51:51 +02:00
Iceman
1c313691e6 Update ikeys.c (#537)
FIX: 'hf iclass'  - sneaky fread bug.   It should return same number of bytes as read if ok.   Thanks to @bettse who found it.
2018-01-03 11:15:46 +01:00
merlokk
362d203909 works 2018-01-02 22:28:13 +02:00
merlokk
eaecd7f541 add print SIMD core at the beginning 2018-01-02 19:11:26 +02:00
merlokk
4a768458d2 hardnested SIMD select 2018-01-02 19:05:12 +02:00
Iceman
e1e7a09db1
Merge pull request #533 from merlokk/chktd
fix #532. looks at length of parameters.
2017-12-30 15:23:14 +01:00
Michael Farrell
3775e9e865 Allow externalisation of PrintAndLog (#506) 2017-12-28 18:27:39 +01:00
pwpiwi
96be871374 Merge branch 'master' into fix_printf 2017-12-28 18:23:41 +01:00
Pierre Pronchery
3ded0f97d3 Khorben/warnings (#519)
* Fix warnings and missing #include for <ctype.h>
* Avoid a warning in client/util.c
2017-12-28 17:56:18 +01:00
merlokk
55b700a0ac fix #532. looks at length of parameters. 2017-12-28 13:29:30 +02:00
pwpiwi
b838c4ff27 Minor fixes
* fix compiler warnings on Ubuntu
* cmdhf14a.c: make manufactureMapping static
* cmdhf14a.c: fix format strings
2017-12-28 08:49:07 +01:00
Pierre Pronchery
0f112d6f19 Avoid a crash in "script list" (#521)
This command crashes if the path to the executable directory could not
be found.
2017-12-28 08:37:09 +01:00
Iceman
91e03840f4
Merge pull request #531 from pwpiwi/loclass_gpl
Update loclass license conditions
2017-12-27 09:41:50 +01:00
Martin Holst Swende
26f202e22f Change copyright to allow GPLV3, for https://github.com/Proxmark/proxmark3/issues/527 2017-12-27 08:44:27 +01:00
Iceman
dfdc087bc0
Merge pull request #529 from merlokk/appveyor-tst
added crypto tests to Appveyor
2017-12-25 15:13:46 +01:00
merlokk
e79209e1f4 fixed condition 2017-12-24 01:11:43 +02:00
merlokk
b1c0f02098 added xcode 9.2 and some logging 2017-12-24 00:28:38 +02:00
marshmellow42
69fb283011
Merge pull request #528 from Proxmark/iceman1001-patch-1
Update cmdmain.c
2017-12-23 17:17:43 -05:00
merlokk
828279508a inc timeout 2017-12-23 23:59:47 +02:00
merlokk
546ae21fa1 add hf emv test to appveyor config 2017-12-23 23:50:51 +02:00
Iceman
097d265091
Update cmdmain.c
cherry picking at fix for LF SNOOP,
2017-12-23 22:14:04 +01:00
Oleg Moiseenko
d03fb293bc Emv4 - more additions to hf emv exec
* added rsa polarssl and changed sha1 location to polarssl dir
* deleted old sha1
* added emv-tools pk files
* added polarrssl wrapper sketch to emv_tols
* added test command
* added crypto polarssl with sda test
* added crypto tests and crypto_polarssl sha logic
* added SDA,DDA,fDDA,CDA
2017-12-23 16:46:43 +01:00
marshmellow42
69f98ec91e
Merge pull request #526 from Proxmark/marshmellow42-patch-1
Update lfsampling.c
2017-12-21 08:02:19 -05:00
Iceman
6469d5503a
Update lfsampling.c
@marshmellow42 's fix for #514
2017-12-21 07:55:51 +01:00
Iceman
5e4932e846 'hf iclass chk' part3 (#525)
added the options 
E -   target elite keys
R -  interpret dictionary keys as raw (already diversified keys)
2017-12-17 12:53:21 +01:00
marshmellow42
afb4408b00
Merge pull request #524 from Proxmark/iceman1001-patch-1
ADD 'hf iclass chk'  -  part2
2017-12-16 11:10:05 -05:00
marshmellow42
5421396e7e
Merge pull request #523 from Proxmark/iceman1001-patch-2
ADD: 'hf iclass chk'
2017-12-16 11:09:48 -05:00
Iceman
909c40c835
Update cmdhficlass.h
...hm..  cut'nd'paste error...
2017-12-16 17:08:45 +01:00
Iceman
385c1a5ebc
Update cmdhficlass.c
ADD: 'hf iclass chk'  - new command to check for keys from a dictionary file. 

hf iclass chk h
hf iclass chk f default_iclass_keys.dic
2017-12-15 15:53:58 +01:00
Iceman
678a3cb2fe
Update cmdhficlass.h
add function head
2017-12-15 15:48:25 +01:00
Iceman
feb1bf4184
Merge pull request #515 from pwpiwi/fix_14atimeout
fix: hf mf hardnested failed with new WUPA timing
2017-12-12 15:50:53 +01:00
pwpiwi
fa85b08504 fix iso14a_set_timeout() adjustment 2017-12-11 20:40:09 +01:00
pwpiwi
7c7327e7c8 fix: hf mf hardnested failed with new WUPA timing
* allow additional 2 ssp_frame cycles to detect SOF
* use only respective functions to get/set iso14a_timeout
* remove waiting time in MifareAcquireEncryptedNonces(). This is covered by GetATQA() now.
2017-12-10 19:27:46 +01:00
Iceman
bc3b2f7f94
Merge pull request #511 from ikarus23/typo
fix: usage and sample text of hf mf cwipe
2017-12-07 00:00:10 +01:00
ikarus
6148817a7f fix: usage and sample text of hf mf cwipe 2017-12-06 23:30:27 +01:00
Iceman
8afa9712f7
Merge pull request #508 from pwpiwi/fix_AVX512
fixing the fix: older shells don't know about &>
2017-12-06 17:26:49 +01:00
pwpiwi
1ff75f168b fixing the fix: older shells don't know about &> 2017-12-06 09:25:10 +01:00
Iceman
0fb3e45541
Merge pull request #507 from pwpiwi/fix_AVX512
fix: AVX512 detection
2017-12-05 17:26:20 +01:00
Iceman
385e4b5019
Merge pull request #504 from merlokk/emv3
EMV3. hf emv exec 2nd part
2017-12-05 15:39:37 +01:00
pwpiwi
c656c870ae fix: AVX512 detection 2017-12-05 08:25:10 +01:00
merlokk
7a7afeba5c small refactoring 2017-12-04 22:20:29 +02:00
merlokk
5a1b25ac31 added 9f0a tag 2017-12-03 20:36:04 +02:00
merlokk
f7ec230e98 added a tag 2017-12-03 20:28:36 +02:00
merlokk
1e431c5d36 get rid of tabs) 2017-12-02 22:12:41 +02:00
merlokk
b0c73387f0 added if 2017-12-02 22:10:25 +02:00
merlokk
10d4f82338 transactions MSD and M/Chip, qVSDC works 2017-12-02 21:47:30 +02:00
Iceman
2db66b01da
Merge pull request #493 from merlokk/emv2
Emv2. next part of EMV work
2017-12-02 18:39:14 +01:00
merlokk
245a6b2083 added xcode 9 and 9.1 coz 8 and 8.1 links to 8.3 2017-12-02 16:41:39 +02:00
merlokk
3c9b6573ec remove show options 2017-12-02 16:24:47 +02:00
merlokk
a36b278fad add options show 2017-12-02 13:06:51 +02:00
merlokk
2e35aa3aa7 added info 2017-12-02 11:51:12 +02:00
merlokk
755c72b798 rename travis file 2017-12-01 18:57:31 +02:00
merlokk
b6c370f171 added REPOSITORY_EP var 2017-12-01 18:54:54 +02:00
merlokk
b35c11f95e init travis from https://github.com/pwpiwi/proxmark3/tree/travis_test 2017-12-01 18:49:31 +02:00
Iceman
d217282541
Merge pull request #502 from merlokk/apduhelp
added hint on `hf 14a apdu`. close #495
2017-11-30 20:04:16 +01:00
merlokk
606eddca8d added hint on hf 14a apdu. close #495 2017-11-30 19:34:20 +02:00
Iceman
dc93020701 Update fpgaloader.c (#500)
This address part1 in issue https://github.com/Proxmark/proxmark3/issues/499

Device power out 13.56Mhz when started (initialised). This output is not stopped until arbitary command is sent.
2017-11-30 12:46:40 +01:00
Iceman
653e5ed3ca
Merge pull request #488 from pwpiwi/fix_usbpower
fix: USB Power requirements
2017-11-28 21:26:57 +01:00
pwpiwi
f380317220
Change USB Configuration to "Bus Powered" 2017-11-28 21:22:29 +01:00
Iceman
14971507b1
Merge pull request #494 from qaisjp/patch-1
Make README file markdown
2017-11-26 06:15:48 +01:00
Qais Patankar
1ccdd4f631
Make README file markdown 2017-11-26 04:41:24 +00:00
merlokk
78528074b1 optimization UDOL creation. does not affect on functionality. 2017-11-25 21:17:56 +02:00
merlokk
44128a0e9a Added hf emv exec - command for execute EMV transaction
Added to `hf emv exec` MSD path for VISA and Mastercard and some other compatible EMV cards
2017-11-25 14:40:23 +02:00
merlokk
87fc2dad14 merged emvcore 2017-11-25 14:30:53 +02:00
merlokk
66efdc1f64 part of changes 2017-11-25 12:58:50 +02:00
Iceman
45eb1383e3
Merge pull request #491 from pwpiwi/mod_select
minor iso14443a timing fixes to avoid select errors
2017-11-25 09:51:39 +01:00
Iceman
137dd5826e
Merge pull request #486 from KenzyCarey/master
Add brutesim script
2017-11-24 12:39:45 +01:00
pwpiwi
47b78133a0 minor iso14443a timing fixes to avoid select errors:
* take setup frame guard time (SFGT) into account
* adjust iso14a_timeout by FPGA delays
* don't give up on first WUPA. Retry several times
2017-11-22 19:43:12 +01:00
Oleg Moiseenko
3c5fce2ba7 Add: Emv first part of commands
* hf emv search
* hf emv pse
* hf emv select
* hf emv exec command - only part of functionality
2017-11-22 06:16:33 +01:00
pwpiwi
4058a2d7df
fix: avoid SspClk overflow due to incomplete reset
* should fix watchdog reset during hf mf mifare. Thanks @iceman1001 for the hint.
2017-11-21 07:31:42 +01:00
Kenzy Carey
dfa1628ac3
Add files via upload 2017-11-17 14:42:52 -08:00
pwpiwi
0363be9358 fix: USB Power requirements
* correctly indicate the maximum current drawn from the USB bus
2017-11-17 09:13:37 +01:00
Oleg Moiseenko
c95affa8d3 minor fixes
* fix timeout set in PR #481
* fix warning in util.c printf
2017-11-15 07:49:18 +01:00
pwpiwi
db68bcdb06
Complete WTX handling 2017-11-15 07:47:18 +01:00
marshmellow42
aa264aba1d
Merge pull request #480 from pwpiwi/fix_nested
fix memory overflow in hf mf nested (issue #479)
2017-11-13 09:42:56 -05:00
pwpiwi
e537c3e894 fix memory overflow in hf mf nested (issue #479) 2017-11-12 18:08:57 +01:00
Iceman
c3511781a1
Merge pull request #478 from wsmoses/master
Fix memory bounds error
2017-11-11 22:45:37 +01:00
Iceman
230eaa5391
Merge pull request #477 from merlokk/wtx
Added work with S-Block WTX in 14a apdu on arm side
2017-11-11 22:16:19 +01:00
William S. Moses
874572d419 Fix memory bounds error 2017-11-11 16:15:29 -05:00
merlokk
ba4f95b4af added some info from @peterfillmore fork 2017-11-11 23:05:08 +02:00
merlokk
a63505c953 Added work with S-Block WTX in 14a apdu on arm side 2017-11-11 22:56:50 +02:00
Iceman
c0e852f907
Merge pull request #475 from merlokk/master
true fix #472 )))
2017-11-11 00:39:29 +01:00
merlokk
298143218a true fix #472 ))) 2017-11-11 01:28:20 +02:00
Iceman
8b5ec1f4a6
Merge pull request #474 from merlokk/df_fix
change `ul_switch_off_field` to `DropField` fix #473
2017-11-11 00:24:38 +01:00
Iceman
7c84f80657
Merge pull request #471 from marshmellow42/master
fix lf search bugs when no tag is on antenna  …
2017-11-11 00:24:20 +01:00
merlokk
872337e019 change ul_switch_off_field to DropField fix #473 2017-11-11 01:19:34 +02:00
Iceman
c425cc7efc
Merge pull request #472 from merlokk/master
fix #468
2017-11-10 23:45:45 +01:00
merlokk
77499f6fb2 fix #468 2017-11-11 00:43:29 +02:00
Iceman
d940ebfbad
Merge pull request #470 from pwpiwi/mod_indent
add: proper indentation when printing TLV objects
2017-11-10 23:21:26 +01:00
pwpiwi
33a9982c76 dump only leaf TLV data 2017-11-10 23:09:08 +01:00
marshmellow42
cb593491df fix incorrect variable name
that is what i get for going back over my code and trying to mimic the
naming style used previously...
2017-11-10 16:03:55 -05:00
marshmellow42
217cfb6b29 fix lf search bugs when no tag is on antenna
cotag read could enter endless loop, now cancels if the next bit doesn't
appear

em4x05 detection would loop due to a threshold never being met, now has
a dump out after 1000 samples tested.

fixed some indenting in hitag2 while i was reviewing that code for
potential endless loops...
2017-11-10 15:57:55 -05:00
pwpiwi
43912d6349 add: proper indentation when printing TLV objects 2017-11-10 21:54:07 +01:00
Iceman
7c8115b273
Merge pull request #466 from pwpiwi/mod_14areader
revert field on/off in hf 14a reader, fix typo
2017-11-10 20:53:20 +01:00
pwpiwi
f5adb06fae revert field on/off in hf 14a reader
fix typo
2017-11-10 20:14:00 +01:00
Iceman
e464f62258
Merge pull request #462 from pwpiwi/fix_hfmfsim
Fix hf mf sim (issue #412)
2017-11-10 18:07:25 +01:00
Iceman
881eacc8aa
Merge pull request #461 from merlokk/14a_rework3
added `hf 14a apdu` #447 part 3
2017-11-10 17:14:38 +01:00
merlokk
9658b9e137 move include modules from h to c file 2017-11-10 09:15:56 +02:00
merlokk
86a1c1dc25 eliminate double DropField command 2017-11-09 22:01:00 +02:00
merlokk
b7d3e89923 changed iso14aapdu arm side and client 2017-11-09 16:39:40 +02:00
merlokk
eb6e8de45d moved includes, added clear_trace flag (it was there...) and fixed multiapdu iso14443 stream 2017-11-03 13:42:38 +02:00
pwpiwi
82f4955245 Merge branch 'master' into fix_hfmfsim 2017-11-02 21:37:42 +01:00
pwpiwi
b35e04a7c6 fix hf mf sim:
* more timing fixes
* correctly determine correction bit (taken from iceman's fork)
* add checking of Access Conditions for Read command
* never allow reading KeyA
2017-11-02 21:29:08 +01:00
merlokk
1d6f7bc8ac added changelog 2017-11-02 14:28:05 +02:00
Oleg Moiseenko
378d3406ca
Merge branch 'master' into 14a_rework3 2017-11-02 14:14:55 +02:00
merlokk
23207d748f tlv decoder works. 2017-11-02 14:11:42 +02:00
Oleg Moiseenko
75e42ef5df added changelog (#460) 2017-11-01 20:37:18 +01:00
Oleg Moiseenko
fe6bf3c58c improve hf 14a info (#457)
* added validate_prng_nonce from iceman1001 fork
* added DetectClassicPrng from iceman1001 fork
2017-11-01 17:48:59 +01:00
Oleg Moiseenko
83df98d691 change comment in iso14443a.c (#459) 2017-11-01 17:44:43 +01:00
merlokk
499df9088d fix behavier reading iso14443-3 and iso14443-4 cards 2017-11-01 18:34:15 +02:00
merlokk
7376da5c44 revert SAK check 2017-11-01 18:22:03 +02:00
merlokk
bed3e4c20d Merge branch 'master' of github.com:merlokk/proxmark3 into 14a_rework3 2017-11-01 17:13:27 +02:00
merlokk
89ec86abd2 now SAK check is OK 2017-11-01 17:02:35 +02:00
merlokk
c5e9a0212e deleted condition in iso14a select (sak & 0x20 ==0) - error. Usually SAK = 88 2017-11-01 16:55:12 +02:00
marshmellow42
9d139870cb
Merge pull request #456 from merlokk/hfreaderfix
fixed bug with `hf search 14a`
2017-11-01 07:57:30 -04:00
merlokk
fe842bed9c fixed bug with hf search 14a 2017-11-01 13:54:03 +02:00
merlokk
a2bb2735d5 TLV decoding works 2017-11-01 13:38:29 +02:00
Oleg Moiseenko
7dac1034e5 Add hf mf info, change hf mf reader (#452)
* copy functionality from `hf 14a reader` to `hf 14a info`
* added command `hf 14a reader` with simple anticollision-select procedure.
* add parameters to `hf 14a reader`. may start and end acting as reader
2017-11-01 08:51:05 +01:00
merlokk
78a94ff902 improved GetAPDUCode() 2017-10-31 19:19:49 +02:00
merlokk
5bcb3496fa small refactoring 2017-10-31 19:11:23 +02:00
merlokk
fe346768b3 added showing apdu response codes 2017-10-31 18:14:32 +02:00
merlokk
a23f000182 move strucrture to .h file 2017-10-31 16:25:42 +02:00
merlokk
6fc6cd0f57 export apdu function 2017-10-31 16:20:23 +02:00
merlokk
d1300b47ae apdu sending refactoring 2017-10-31 16:08:58 +02:00
merlokk
8019540b19 param parsing convert to procedures 2017-10-31 15:15:57 +02:00
merlokk
f2b0169cc6 apdu works. 2017-10-31 13:28:16 +02:00
merlokk
f1a983a330 fixed bug in CmdHF14ACmdRaw: if we cant select we send command anyway... 2017-10-30 17:58:43 +02:00
merlokk
980417eacd iso14_apdu works via logical channel. not as it needs. it needs to change to raw( 2017-10-30 17:29:03 +02:00
Oleg Moiseenko
618c220c38 small fixes in ReaderIso14443a() (#446) 2017-10-29 16:34:51 +01:00
merlokk
1208cdcb45 added sketch for command hf 14a apdu 2017-10-27 19:02:45 +03:00
merlokk
7710983be3 added hf 14a apdu command. 2017-10-27 18:45:42 +03:00
Oleg Moiseenko
fefb7f5376 appveyor.yml. display return values (#451)
* display return values from commands and compare them with value. as promised in #440
2017-10-27 16:58:24 +02:00
pwpiwi
3851172d81 Revert "Comms refactor (prerequisite of libproxmark work) (#371)" (#450)
This reverts commit afdcb8c159.
2017-10-27 09:56:46 +02:00
Michael Farrell
afdcb8c159 Comms refactor (prerequisite of libproxmark work) (#371)
* Refactor the comms code only from PR#346, without comms_globals.h.
* OSX: Add note for example serial port
2017-10-26 21:54:27 +02:00
Oleg Moiseenko
e17660d5f7 code cleaning (#445) 2017-10-26 19:09:53 +02:00
Oleg Moiseenko
5d7d0c3af9 small improvement in tests (test result in green or red) (#448) 2017-10-26 18:32:18 +02:00
Iceman
8dd0118673 Merge pull request #440 from merlokk/c3
improve appveyor.yml
2017-10-26 11:46:20 +02:00
Oleg Moiseenko
8bdb6043b0 identification fix for magic chinese cards (#444)
* fixed #411
2017-10-25 07:56:03 +02:00
Iceman
5cc1ff44b4 Merge pull request #443 from doegox/flush
Flush stdout when waiting for /dev/ttyACM0
2017-10-24 14:28:16 +02:00
Philippe Teuwen
8a50d60617 Flush stdout when waiting for /dev/ttyACM0 2017-10-24 14:10:52 +02:00
pwpiwi
23af9327a5 fix hw status (and USB comm in general) (#434)
* don't ignore ReadLine() errors (Windows)
* lock CmdBuffer with Mutex
* refactor WaitForResponseTimeoutW
2017-10-24 07:48:38 +02:00
Iceman
a6d4e93cb5 Merge pull request #438 from pwpiwi/fpga_14b
FPGA changes ISO14443B:
2017-10-23 15:05:07 +02:00
merlokk
b5381d70dc added write-host for tests 2017-10-23 13:43:46 +03:00
Michael Farrell
05b6b11785 Multiple USB-CDC changes (attempt 6) (#439)
- Fix reporting of string descriptors.
- Add note about ModemManager matching on the manufacturer string.
2017-10-23 09:04:06 +02:00
merlokk
9764d3ea0e normally show powershell scripts
it needs to have no spaces at the end of lines and no `;`
2017-10-22 22:20:44 +03:00
merlokk
da36bed90d added testing timeout 40 sec to avoid hang VM 2017-10-22 21:47:19 +03:00
pwpiwi
d372569b45 FPGA changes ISO14443B:
* slightly increase reader field strength
* increase sensitivity when reading, allowing increased reading distance
2017-10-21 10:36:01 +02:00
pwpiwi
bb04ef216d small fix: make iso14a_set_timeout() external 2017-10-20 20:20:07 +02:00
Oleg Moiseenko
ef9746cb2f added CI appveyor.com (#436) 2017-10-20 19:11:02 +02:00
pwpiwi
6e49717b5e fix hf mf sim (issue #412) (#419)
* move to separate files mifaresim.[ch]
* check CRC of commands
* don't execute commands without successfull authentication
* ensure correct timing of REQA, WUPA, ANTICOL and SELECT responses
* trace reader commands immediately, only fix start time after tag response. Decreases time to be ready for next reader command.
* remove iso14443-4 remnants
* trace raw reader commands instead of decrypted ones
* some refactoring

* fix hf mf sim
* timing: decrease time to get ready for new reader commands
2017-10-20 17:55:13 +02:00
Iceman
ed6f29f317 Merge pull request #435 from ytisf/master
Fixing liblua issues
2017-10-20 17:54:36 +02:00
tisf
1df4df6d8a Fixing liblua issues
On MacOS might have issues with compilation. This should fix it in a case where liblua used is not the built in one.
2017-10-20 21:55:13 +07:00
Oleg Moiseenko
aa757f71d9 proxmark3 refactoring command line parameters (#417)
* add -c (execute command from command line)
* fix: sometimes proxmark executes command twice...
* fix: start proxmark from QT was in a strange way (if we issue command very fast - it hangs)
* added -l (execute lua script)
* rework help
* small memory management bugfix
* small fix in executing command files
* enable piping from STDIN
2017-10-20 06:49:53 +02:00
Oleg Moiseenko
36b1cdd1b4 fix fpga_comress sending no-error messages to stderr (#430) 2017-10-19 12:23:09 +02:00
Iceman
544f3fae91 Merge pull request #427 from pwpiwi/usb_mods
Improve device side USB implementation.
2017-10-18 22:08:07 +02:00
Oleg Moiseenko
0c86cb0127 Check keys in hf mf nested (issue #426)
* hf mf nested added 14a timeout for check keys
* hf mf nested added options s and ss
2017-10-18 21:44:59 +02:00
pwpiwi
f194e4290c Device side USB implementation:
* add some comments and #defines in usb_cdc.c
* use full FIFO size of 64 Bytes for device -> host transfers
2017-10-17 19:25:40 +02:00
Iceman
9d0a333449 wrong define used (#421)
The set define under the case "STD_SET_CONFIGURATION" is not the same as here.
The endpoint is configured as INTERUPT not ISOCHRONOUS
2017-10-16 18:16:39 +02:00
Iceman
a008a74541 Merge pull request #420 from merlokk/b_fix
small fix #416
2017-10-16 10:36:49 +02:00
merlokk
73d7bf75c8 small fix #416 2017-10-16 11:33:17 +03:00
Oleg Moiseenko
275d9e61c2 Check keys in hf mf nested and hf mf chk (#414)
Improve hf mf chk and hf mf nested
* hf mf chk. added interrupt of procedure by usb
* extract mifare default keys into separate module
* arm side multisector `hf mf chk`
* hf mf nested. change key search procedure
* hf mf nested. added key check after we have found a key.
* small fix hf list f
* hf mf chk. add timeout (arm side) and some tweaks.
2017-10-15 21:19:34 +02:00
Iceman
77aecdd286 Merge pull request #407 from pwpiwi/no_rats
Don't do iso14443-4 select for mifare emulations on processor cards (IDPrime, SmartMX, …)
2017-10-06 02:36:06 +02:00
pwpiwi
7085af051d fix LUA script errors 2017-10-05 18:07:26 +02:00
Oleg Moiseenko
adf023ffe3 hf mf nested add some functionality (#403)
* Added nested auto mode. it checks known keys and then launches nested
* Check if we allready have all keys after nested
2017-10-05 13:37:51 +02:00
pwpiwi
5d8f664d7a Adjust LUA scripts to new ISO14A_NO_RATS option 2017-10-04 18:28:57 +02:00
pwpiwi
c04a4b60ce Don't do iso14443-4 select for mifare emulations on processor cards (IDPrime, SmartMX, ...) 2017-10-01 17:52:10 +02:00
Iceman
5191ad9e55 Merge pull request #405 from ZenSecurity/master
Added bus blaster (http://dangerousprototypes.com/docs/Bus_Blaster) c…
2017-09-29 12:02:10 +02:00
Iceman
0060e3daa2 Merge pull request #402 from pwpiwi/env_flags
Don't ignore environment variables CFLAGS and LDFLAGS
2017-09-29 12:01:54 +02:00
Mikhail Yushkovskiy
ab92e6c301 Added bus blaster (http://dangerousprototypes.com/docs/Bus_Blaster) configuration for AT91SAM7S512 support in openocd. 2017-09-27 23:37:46 +03:00
pwpiwi
340f50a53c Don't ignore environment variables CFLAGS and LDFLAGS for tools as well 2017-09-26 18:15:19 +02:00
pwpiwi
f53eb07de0 Don't ignore environment variables CFLAGS and LDFLAGS
* they are be set by some build environments to find include and lib dirs
2017-09-26 18:06:51 +02:00
Iceman
c19f26b05d Merge pull request #393 from pwpiwi/fix_getclocktime
Fix clock_gettime() for Apple OSX
2017-09-26 17:08:50 +02:00
Fl0-0
a2d058f3aa Fix typo and gcc-7 warnings (#401)
* Fix typo in hf mf csave help
* Fix gcc 7 warning: '~' on an expression of type bool [-Wbool-operation], use logical ! not instead of ~
* Fix gcc 7 warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
* Fix gcc 7 warning: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
2017-09-26 16:36:05 +02:00
marshmellow42
1ece662f0f Merge pull request #400 from merlokk/master
fixed #395
2017-09-26 07:38:24 -04:00
merlokk
2ce43a28f7 fixed #395 2017-09-26 14:29:08 +03:00
Oleg Moiseenko
3a05a1e739 reworking magic cheneese card wipe (#365)
Implement hf mf cwipe. Remove wipe parameter from hf mf csetuid.
2017-09-22 19:40:42 +02:00
pwpiwi
d47c8c701a Fix clock_gettime() for Apple OSX
(also fixes hf mf hardnested)
2017-09-20 07:32:15 +02:00
Iceman
08b7cd17a5 Merge pull request #392 from pwpiwi/expr_fix
Fix detection of AVX512 support for Apple clang compiler
2017-09-13 19:02:05 +02:00
pwpiwi
de1e68d34b Fix detection of AVX512 support for Apple clang compiler 2017-09-12 09:09:15 +02:00
marshmellow42
8c8317a5e9 fix lf sim fpga download overwrites sim buffer (#391)
* adjust LFSim to download lf fpga prior to setting emulation buffer to prevent buffer overwrite condition if you are coming from HF fpga.
* fix lf sim big buff overwrite with fpga download. Move fix to the buffer download cmd.
2017-09-11 19:18:32 +02:00
marshmellow42
1dae9811f2 Indala fixes - set accurate preamble and start of.. (#385)
.. data for both format types (64 bit and 224 bit)
also adjust 224 bit demod and clone to output and input in PSK2 instead
of PSK1 as this appears to be most common for this format.
2017-08-27 12:10:28 +02:00
uzlonewolf
c6c0449105 Don't try to display the GUI when running in textmode (#387)
* Don't try to display the GUI when running in textmode

* Updated textmode fix to always run the GUI under Windows
2017-08-27 12:09:39 +02:00
Fl0-0
a221bacd43 Fix gcc version detection (from iceman1001 fork), fix issue #386 (#388) 2017-08-27 12:08:48 +02:00
iceman1001
14d7657703 fix: 'hf mf nested' - got an initialized bug from the monster merge 2017-08-27 00:32:22 +02:00
marshmellow42
5c814c3a9f helptext fixes (#384) 2017-08-22 18:33:12 +02:00
pwpiwi
930763e86d Use PolarSSL DES implementation (GPL 2 or later) for both client and firmware (#378)
to prevent licensing issues with ARM-Crypto-Lib (GPL 3 or later)
2017-08-22 10:04:47 +02:00
marshmellow42
fe087813f6 Merge pull request #356 from pwpiwi/low_frequencies
revert removal of quarter frequency support for hi_read_rx_xcorr.v
2017-08-21 15:29:56 -04:00
pwpiwi
d0067d0768 Fix compile issues for mfkey32 and mfkey64 after Pull Request #380 2017-08-18 07:50:03 +02:00
etmatrix
4efdfbe638 Fixes 2 bugs in mifare simulate (#380)
- Check button press when there is NOFIELD, so we can exit also without FIELD
- struct nonces_t is moved to include/mifare.h so client and arm has the same definition
2017-08-17 16:59:48 +02:00
pwpiwi
6b758d652d Prevent using x86 SIMD compiler flags on aarch64 (ARM) architecture 2017-08-16 08:50:31 +02:00
marshmellow42
f2081c4356 adjust lf simulation - fix one bug + attempt... (#369)
... to speed up the loops waiting for carrier signal to go high or low
by only checking for a halt (button press or usbpol) every 1000th loop
iteration.
some users were experiencing modulating reactions to be too slow.
2017-08-08 21:08:59 +02:00
pwpiwi
8cf533fd98 FIX: 'lf hid sim' - it now prints the id correct ref https://github.com/Proxmark/proxmark3/issues/364 2017-07-27 18:35:12 +02:00
Iceman
6f7a0f7d86 Merge pull request #362 from merlokk/master
small fix formatmifare.lua
2017-07-22 13:38:30 +02:00
merlokk
0e512a905f small fix formatmifare.lua 2017-07-21 19:36:49 +03:00
Iceman
8614a5a271 Merge pull request #361 from marshmellow42/master
fix lf get sample bits vs bytes bug
2017-07-18 09:06:49 +02:00
marshmellow42
c68f5fc7ec fix lf get sample bits vs bytes bug 2017-07-17 17:40:10 -04:00
marshmellow42
26ea310f0e Merge pull request #355 from pwpiwi/io_fix
fix lf io clone (issue #331):
2017-07-14 12:27:41 -04:00
marshmellow42
d8f2ff3293 Merge pull request #358 from Fl0-0/Fix_missing_reference_PAC_Stanley
Fix missing reference for PAC/Stanley
2017-07-14 12:24:24 -04:00
Fl0-0
48d41dc320 Fix missing reference for PAC/Stanley 2017-07-14 17:45:09 +02:00
marshmellow42
69f42a0593 add lf PAC/Stanley tag read (#354)
lf pac read - read from antenna and demod
lf pac demod - demodulate from graphbuffer
fix typo in securakey
2017-07-14 14:04:46 +02:00
pwpiwi
edf8806f15 fix lf io clone (issue #331):
- remove confusing message about simulation
- add h (help) parameter and usage text
2017-07-13 18:12:53 +02:00
pwpiwi
3f7aaf24fb revert removal of quarter frequency support for hi_read_rx_xcorr.v 2017-07-13 08:48:27 +02:00
Fl0-0
7906cb41ff Improve 'Magic' Mifare tags generation detection & hf mf c* commands magic 4k compatibility (#349)
* Improve 'Magic' Mifare tags detection

* Magic Mifare tags detection and version printing

* Magic s50/1k tag halt error correction for cload and csave

* hf mf c* commands for gen1b

* Use |= for bitwise operation

* gen1b: don't issue wipe command and don't expect response from WUPC1 magic command after a SELECT_UID: old UID display works in hf mf csetuid

* hf mf cgetsc compatibility for 4k

* hf mf csave compatibility for 4k

* hf mf cload compatibility for 4k, suppress halt errors messages for debug level 2

* Revert to MF_DBG_ERROR level in mifare_classic_halt() and don't issue the halt command for gen1b

* Improve 'Magic' Mifare tags generation detection & hf mf c* commands magic 4k compatibility
2017-07-12 15:58:32 +02:00
marshmellow42
0e2ddb4196 add data fsktonrz fsk cleaning util (#352)
add fsk cleaning / demod tool fsktonrz
- used old fskdemod for HID and adjusted it to build the tone tables for any fsk model detected or given.  using the tone tables we are able to convert the fsk to clear strong NRZ/ASK even with very weak fsk waves.
- also fixed a small textual bug in `lf search u` output
- also added more graph clearing code to help ensure the demod overlay doesn't show when it shouldn't...
- and improved strong NRZ clock detection.
- fixed bugs in places it used old static values instead of dynamic read values. and removed redundant items.
2017-07-12 07:31:42 +02:00
Iceman
53814fe4f2 Merge pull request #351 from Fl0-0/CmdEM410xBrute_mingw_fix
Fix CmdEM410xBrute string format warning
2017-07-06 09:25:03 +02:00
Fl0-0
03a4837bfa Fix CmdEM410xBrute string format warning 2017-07-05 21:16:15 +02:00
Michael Farrell
067bfc8b76 Refactoring uart interface (#341)
* uart: Major cleanups
- Adds documentation to the uart API.
- Fixes a buffer overflow issue in `uart_receive`, where the maximum parameter was ignored.
- Splits the maximum length and bytes recieved variables in `uart_receive`.
- Downsizes the receive buffer to the minimum required, saving 16MiB of RAM at runtime.
- Refactors the POSIX and Win32 implementations of uart into separate files.
- Removes the unused `uart_{get,set}_parity` functions, which were not implemented on Win32.
2017-07-05 20:22:02 +02:00
Henrik Johansson
52244230d3 hitag2 write (#310)
Usage is similar to hitagS write: lf hitag write 24 KEY pagenumber 32bitvalue
* added changlelog entry
2017-07-05 20:16:54 +02:00
marshmellow42
979c76556a fix some iclass reader bugs (#350)
endless loop in reader if no tag was found
button press on pm3 did not cancel.
led_b was left on in some cases
also moved 14b detection to last in hf search to help speed up the
command for the other tags.  14b is slow (does multiple tests)
Thanks to @Fl0-0 and @pwpiwi for their idenfication of some of the
issues.
2017-07-05 18:11:48 +02:00
Iceman
ebe9a3ba04 Merge pull request #347 from Fl0-0/master
LF EM410x bruteforce typo errors correction
2017-07-03 09:34:48 +02:00
Fl0-0
cea3dc4e9e Fix typo in helps 2017-07-03 09:16:28 +02:00
Fl0-0
e8e2cfd0f1 missing a c in the helptext sample 2017-07-03 08:56:36 +02:00
Iceman
fe8157d59e Merge pull request #343 from Fl0-0/master
LF EM410x bruteforcing function by simulating EM410x tags (1 UID/s)
2017-07-03 08:56:19 +02:00
Fl0-0
1dc0500b36 Update changelog 2017-07-03 08:04:24 +02:00
Fl0-0
2ed09d15e4 Merge remote-tracking branch 'upstream/master' 2017-07-02 17:54:35 +02:00
Fl0-0
c109ac9f65 Identation fix 2017-07-01 22:36:49 +02:00
Fl0-0
634a55aa17 Identation fix 2017-07-01 22:35:49 +02:00
Fl0-0
f800241260 Identation 2017-07-01 22:32:49 +02:00
Fl0-0
553bbf59b6 Use param_get32ex() and add c for clock parameter 2017-07-01 22:31:06 +02:00
Iceman
138927dd7b Merge pull request #345 from pwpiwi/hardnested_compress
hardnested: dramatically reduce required disk space for tables
2017-07-01 21:22:55 +02:00
Fl0-0
2e39af0739 Fix typo error 2017-07-01 19:49:02 +02:00
root
539337a7d2 EM410x bruteforcing changes: Load the whole file at once, pause delay as parameter, stop the execution on key press and EM410x conversion to signal function. 2017-07-01 17:53:06 +02:00
root
30e37e973d Merge remote-tracking branch 'upstream/master' 2017-07-01 13:57:30 +02:00
Iceman
1cbb352b71 Merge pull request #344 from pwpiwi/RasPi_fix
Fix issue #342
2017-07-01 08:08:45 +02:00
pwpiwi
4fed4488b1 Fix issue #342 2017-06-30 20:27:38 +02:00
Fl0-0
1ccba0b91b Indentation fix 2017-06-30 14:50:32 +02:00
Fl0-0
47af8c5fa9 Add EM410x bruteforcing error checks 2017-06-30 10:00:03 +02:00
Fl0-0
50acfd37e2 Add EM410x bruteforcing function by simulating EM410x tags (1 UID/s) 2017-06-30 09:17:31 +02:00
pwpiwi
7f9e4c257f hardnested: reduce disk space for tables (by > 700MBytes) and other minor changes
- compress tables
- minor changes to progress reporting
- free memory on aborts (@iceman1001)
2017-06-30 08:48:37 +02:00
marshmellow42
82e8eee62d Merge pull request #333 from micolous/osx-libedit
OSX: Disable GNU readline-specific hack when libedit is used (fixes #110)
2017-06-30 00:22:55 -04:00
Iceman
2a7861ef0a Update cmdhf14a.c
need include to detection function
2017-06-26 21:58:03 +02:00
Iceman
6100040454 Update hfsnoop.c (#338)
fix:  missed a include for usb_poll_validate_length
2017-06-26 08:37:32 +02:00
pwpiwi
893d0fcc49 Merge pull request #337 from Proxmark/iceman1001-patch-4
Iceman1001 patch 4
2017-06-26 07:50:57 +02:00
Iceman
d8e61a3004 Update aes.c (#336)
FIX:  coverity scan - improper use of sizeof
2017-06-26 00:52:09 +02:00
Iceman
06ed826c01 Update hfsnoop.c
chg:  enabled snooping function to break on receiving a usbpackage.
2017-06-25 19:39:45 +02:00
Iceman
e7fd9f5ff4 Update BigBuf.h
added the header definition
2017-06-25 19:35:59 +02:00
Iceman
f4329b1732 Update BigBuf.c
chg:  change from defines to booleans.
add: bigbuf_clear_em(),  empties the reserved emulator part only
2017-06-25 19:35:03 +02:00
Iceman
e702439e00 Update fpgaloader.c
CHG:  just making sure the bigbuff is cleared after the zlib played.  So we don't get the random noice that ppl are posting thinking they got a signal.
2017-06-25 19:30:07 +02:00
Michael Farrell
c39ce233fe OSX: delete another reference to readline 2017-06-25 21:44:08 +10:00
Michael Farrell
1a8cd8c7c4 OSX: Remove references to GNU readline as it will be no longer required 2017-06-25 12:38:42 +10:00
Michael Farrell
ed50f7f327 OSX: Disable GNU readline-specific hack when libedit is used (fixes #110) 2017-06-25 12:26:33 +10:00
Iceman
7f2114d845 Update cmdhfmfu.c (#332)
* Update cmdhfmfu.c

CHG:
   removed sniffed keys,  amiibo pwd gen algo is known.
   'hf mfu rdbl' - header output aligned
  'hf mfu dump' - header output aligned

* Update cmdhfmfu.c

chg: adjusted KEYS_PWD_COUNT accordingly
2017-06-24 11:54:42 +02:00
Iceman
b4d321bbf3 Merge pull request #330 from marshmellow42/master
bug fix for hf iclass reader and iclass detection
2017-06-23 20:25:51 +02:00
marshmellow42
34e2af02a4 bug fix for hf iclass reader and iclass detection
memory locations in code are now accurate and the CC output is not
corrupted by the config's crc.

also the looping and flags for what to read are now correctly
implemented in the code.
2017-06-23 13:50:25 -04:00
Iceman
c0a2ae50da Merge pull request #329 from marshmellow42/master
iclass - updates
2017-06-22 01:13:07 +02:00
marshmellow42
67e344df90 iclass - updates
clean up output
allow readblock without authenticating (can read blocks 0, 1, 2, 5
without authenticating.)
add Application Issuer Area to reader output and use it to attempt to
identify legacy vs NOT legacy.
2017-06-21 17:07:55 -04:00
marshmellow42
bf8243475b some coverity fixes plus fix fdx help (#328)
* coverity fixes

cmdhflegic- indications are the i in calls to data_buf[i] could = 1052
and overflow the array.
cmdhfmfhard - +1 to add space for string null terminator - should we add
the 0 terminator value too?
reveng.c - memory leak
util.c - fix potential overflow of array buf[]
util_posix.c - possible integer overflow

* fix help errors

* fix sprint_hex_ascii

again
and this function is not even used anywhere... yet...
2017-06-20 17:25:08 -05:00
marshmellow42
58c00ce7fc Merge pull request #322 from Proxmark/iceman1001-patch-2
Update 77-mm-usb-device-blacklist.rules
2017-06-19 09:01:44 -04:00
marshmellow42
0c29544f64 Merge pull request #321 from Proxmark/iceman1001-patch-1
BUG: 'hf mf mifare'
2017-06-16 14:46:50 -04:00
Iceman
513c6c98af Update 77-mm-usb-device-blacklist.rules
fix: updated the blacklist rules file with the updated usb_cdc vid/pid values
2017-06-16 19:48:18 +02:00
Iceman
84ca27b33a BUG: 'hf mf mifare'
BUG: 'hf mf mifare' ,  wrongly identify success when faulty key is found
https://github.com/Proxmark/proxmark3/issues/320
2017-06-16 14:43:53 +02:00
marshmellow42
e5a15888b6 Merge pull request #319 from Proxmark/iceman1001-patch-2
bug:  hf mf chk - wrong size
2017-06-13 17:23:24 -04:00
marshmellow42
0efcb69128 Merge pull request #317 from Proxmark/iceman1001-patch-1
bug;  Check keys params
2017-06-13 17:22:44 -04:00
Iceman
1e11e5d762 bug: hf mf chk - wrong size
bug:  'hf mf chk' - size of keycounter variable is too small for dictionary files larger than 256rows.
2017-06-12 15:07:00 +02:00
Iceman
4419118038 bug; Check keys params
CMD_MIFARE_CHKKEYS command has a different arg1, arg2 meaning nowdays.
Arg0  =  keytype << 8 | blockno 
arg1  = clear trace

In lua its name arg1, probably with lua's startindex is 1...
2017-06-12 12:21:01 +02:00
Iceman
8040afa5ba Merge pull request #315 from marshmellow42/master
fix compile issues on OS X 10.11
2017-06-09 15:50:55 +02:00
Iceman
3e7df26213 updated onlineshops
Updated the onlineshops,   same info here as on www.proxmark.org  order page. 
Two have been removed because of bad reviews and no lifesign.
2017-06-09 09:59:30 +02:00
marshmellow42
087c8bf330 fix compile issues on OS X 10.11
OSX 10.11 does not have clock_gettime()
clang <= 8.0.0 has a bug in __builtin_cpu_supports() and it doesn't
function.
see https://llvm.org/bugs/show_bug.cgi?id=25510
2017-06-08 17:07:14 -04:00
pwpiwi
eabbb166f0 Add two missing bitflip state tables. Update .gitignore 2017-06-08 15:32:24 +02:00
pwpiwi
b63bd049fc Update CHANGELOG.md to release 3.0.1 2017-06-08 14:18:25 +02:00
Iceman
9a15745577 Merge pull request #313 from pwpiwi/fix_memalign
fix MacOS compile errors by replacing memalign() with posix_memalign()
2017-06-08 09:40:57 +02:00
pwpiwi
c3d117a8a1 fix MacOS compile errors by replacing memalign() with posix_memalign() 2017-06-08 08:26:20 +02:00
pwpiwi
ec9c71129f Fix compile errors with MacOS (#312)
* Fix compile errors with MacOS
- _POSIX_C_SOURCE must not be defined for num_CPU()

* separate util_posix.c require changes in tools directory as well

* remove unnecessary self-include
2017-06-07 22:35:20 +02:00
pwpiwi
f9a12dfac2 Merge branch 'master' of https://github.com/Proxmark/proxmark3 2017-06-07 22:32:41 +02:00
Iceman
6b6aafabcf Merge pull request #311 from marshmellow42/master
a few coverity scan bug fixes
2017-06-07 22:31:52 +02:00
pwpiwi
59d86bafb7 Updated CHANGELOG to new release 3.0.0 2017-06-07 22:31:15 +02:00
marshmellow42
2c51d4cfa6 remove warning about non-static init...
warning was: non-static data member initializers only available with
-std=c++11 or -std=gnu++11
2017-06-07 15:42:28 -04:00
marshmellow42
5dd5bfb268 attempt to fix compile error gcc lt 4.9 (#306) 2017-06-07 07:36:22 +02:00
Iceman
d4625ea408 Merge pull request #304 from pwpiwi/fix_nethunter
fix compile errors on non-Intel CPUs (issue #303)
2017-06-06 22:13:10 +02:00
marshmellow42
dab1c6f5e9 lf presco help and command loop !=
thanks to @iceman1001 for noticing.
2017-06-06 13:30:06 -04:00
marshmellow42
ebf93643fa allow hex input again to lf presco 2017-06-06 13:12:25 -04:00
marshmellow42
b4810303f5 needs a ; ... ...
...
2017-06-06 12:57:11 -04:00
marshmellow42
e57c8b2e56 more coverity fixes
plus fix some spacing in functions i touched.
2017-06-06 12:45:00 -04:00
pwpiwi
af7a1f7004 fix compile errors on non-Intel CPUs:
- client/Makefile: don't compile for different SIMD instruction sets if non-Intel
- hardnested cores: provide non-SIMD versions of core functions
2017-06-06 18:38:07 +02:00
marshmellow42
3d542a3dfa coverity scan bug fixes
mfu keyNo buffer overflow
mf reader attack key count reduced to not overrun c.d.asBytes buffer.
2017-06-06 12:12:18 -04:00
marshmellow42
c2ca50419d Merge pull request #302 from pwpiwi/fix_QtThreads
fixing the crash on exit (issue #284)
2017-06-04 19:53:28 -04:00
pwpiwi
5acd195d0f fixing the crash on exit 2017-06-04 09:30:49 +02:00
Iceman
a4a6780efe Merge pull request #301 from marshmellow42/master
make hardnested compile on gcc 4.9.2
2017-06-02 09:20:51 +02:00
marshmellow42
e5baf1ef79 adjust hardnested compiler fix to accurate version
avx512f is only available in gcc 5.3 and above.
2017-06-02 00:17:57 -04:00
marshmellow42
f950ce1cb9 make hardnested compile on gcc 4.9.2
plus add Td to gitignore.
2017-06-01 23:08:01 -04:00
pwpiwi
8224307338 Updated CHANGELOG.md 2017-06-01 15:38:00 +02:00
Iceman
c7b2751136 Merge pull request #297 from pwpiwi/hardnested
Implement hf mf hardnested
2017-06-01 14:34:43 +02:00
Gator96100
43c3b944e4 fix wrong vid & pid values (#298) 2017-05-31 21:40:27 +02:00
pwpiwi
1985eb7cbd Fix client Makefile 2017-05-31 08:27:08 +02:00
pwpiwi
c48c4d7856 New: implementing hf mf hardnested
This implements the attack described in
	Carlo Meijer, Roel Verdult, "Ciphertext-only Cryptanalysis on Hardened
	Mifare Classic Cards" in Proceedings of the 22nd ACM SIGSAC Conference on
	Computer and Communications Security, 2015
It uses precomputed tables for many bitflip properties (not only two as in the paper)
and is therefore quite efficient. To prevent failing it doesn't do
differential analysis with several nonce bytes' Sum(a8) properties (each of them
may be wrongly guessed) - instead it concentrates on one nonce byte and tries all
Sum(a8) property guesses sequentially (ordered by probability). The brute force phase
makes use of aczid's bit sliced brute forcer (https://github.com/aczid/crypto1_bs).
Includes runtime CPU-detection to leverage modern (and old) SIMD instructions
with a single executable.
2017-05-31 07:30:56 +02:00
ikarus
c87c452120 Fix increment on bool variable (#294) 2017-05-26 11:26:27 +02:00
pwpiwi
b535053a77 fix hf 15 commands (#293) 2017-05-26 07:10:30 +02:00
marshmellow42
a5eb7820a5 Merge pull request #289 from patrickdk77/master
Add needed header files to proxguiqt
2017-04-28 12:25:10 -04:00
patrickdk
b8208bda88 Add needed header files to proxguiqt 2017-04-28 11:14:03 -04:00
Iceman
a8bd358225 Merge pull request #287 from pwpiwi/fix_usb
fix USB descriptors
2017-04-27 21:31:59 +02:00
pwpiwi
f9e2c24b01 reenable build in old proxspace environment (#286)
* reenable build in old proxspace environment
(use -std=c++11 and -fPIC options for Qt5 only)

* fixing the fix...
2017-04-24 18:33:55 +02:00
pwpiwi
3a89d04c7f more fixes to USB communication
- use modified UDP_GET/UDP_SET_EP_FLAGS macros from @iceman1001's branch
2017-04-24 18:16:47 +02:00
pwpiwi
1f42ccddfb fix USB descriptors
- indicate compliance with USB release 2.0
- set correct vendor and product IDs
- indicate power consumption (500mA)
- add String Descriptor 0 indicating supported languages
- add String Descriptors for Manufacturer and Product
2017-04-24 14:19:39 +02:00
marshmellow42
ebcc86a2fa Merge pull request #281 from brianredbeard/lf-script
contrib: LF Programming script
2017-04-20 13:17:29 -04:00
pwpiwi
b62b5e2527 Merge pull request #277 from pwpiwi/clang_warnings
fix clang compiler warnings (including fixing a bug revealed in cmdhftopaz.c)
2017-04-19 18:11:46 +02:00
pwpiwi
24aa0a5733 Merge pull request #282 from Proxmark/graphwork2
Implement graph improvements
2017-04-19 18:11:07 +02:00
marshmellow42
3759e8a02d Remove built file 2017-04-18 23:59:40 -04:00
marshmellow42
9c44a9b6ca fix .gitignore changes 2017-04-18 23:43:42 -04:00
marshmellow42
3fc4596f2c fix makefile to allow make of overlays.ui
to ui_overlays.h
add ui_overlays.h to .gitignore
should now compile to whatever qt version you have. (as long as it is
compatible with the overlays.ui file...)
2017-04-18 23:41:38 -04:00
Brian 'Redbeard' Harrington
79b19c5f90 contrib: LF Programming script
Submitting a well documented Lua script whose purpose is to do
bulk, repeated, sequential programming of RFID tags.  Could be useful
for users of the ACCX Open Access 4.0 or other simple RFID systems.

Tags programmed with this would potentially be vulnerabile to bisection
attacks, etc... But honestly, they likely would have been anyway.

To use run from within the proxmark3 client:

```
proxmark3> script run lf_bulk_program.lua  -b 1000 -c 5 -f 23
--- Executing: lf_bulk_program.lua, args '-b 1000 -c 5 -f 23'
Press enter to program card 1000:23 (hex: 0020042e07d1)

Cloning tag with ID 20042e07d1
Press enter to program card 1001:23 (hex: 0020042e07d2)

Cloning tag with ID 20042e07d2
Press enter to program card 1002:23 (hex: 0020042e07d4)

Cloning tag with ID 20042e07d4
Press enter to program card 1003:23 (hex: 0020042e07d7)

Cloning tag with ID 20042e07d7
Press enter to program card 1004:23 (hex: 0020042e07d8)

Cloning tag with ID 20042e07d8

-----Finished
```
2017-04-18 11:56:21 -07:00
marshmellow42
3fd7fce4ac new grid X offset calcs to fix some issues
also fixed a save_restore issue with grid alignments
now save_restoreGB() saves/restores offset values
added macro enumeration of SAVE vs RESTORE for save_restore commands.
2017-04-17 18:37:23 -04:00
marshmellow42
999d57c201 fix y grid +
and move em4x50 saveGB to allow graph restore after lf search
clean up plotgraph unused code.
should be done for a bit...
2017-04-16 00:26:26 -04:00
marshmellow42
537f80f2c8 adjust lf search to not use save/restore if...
offline or '1' entered
this allows the graph restore button to continue functioning after a `lf
search 1`
2017-04-15 21:40:05 -04:00
marshmellow42
1c70664ae7 finish FSK graph index changes 2017-04-15 16:18:54 -04:00
marshmellow42
b760f0ffd8 cannot seem to get uic to work for ...
... different qt versions in the make file correctly...
so, make the ui_overlays.h file version generic.  maybe...
2017-04-15 13:40:49 -04:00
marshmellow42
2c441f573c attempt ui_overlays.h qt4 version 2017-04-15 13:12:56 -04:00
marshmellow42
27882d378b add uic make ui_overlays.h
to makefile
2017-04-14 10:31:00 -04:00
marshmellow42
1a3c006469 maybe fixed loading/unloading bug. 2017-04-14 09:53:36 -04:00
marshmellow42
2deb4b6b46 Merge pull request #278 from marshmellow42/graphwork
Update Graphing Part1
2017-04-13 17:25:24 -04:00
marshmellow42
c4809fd411 Merge branch 'graphwork2' into graphwork 2017-04-13 17:24:33 -04:00
marshmellow42
f516ff0895 a few notation fixes 2017-04-13 17:16:34 -04:00
marshmellow42
c4f51073fc combine autocorr, dirth functions
fix lfdemod bug
add askedge to overlays (remove askdemod)
2017-04-13 10:33:18 -04:00
marshmellow42
9fe4507c03 update more demods for graphing
still todo fsk based tag demods (like HID, AWID, IO, Pyramid...)
2017-04-12 17:55:31 -04:00
marshmellow42
b8fdac9e6f apply @holiman s graph changes +
add demod data to graph.
some bugs are known:
if you close the graph window data plot will not bring it back.
exiting the application without closing the widget form results in
error.
autocorrect graph y labels are ugly
form has old askdemod tab.
sticky button purpose not defined/labeled well.
doesn't clear s_Buff when new graph loaded or sampled.
probably more...
2017-04-12 14:35:07 -04:00
marshmellow42
bb4e6dbd62 align clock grid with demods on graph (#276)
* align clock grid with demods on graph

* proper initialized values
2017-04-12 05:48:49 +02:00
marshmellow42
3fe7103959 proper initialized values 2017-04-11 21:51:31 -04:00
pwpiwi
31a29271b9 fix clang compiler warnings (including fixing a bug revealed in cmdhftopaz.c) 2017-04-11 18:55:33 +02:00
marshmellow42
0f321d631a align clock grid with demods on graph 2017-04-11 10:34:43 -04:00
pwpiwi
8aee1b8418 avoid vast number of warnings with clang compiler 2017-04-11 07:05:22 +02:00
pwpiwi
3472ebe528 Compatibility fixes for Qt5 (#271)
* Compatibility fixes for Qt5
- make Qt detection in client/Makefile independent of OS
- added -std=c++11 and -fPIC as compiler options (required by some Qt versions, breaks compiling with old ProxSpace environment)
2017-04-11 06:58:20 +02:00
pwpiwi
68541dddc2 Merge branch 'master' of https://github.com/Proxmark/proxmark3 2017-04-10 19:37:05 +02:00
pwpiwi
4a6bc37e70 fix missing terminating 0 in my_executable_directory (thanks @iceman1001).
fix warning about const used twice in get_my_executable_path() and get_my_executable_directory().
2017-04-10 18:44:27 +02:00
pwpiwi
88499d8694 Merge pull request #274 from marshmellow42/master
lf read adjustments
2017-04-10 18:01:04 +02:00
marshmellow42
90e9da2566 fix length test
thanks @pwpiwi for catching what i missed.
2017-04-10 11:38:11 -04:00
marshmellow42
e8647c5764 fix silent option for getSamples 2017-04-07 18:10:01 -04:00
marshmellow42
f9a6e84c56 update changelog 2017-04-07 18:05:23 -04:00
marshmellow42
f1004b345e fix buffer length bugs
adjust lf search a little as to when the chiptype check happens
2017-04-07 18:00:55 -04:00
marshmellow42
0aed2199a4 fix pskclockdetect bug 2017-04-07 17:41:22 -04:00
marshmellow42
b9957414a5 lf read adjustments
add parameter for # bits to read
auto get samples after lf read/snoop (don't need to do a `data samples`
anymore)
add safe function to get DemodBuffer
add some lf demod comments and apply new lf_read function instead of
read then get samples.
fixed output bug in lf t55xx config print
fixed small bug in lf t55xx detect during ST check
2017-04-07 17:28:12 -04:00
marshmellow42
bed24f53c2 no longer need doT55x7Acquisition... 2017-04-05 21:37:04 -04:00
marshmellow42
2229ee897e adjust t55x7 testmode write timing 2017-04-05 21:19:48 -04:00
Iceman
ebfb4447b8 Merge pull request #268 from marshmellow42/master
various lf bug fixes and improvements
2017-04-05 15:41:16 +02:00
marshmellow42
605524b131 fix command help
add comments in changelog
2017-04-04 17:34:15 -04:00
marshmellow42
bf85d22f96 fix bug in st detect +
adjust nrz t55xx detection to reduce false positives on weak antennas
adjust t55xx read wait to get past initial startup wave.
2017-04-04 17:22:21 -04:00
marshmellow42
b97311b1bd lf improvements
fix noralsy demod bug (st should be true)
fix sprint_bin_break bug (didn't print last bit)
add a function to save/restore demodbuffer
remove redundant countFC call in PSKDemod
clean up pskclockdetect functions
fix indala26decode bug (end of data sometimes not correct)
improve PSK detection / demodulation
improve NRZ detection
improve t55xx commands & fix a few bugs
add t55xx page1 detection - added it to lf search
added experimental t55xx testmode write
2017-04-04 11:52:10 -04:00
pwpiwi
b3ec0b3d4f Merge pull request #266 from marshmellow42/master
a few more tools for em4x05 writing
2017-04-01 09:44:17 +02:00
marshmellow42
6a772a1273 add verification data was entered-lf em 4x05 write 2017-03-31 12:52:30 -04:00
marshmellow42
51b614aa75 fix return value for error. 2017-03-31 12:22:30 -04:00
marshmellow42
5249ff940f Merge remote-tracking branch 'upstream/master' 2017-03-31 12:18:50 -04:00
marshmellow42
4ab135c0cd a few more tools for em4x05 writing.
ready to begin coding cloning cmds to em4x05.
2017-03-31 12:14:28 -04:00
pwpiwi
fb9acd4588 Update/cleanup Makefiles (#265)
- add new target "make mfkey" to build mfkey32 and mfkey64
- include above when "make all"
- fix Qt detection for Kali Linux
- create and use dependency files when building client
- create client/lualibs/usb_cmd.lua from include/usb_cmd.h when building client
- add Windows *.exe files with "make tarbin"
- For the time being don't include Makefile.common in Makefile and client/Makefile
- set com3 as default flashing port for Windows (including mingw)
- remove static targets snooper and cli. Remove their sources as well.
2017-03-31 16:04:04 +02:00
marshmellow42
b642ce7ab5 Merge pull request #264 from qweenwasabi/master
Update README.txt
2017-03-30 23:12:22 -04:00
marshmellow42
fa2aab705b Fix data mtrim (#262)
I don't even know what happened there...
2017-03-30 22:23:02 +02:00
Jacky
425b6c0eb0 Update README.txt 2017-03-30 12:51:49 -07:00
marshmellow42
3991b2ec6a Fix data mtrim
I don't even know what happened there...
2017-03-30 12:05:03 -04:00
m2otech
1f1f1955dc Fixed compile error in MinGW (#260)
* Fixed compile error in MinGW

Some versions of MinGW miss some definitions. In order to be able to
compile I redefined a function and added an explicit include. It is only
a quick workaround, as other people also seemed to have the same
problem. It should be checked whether a better solution is possible.

* Removed _ftime_s redefine, calling _ftime directly
2017-03-30 03:39:39 +02:00
Iceman
f25c62c5ec Merge pull request #256 from pwpiwi/fast_select
add: iceman1001's idea to reuse @pwpiwi's fast select without anticol…
2017-03-29 17:36:37 +02:00
Iceman
06da1c3f4b Merge pull request #259 from marshmellow42/master
fix/update removeParity & fix securakey detection
2017-03-29 17:12:55 +02:00
marshmellow42
f2ea55fb3c fix/update removeParity & fix securakey detection 2017-03-29 10:02:29 -04:00
Iceman
2938b3cb12 Merge pull request #258 from marshmellow42/master
Add lf jablotron & lf noralsy tag definitions/cmds
2017-03-29 07:39:40 +02:00
marshmellow42
c3caf0409c add lf securakey
still unknown - checksum and how FC relates to printed FC/Code

also removed noralsy extra ST check (i was tired...)
2017-03-29 00:37:16 -04:00
marshmellow42
199c74a47f fix build error on kali in new noralsy 2017-03-28 18:15:43 -04:00
marshmellow42
a9968da347 add jablotron+noralsy lf tag definitions/cmds
Thanks to @iceman1001 for most of the code.
Jablotron is complete
noralsy is mostly known - a few bits are still unknown.
2017-03-28 18:01:45 -04:00
Iceman
160dba8697 Merge pull request #257 from marshmellow42/master
split lf paradox/nexwatch into own files
2017-03-28 16:04:27 +02:00
marshmellow42
b2f565142c fix copy paste header issue
thanks @iceman101 for noticing.
since i forgot to remove it from cmddata.h it didn't show during
compile.
2017-03-28 09:11:29 -04:00
marshmellow42
5bce72d5e3 split lf paradox/nexwatch into own files
see changelog.md for cli changes!
2017-03-27 18:04:20 -04:00
pwpiwi
de77d4acde add: iceman1001's idea to reuse @pwpiwi's fast select without anticollision to speedup hf mf chk
(see http://www.proxmark.org/forum/viewtopic.php?id=2920)
2017-03-27 10:29:44 +02:00
Iceman
9331855865 Merge pull request #254 from marshmellow42/master
fix indentation warning
2017-03-26 23:39:37 +02:00
marshmellow42
488d309804 fix indentation warning
thanks to piwi for finding.
2017-03-26 17:35:16 -04:00
marshmellow42
8169040a0a Merge pull request #253 from marshmellow42/master
fix missing header
2017-03-26 13:35:32 -04:00
marshmellow42
3e8c61a522 fix missing header
http://www.proxmark.org/forum/viewtopic.php?pid=26786#p26786
2017-03-26 13:34:38 -04:00
Iceman
79375850fd Merge pull request #252 from marshmellow42/master
adjust lf menu descriptions
2017-03-26 15:24:07 +02:00
marshmellow42
9b99a6dbdb adjust lf menu descriptions
RFIDs for tag formats that can be emulated by many chips
CHIPs for chip specific commands
2017-03-26 08:46:45 -04:00
Iceman
d95878f802 Merge pull request #251 from marshmellow42/master
split fdx-b demod to its own file
2017-03-26 14:35:42 +02:00
marshmellow42
4db6f3bbb9 split fdx-b demod to its own file
added @iceman1001 s read/sim/clone commands for fdx--b
check changelog.md for cli changes!
2017-03-26 08:09:40 -04:00
Iceman
7cd25ae5a3 Merge pull request #250 from pwpiwi/fix_mfkey
fix mfkey tools (issue #247)
2017-03-26 13:05:26 +02:00
pwpiwi
dc2349ae77 fix mfkey tools (issue #247)
- add -std=c99 -D_ISOC99_SOURCE to compiler flags
- fix: include <string.h> instead of <strings.h> in mfkey64.c
2017-03-26 12:28:07 +02:00
Iceman
1ee7925609 Merge pull request #249 from pwpiwi/parity
Refactor parity functions
2017-03-26 08:28:43 +02:00
Iceman
fecfd86d3d Merge pull request #248 from marshmellow42/master
Split data askgproxiidemod to own file
2017-03-26 08:26:30 +02:00
pwpiwi
1f065e1dad Refactor parity functions
- get rid of __asm function in crapto1.h, use gcc builtin function instead
- make parity functions available in common directory
2017-03-25 22:03:17 +01:00
marshmellow42
946a84c35b Split data askgproxiidemod to own file
added lf gproxii read (from antenna)
fixed a few copy paste issues in the comments of some lf files
2017-03-25 15:51:31 -04:00
Iceman
a7e0d39ce3 Merge pull request #246 from marshmellow42/master
hitag sim fix

mea culpa.
2017-03-25 13:12:05 +01:00
marshmellow42
28598e80c0 hitag sim fix
from
e1778858dd
and http://www.proxmark.org/forum/viewtopic.php?pid=26733#p26733
sim mode should not have the reader field on.
2017-03-25 07:49:53 -04:00
Iceman
edf751bb62 Merge pull request #245 from marshmellow42/master
split lf indala[cmd] to lf indala [cmd]
2017-03-25 07:28:53 +01:00
marshmellow42
0fb65a262b split lf indala[cmd] to lf indala [cmd]
see changelog.md for cli changes!
2017-03-24 19:18:33 -04:00
Iceman
f513388ee0 Merge pull request #243 from pwpiwi/cleanup
Deduplicate mfkey32 and mfkey64
2017-03-24 08:19:23 +01:00
pwpiwi
42a6a3f87b Remove duplicate #include stdio.h 2017-03-24 07:53:52 +01:00
Iceman
41f4bcabc6 Merge pull request #244 from marshmellow42/master
fix lf file includes to include own .h
2017-03-24 07:46:34 +01:00
marshmellow42
2b4898ec71 fix lf file includes to include own .h
thanks @iceman1001 for noticing.
2017-03-23 22:32:38 -04:00
pwpiwi
4cb4b588c2 Deduplicate mfkey32 and mfkey64
- rename client/nonce2key.[ch] to mfkey.[ch]
- leave only main() wrapper in tools/mfkey
- add mfkey32 and mfkey64 to .gitignore
2017-03-23 18:38:17 +01:00
pwpiwi
bd2797de15 fix: compile issue on RasPi (http://www.proxmark.org/forum/viewtopic.php?id=4678) 2017-03-23 06:45:42 +01:00
pwpiwi
275111f6ff Merge pull request #242 from marshmellow42/master
move viking demod to respective file
2017-03-23 06:38:22 +01:00
marshmellow42
f2fc0a9c4d move viking demod to respective file
see changelog.md for cli changes!
2017-03-22 22:59:55 -04:00
Iceman
9b952b29eb Merge pull request #241 from pwpiwi/ukbhit_fix
fix: ukbhit() for OS X
2017-03-22 22:39:28 +01:00
pwpiwi
dc0bd4169f Merge pull request #240 from marshmellow42/master
split io demod/pyramid demod to respective files
2017-03-22 22:27:02 +01:00
marshmellow42
cf4640b973 split io demod/pyramid demod to respective files
out of cmddata.c / data cmds
see changelog.md for cli changes as options have changed!
2017-03-22 17:16:43 -04:00
pwpiwi
8c0ccdef35 fix: ukbhit() for OS X
- don't use CMIN and CTIME
- corrected comments
2017-03-22 22:15:24 +01:00
Iceman
bcec0edb97 Merge pull request #239 from marshmellow42/master
split hid demod/awid demod to respective files
2017-03-22 21:02:52 +01:00
marshmellow42
ecbf82fe20 fix headers 2017-03-22 15:54:32 -04:00
marshmellow42
6cd2eef44b split hid demod/awid demod to respective files
NOTE: see changelog.md for cli changes
2017-03-22 15:49:01 -04:00
Iceman
2f337fe8a3 Merge pull request #237 from marshmellow42/master
move em410x demods to cmdlfem4x.c from cmddata.c
2017-03-22 15:51:00 +01:00
marshmellow42
35aa230ee4 move em410x demod functions to cmdlfem4x.c
from cmddata.c
NOTE: see changelog.md for command line changes!
2017-03-21 18:42:11 -04:00
marshmellow42
bad2eb8587 Merge remote-tracking branch 'upstream/master' 2017-03-21 10:40:29 -04:00
pwpiwi
7ac59a82ab Merge pull request #235 from marshmellow42/lfdemod_refactors
lfdemod refactor
2017-03-21 15:38:17 +01:00
marshmellow42
86b8ecb56e adjust ManchesterEncode
removed dead size check
added a max size of 2k input bits (4k out)
this shouldn't overload the array memory passed to it typically...
2017-03-21 09:53:14 -04:00
Iceman
bea6e7b0b6 Merge pull request #234 from pwpiwi/nonce2key
Code cleanup: Refactoring nonce2key
2017-03-21 08:49:27 +01:00
marshmellow42
2d42ea1e4d add bitswap option for lf em 4x05write (#236)
default read mode of this chip outputs in reverse order...  so offer the
option to program in reverse order
2017-03-21 08:26:26 +01:00
pwpiwi
7779d73c71 Code cleanup: Refactoring nonce2key
- include nonce2key() in mifarehost.c
- remove tools/nonce2key
- simplify mifare_autopwn.lua
2017-03-20 21:16:57 +01:00
pwpiwi
de867f502f fix: crapto3.3 sometimes crashing with hf mf mifare on Fudan clones (no par, all NACK) (#233)
added readme.txt again in tools/nonce2key
2017-03-20 21:05:26 +01:00
marshmellow42
ec187c2f9f line break 2017-03-15 11:07:52 -04:00
marshmellow42
6f36848f9e refactor pskdemod - remove nrz.._ext 2017-03-15 10:53:32 -04:00
marshmellow42
56de46b466 further refactor 2017-03-14 17:08:58 -04:00
marshmellow42
d87bf1567a move new functions to utilities area 2017-03-14 16:24:14 -04:00
marshmellow42
c83d6dc6fa continue refactor detectST
detectST should be done now...
2017-03-14 16:20:15 -04:00
marshmellow42
c9ad641b61 Merge remote-tracking branch 'upstream/master' 2017-03-14 14:48:31 -04:00
marshmellow42
713045f819 add bitswap option for lf em 4x05write
default read mode of this chip outputs in reverse order...  so offer the
option to program in reverse order
2017-03-14 14:42:01 -04:00
marshmellow42
cb86f8d69f wasn't ready for these yet... 2017-03-14 13:18:20 -04:00
marshmellow42
127f149075 add first attempt at lf miller decoding
don't have any tags capable to test and not yet hooked up to data
rawdemod...
2017-03-14 13:16:30 -04:00
marshmellow42
549daaf778 fixed bug in new refactored detectST
forgot to return i...
2017-03-13 13:27:38 -04:00
marshmellow42
d5051b9817 meant to put clock detection before demods
... fixing that.
no code changed here...
2017-03-12 23:11:52 -04:00
marshmellow42
bf74114d50 refactor detectST a little...
+ a little more shuffling
2017-03-12 22:57:01 -04:00
marshmellow42
4d3c179669 re-organize lfdemod.c
sorry but it was ugly  (still is... but i can get to things easier)
2017-03-12 22:47:50 -04:00
pwpiwi
02069dbbdb fix: add missing #includes 2017-03-12 18:39:47 +01:00
pwpiwi
0691975406 fix: add missing #includes 2017-03-12 18:36:24 +01:00
pwpiwi
acf0582d53 Provide msclock() as Milliseconds timer for performance measures (#231)
- don't use clock(). It has different functionalities in Windows and Linux
- move sleep functions to util.h
2017-03-12 15:06:27 +01:00
pwpiwi
0ca9bc0e99 Upgrade crapto1 library to v3.3 (#232)
- fix standalone tools mfkey32, mfkey64 and nonce2key to use common crapto1 library
- fix compiler warnings in tools/mfkey/mfkey64.c and tools/nonce2key/nonce2key.c
- allow crapto1.c to compile on ARM hosts
- add @iceman1001's readme.txt to tools/mfkey
2017-03-12 15:05:54 +01:00
marshmellow42
669959bc5c started to enable demod graphing
first step: find graph start position from each rawdemod -now complete.
todo: apply to each individual demod
todo: graph it
2017-03-11 19:21:53 -05:00
pwpiwi
62fab50902 Create directory client/obj/crapto1 (missing in commit 33443e7) 2017-03-11 08:50:32 +01:00
pwpiwi
33443e7caa Code cleanup: deduplicate crapto1 library (#228)
- merge the existing 4 crapto1 sources into common/crapto1
2017-03-09 11:12:50 +01:00
Iceman
a3bd24b5dc Merge pull request #230 from zhovner/master
Adding homebrew tap method for macOS
2017-03-08 12:20:47 +01:00
Pavel Zhovner
45095b0178 Adding homebrew tap method for macOS 2017-03-08 14:16:33 +03:00
Iceman
6143f8ccf1 Merge pull request #229 from marshmellow42/master
add iceman1001 s lf visa2000 commands
2017-03-08 06:42:08 +01:00
marshmellow42
8b6abef506 add iceman1001 s lf visa2000 commands
-reset my fork due to corruption - now add back in the lf visa
commands...
also adjusts lfdemod all detect clock functions to always return a
starting point of the clock detected ( for graphing purposes)
2017-03-07 08:48:16 -05:00
pwpiwi
300bb58ac1 Merge pull request #227 from pwpiwi/client_fixes
Client code cleanup:
2017-03-06 22:19:15 +01:00
pwpiwi
7cb8516cb5 Client code cleanup:
- cleanup some header files and respective #includes
- rearrange functions (definition before first use)
- use SCNxxx instead of PRIxxx macros in scanf()
- use stdbool true/false instead of self defined TRUE/FALSE
2017-03-06 21:03:13 +01:00
Iceman
7ea23ef5b3 Merge pull request #226 from pwpiwi/fix_defines
Fix some #defines
2017-03-06 20:46:09 +01:00
Iceman
571324a5c4 Merge pull request #225 from pwpiwi/armsrc_header_fixes
Remove local armsrc/stdint.h and fix some other #includes
2017-03-06 20:45:58 +01:00
pwpiwi
c44c2f04d9 Fix some #defines
- Use -D_ISOC99_SOURCE instead of -D__USE_MINGW_ANSI_STDIO=1
- WIN32 is deprecated. Use _WIN32 instead
2017-03-06 19:55:23 +01:00
pwpiwi
b8e461ff61 Remove local armsrc/stdint.h and fix some other #includes 2017-03-06 19:22:35 +01:00
Iceman
8a8e7c6914 Merge pull request #223 from 4m4rOk/master
Typo fix for CmdPing
2017-03-04 13:54:44 +01:00
Luca
6ef3f9f219 Typo fix for CmdPing
Ping successfull -> Ping successful
2017-03-04 13:38:57 +01:00
pwpiwi
23bd68f944 Merge pull request #221 from jamchamb/clean-mfu-dump
Clean mfu dump output
2017-03-04 12:48:37 +01:00
James Chambers
d172c17ca4 make clean_ascii a util function 2017-03-03 18:04:58 -05:00
James Chambers
4bbf5ad17d clean up unprintable characters in MFU dump output 2017-03-03 17:38:51 -05:00
pwpiwi
f76d6fae10 Merge pull request #220 from marshmellow42/master
small patches and small added features listed below:
2017-03-01 07:08:50 +01:00
marshmellow42
ebd95febb8 update changelog 2017-02-28 17:44:19 -05:00
marshmellow42
f75b313b00 fix stt mark location bug
add `data mtrim` to do a middle trim of the graph.
2017-02-28 17:28:51 -05:00
marshmellow42
ab812dfae5 implement marking the second STT when detected
on the graph window
2017-02-28 16:35:01 -05:00
marshmellow42
f9f0e83b7c Add 2 pre-setable markers for the graph 2017-02-28 15:53:33 -05:00
marshmellow42
b1ee7eed65 fix em410x XL bug
and make it rule out more false positives.
2017-02-28 13:32:23 -05:00
marshmellow42
62a38cc883 adjust em4x05/em4x69 command timings to...
better conform to datasheet.
2017-02-28 13:18:52 -05:00
marshmellow42
dda5a928f0 fix STT bug for strong waves (or cleaned ones) 2017-02-28 11:53:55 -05:00
marshmellow42
40c6a02bc9 Add a retry loop to hf mf dump
helps get the data dumped even if positioning isn't 100% perfect.

also switched em4x05 commands to WaitUS instead of SpinDelayUs, per
@pwpiwi 's suggestion.
2017-02-28 11:09:42 -05:00
Iceman
38231ce012 Merge pull request #219 from marshmellow42/master
em cleanup and fix bug in lf config [threshold] option making it not work...
2017-02-28 08:00:00 +01:00
marshmellow42
fac69c3d76 Adjust global variable name 2017-02-27 23:03:55 -05:00
pwpiwi
a9d08ed0d5 fix for Kali Linux users (Issue #218) 2017-02-27 19:09:09 +01:00
marshmellow42
2b11c7c750 adjust timeouts on lf read/lf search to no timeout if threshold was set.
NOTE: lf snoop already doesn't have a timeout...
also adjusted PRIx64 to SCNx64 in em410xwrite
2017-02-26 21:44:40 -05:00
pwpiwi
5a6a7affc5 Fix issues with commit 4197a3f on some linux distributions and old mingw environments (issue #217) 2017-02-24 16:19:35 +01:00
marshmellow42
c85189135e the timeout on lf read makes the threshold ...
option not work as expected..  need to find a more robust option...

+ added iceman's lf_em410x_sim help text..
2017-02-24 01:02:25 -05:00
Jeff Morsch
e88c04f924 Merge remote-tracking branch 'upstream/master' 2017-02-24 00:45:57 -05:00
marshmellow42
4913be92ac Merge remote-tracking branch 'upstream/master'
Merge Head
2017-02-23 14:08:41 -05:00
marshmellow42
e88096ba25 cleanup
combine preamble searches (thanks @iceman1001)
simplify Em410xDecode
fix bug in removeParity (I made recently)
move Unique TAG ID printout to avoid confusion
2017-02-23 13:53:40 -05:00
pwpiwi
4197a3f6ff Make LUA scripting work even if proxmark3 is called from arbitrary working directory
- add @gpakosz whereami library (https://github.com/gpakosz/whereami) in order to ...
- determine and set absolute paths for LUA scripts and LUA libraries
2017-02-23 18:37:34 +01:00
pwpiwi
4c16ae80f0 Code cleanup:
- correctly using stdtypes.h printf and scanf format string macros (PRIx64 et al)
- coverity fixes to client/cmdhfmf.c
- fix linker warning re missing entry point when linking fullimage.elf
2017-02-23 18:29:03 +01:00
pwpiwi
43534cbad2 Code cleanup:
- correctly use inttypes.h scanf and printf macros (PRIx64 et al)
- fix indendation warnings
2017-02-22 22:45:00 +01:00
pwpiwi
2d0717853d Merge pull request #216 from marshmellow42/master
EM4x05/EM4x69 command rewrite and improvements
2017-02-22 17:38:56 +01:00
marshmellow42
33a1fe9636 small text adjustments plus...
small improvement to fsk clock detect + fixed a bug where it would
default to rf/16 when it couldn't find a valid one...
2017-02-22 10:41:40 -05:00
marshmellow42
34ff898553 fix false positive psk demod with fsk wave
also break out new find start of modulation routine.
2017-02-21 23:00:43 -05:00
marshmellow42
b7fc61f0c9 update changelog 2017-02-21 16:57:32 -05:00
Iceman
bc1c9c5588 Merge pull request #215 from AdamLaurie/master
buspirate config for debricking.
2017-02-21 19:53:52 +01:00
Adam Laurie
a386043fa9 buspirate config for debricking 2017-02-21 17:53:56 +00:00
marshmellow42
73a2a84f75 simplified lf em command structure
WARNING changes command calling!
2017-02-21 12:00:09 -05:00
marshmellow42
d0b0586411 cleanup cmdlfem4x.h - add chip detection to ...
... lf search
2017-02-21 11:46:13 -05:00
marshmellow42
0a85edf471 add em4x05 config printout 2017-02-21 11:06:19 -05:00
marshmellow42
a37228c8c2 shorten em4x05 capture samples
add cap option for 4469
add sample size option for  DoAcquisition so i can limit how many
samples i want to collect.
use with DoPartialAcquisition
2017-02-20 17:39:39 -05:00
marshmellow42
893534d3b5 speed up the em4x05 cmds by only getting 6k...
samples back
2017-02-20 15:06:22 -05:00
Iceman
086583f6d1 Merge pull request #214 from jamchamb/fix-hf-reader
Fix recvLen variable name in hf_reader
2017-02-20 21:05:35 +01:00
James Chambers
4b12061bee fix recvLen variable name in hf_reader 2017-02-20 14:31:21 -05:00
marshmellow42
fa1e00cfbb add em4x05 info command
plus some minor adjustments
and added a quick em4x05 test:
bool EM4x05Block0Test(uint32_t *wordData)
if successful very likely the tag is an em4x05 or compatible...
2017-02-20 09:50:00 -05:00
marshmellow42
34212c662c fix dump output 2017-02-19 21:31:46 -05:00
marshmellow42
4c6ccc2b04 a little cleanup 2017-02-19 20:47:45 -05:00
marshmellow42
61500621bc @iceman1001 s idea to output failure report 2017-02-17 14:48:19 -05:00
marshmellow42
6980d66b05 add psk to em4x05 reads and tweak psk demod 2017-02-17 14:40:40 -05:00
marshmellow42
c85858f524 minor fixes for FSK demod
works better with EM4x03 and t55x7 tags (in theory)...
2017-02-17 12:59:35 -05:00
marshmellow42
e39a92bb1d em4x05 getting better
got the read/dump cmds working pretty well
some tweaking still left to do.
2017-02-17 01:33:27 -05:00
marshmellow42
2d99d9912c a couple em4x05 fixes. 2017-02-16 13:57:14 -05:00
marshmellow42
59f726c989 EM4x05/EM4x69 continued + a couple of icemans utils. 2017-02-15 23:27:15 -05:00
marshmellow42
6f1a597855 couple q5 fixes + continue with em4x05 em4x69..
.. readword demods
(not tested)  still a work in progress
2017-02-14 23:42:55 -05:00
marshmellow42
7666f4608e update em4x05/em4x69 cmds
@iceman1001 s updates + some of my own.
still more to do:
-auto demod responses
-figure out config block
-figure out block 0 info / serial # in block 1
-figure out block 3 protection data
-add dump all blocks cmd
2017-02-12 23:59:44 -05:00
pwpiwi
3e50af4ee4 Merge pull request #211 from marshmellow42/master
Add Flag for compile warnings, lf cotag read by iceman
2017-02-08 21:49:26 +01:00
marshmellow42
f1e6629b11 update changelog 2017-02-04 16:10:26 -05:00
marshmellow42
e04475c421 Add @Iceman1001 s cotag read
also needed to include some of icemans timer additions.
2017-02-03 00:14:34 -05:00
marshmellow42
38cb7c71c5 add check for no wave in graphbuffer prior to...
hitag lf search check
2017-02-01 15:39:10 -05:00
marshmellow42
11117f6ab5 Merge remote-tracking branch 'upstream/master' 2017-01-30 23:20:55 -05:00
marshmellow42
103c60ec7e flag needed for some compile environments
used for 'z' and 'l' in printf commands.
2017-01-30 23:13:22 -05:00
pwpiwi
1888664863 Merge pull request #209 from micolous/14a-random-nonce
Adds random nonce (r) option to `hf mf sim`.
2017-01-28 17:11:13 +01:00
Michael Farrell
5b5489baf4 hf mf sim: Multiple fixes from review of PR #209.
- Don't increment the nonce when random mode is disabled (this breaks the
  standard attack).

- Don't attempt the standard attack when random mode is enabled (there's no
  point as it won't work, per comments from @pwpiwi).

- Attempt the moebius attack if the standard attack fails.
2017-01-26 20:30:13 +11:00
pwpiwi
c783fd1bb8 Merge pull request #208 from marshmellow42/master
bug fixes - LF rawdemod am and ST
2017-01-26 09:10:38 +01:00
Michael Farrell
f9c1dcd9f6 Adds random nonce (r) option to hf mf sim.
This makes the PM3 generate pseudo-random nonces rather than sequential
nonces, to make it act a bit more like a "real" MFC card.  A reader would
otherwise be able to detect the PM3 probing based on the predictable nonces
and throw different authentication challenges (or refuse to authenticate at
all).

The code includes an implementation of a rand-like function (prand), similar
to the one from libc, which is seeded automatically based on the time it
takes between the PM3 starting up and the first call to the RNG.

This isn't cryptographically random, but should be "good enough" to be able
to evade basic detection.
2017-01-26 18:32:25 +11:00
marshmellow42
01d0f8ae8f bug fixes - LF rawdemod am and ST
rawdemod parameter length test too short for help text
amp option should amp prior to ST check
ST check adjusted to make room for rf/32 clock instead of rf/64 (so will
have extra room if clock is higher than 32)
ST check improved to better account for low drift
2017-01-20 00:55:40 -05:00
Iceman
910ad5470d Merge pull request #202 from marshmellow42/master
add hitag2 uid read and fixes for iclass write
2016-12-19 16:09:58 +01:00
marshmellow42
89696b8b24 fixed lf antenna left on bug && some iclass ...
output cleanup by @iceman1001
2016-12-19 09:45:23 -05:00
marshmellow42
921e63992c a few bug fixes with adding hitag detection to...
`lf search`
2016-12-16 14:04:39 -05:00
marshmellow42
0b91ce03e5 Merge remote-tracking branch 'upstream/master' 2016-11-29 15:09:27 -05:00
marshmellow42
671ff89fcb fix iclass write
thanks to prof_abrasive && go_tus
2016-11-29 14:59:14 -05:00
Iceman
d1057e7a21 Merge pull request #119 from marshmellow42/pm3+reveng
add reveng 1.30 source to PM3 for CRC calculations & searches
2016-10-08 19:18:14 +02:00
ikarus
2943527472 Fixed all "misleading-indentation" warnings (fixes #187). 2016-09-26 21:15:49 +02:00
ikarus
9b3c48688e Revert "Do not treat gcc's "misleading-indentation" warning as error."
This reverts commit fd4f21b766.
2016-09-26 20:39:31 +02:00
ikarus
fd4f21b766 Do not treat gcc's "misleading-indentation" warning as error (fixes #187). 2016-09-26 19:21:01 +02:00
Iceman
fcfd0cbc4e Merge pull request #197 from menshiyun/test-pr
minor fix in client/makefile
extra option to LDLIBS is not needed for mingw env as of now. Might be in the future.
2016-09-25 08:46:59 +02:00
menshiyun
5bac3d9b3c fix client/Makefile 2016-09-25 14:32:06 +08:00
menshiyun
94e27a0961 fix client/Makefile 2016-09-25 14:26:11 +08:00
menshiyun
775c4c4a28 test-pr 2016-09-24 12:56:08 +08:00
Iceman
99911e5c7b Merge pull request #196 from k02a/patch-5
Code cleanup,
2016-09-23 13:04:07 +02:00
Johnny Bengtsson
ad8a18e66e Code cleanup
Some variable type changes.
2016-09-14 13:27:24 +02:00
Iceman
41f08b7c08 Merge pull request #195 from k02a/patch-4
Warning removal fix
2016-09-13 14:25:02 +02:00
Johnny Bengtsson
015520dc4e Warning removal fix
Minor fix of data type corrections.

gcc -std=c99 -I. -I../include -I../common -I../zlib -I/opt/local/include -I../liblua -Wall  -g -O4 -DHAVE_GUI -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED  -c -o obj/fpga_compress.o fpga_compress.c
fpga_compress.c: I funktion "zlib_compress":
fpga_compress.c:90:20: varning: format "%lu" förväntar sig argument av typen "long unsigned int", men argument 3 har typen "int" [-Wformat=]
    fprintf(stderr, "Input files too big (total > %lu bytes). These are probably not PM3 FPGA config files.\n", num_infiles*FPGA_CONF
                    ^
fpga_compress.c:142:18: varning: format "%lu" förväntar sig argument av typen "long unsigned int", men argument 3 har typen "uint32_t {även unsigned int}" [-Wformat=]
  fprintf(stderr, "compressed %lu input bytes to %lu output bytes\n", i, compressed_fpga_stream.total_out);
2016-09-13 12:21:46 +02:00
Iceman
69f30e3209 Update README.txt
Added some new stores
2016-09-12 23:34:42 +02:00
Iceman
04dc10fc43 Merge pull request #193 from k02a/patch-2
Better Linux compilation compability
2016-09-12 18:06:24 +02:00
Iceman
b2030b2216 Merge pull request #192 from k02a/patch-1
Patching Lua compilation error
2016-09-12 18:04:14 +02:00
Johnny Bengtsson
887f6ab4b3 Better Linux compilation compability
Addition of the termcap and ncurses libraries fixes the compilation issue on Slackware Linux 14.2.

/usr/lib64/gcc/x86_64-slackware-linux/5.4.0/../../../../lib64/libreadline.so: undefined reference to `PC'
collect2: fel: ld returnerade avslutningsstatus 1
Makefile:132: receptet för målet "proxmark3" misslyckades
make[1]: *** [proxmark3] Fel 1
make[1]: Lämnar katalogen "/home/github/proxmark3/proxmark3/client"
Makefile:12: receptet för målet "client/all" misslyckades
make: *** [client/all] Fel 2
make: Lämnar katalogen "/home/github/proxmark3/proxmark3"
2016-09-12 16:03:46 +02:00
Johnny Bengtsson
147a3169fd Better Linux compilation compability 2016-09-12 15:55:44 +02:00
marshmellow42
fc249a8e13 Merge pull request #7 from marshmellow42/hitag2_tests
attempt hitag2 uid read for lf search
2016-08-25 13:41:11 -04:00
Iceman
51b42675bf Merge pull request #184 from koalazak/patch-1
Add details to compile using brew in Mac OS X
2016-08-12 13:55:39 +02:00
Iceman
7669409547 Merge pull request #185 from marshmellow42/master
some lf fixes and hf mf sim attack mode add-ons
2016-08-12 13:55:09 +02:00
marshmellow42
f86d6b557a attempt hitag2 uid read for lf search 2016-08-04 13:51:37 -04:00
marshmellow42
ef3f88bca9 disable extra attack - disable stats.txt
Moebius attack didn't yield any better results in my testing so
disabling it, but allowing it to be re-enabled at will.
also disabled the auto logging of all keys with uid delimited file
stats.txt - can be uncommented when needed
2016-07-28 12:52:18 -04:00
Facu ZAK
ed1525805c Add details to compile using brew in Mac OS X 2016-07-19 21:17:38 -03:00
marshmellow42
91f4d53123 couple bug fixes - clean up 2016-06-28 21:02:26 -04:00
marshmellow42
76ef5273d8 hf mf sim code cleanup - update changelog 2016-06-27 00:09:40 -04:00
marshmellow42
73ab92d14c mf 1k sim reader attack cleanup
add abort options - keyboard & button press.
2016-06-25 00:53:53 -04:00
marshmellow42
bbd118760b allow mf1k reader attack from file full of UIDs
also add UID to stats.txt collection.
2016-06-24 23:43:53 -04:00
marshmellow42
6eae192c41 fix bug in moebius nonce collection - now finishes
also cleaned up some comments
note previous update added the creation of a stats.txt file to generate
statistics of the differences between std mfkey32 and the moebius
version.
2016-06-24 16:46:11 -04:00
marshmellow42
c872d8c177 update hf mf sim x attack mode - start 10byte uid..
..support  (some from @iceman1001)
(sim reader attack currently testing std mfkey32 vs mfkey32_moebius
version...)  possibly will remove one later.
2016-06-24 01:31:27 -04:00
marshmellow42
7314995a5a hf mf sim x reader attack add-ons
forgot to include the mfkey32 attack
2016-06-22 11:26:11 -04:00
marshmellow42
79dcb9e090 improve hf mf sim x reader attack
can now directly extract multiple keys for multiple sectors
2016-06-22 11:03:37 -04:00
marshmellow42
16ea2b8ca3 fix askAmp
again... must have been something i missed before.  this function wasn't
complete.
2016-06-20 00:42:03 -04:00
marshmellow42
8f2268397d fix bug in viking clone/sim
from @iceman1001
2016-06-20 00:28:26 -04:00
marshmellow42
de53156e1e Fix the AskEdgeDetect cleaning tool
somehow it got broken.
(maybe i had an incomplete pull request once upon a time)
2016-06-19 23:44:54 -04:00
pwpiwi
83f11ccf72 Merge pull request #181 from raburton/tune
add l/h option to hw tune and optimize order of tuning
2016-06-08 16:20:11 +02:00
marshmellow42
c0d32c3186 Merge remote-tracking branch 'upstream/master' 2016-06-05 22:20:36 -04:00
Richard Antony Burton
fdcfbdcc21 add l/h option to hw tune and optimize order of tuning 2016-06-01 08:13:20 +01:00
Martin Holst Swende
6fcb5dda51 Merge pull request #175 from hiviah/master
Fix hitagS sources to compile on gcc 4.9.3
2016-05-20 13:24:40 +02:00
Martin Holst Swende
cd2872f2cc Merge pull request #178 from dnet/cmdlf-unused-strlen
removed unused variable
2016-05-20 13:17:31 +02:00
András Veres-Szentkirályi
f9ce1c3a00 removed unused variable 2016-05-10 10:33:30 +02:00
Ondrej Mikle
39d56ec88b Fix hitagS sources to compile on gcc 4.9.3 2016-04-23 10:01:19 +02:00
Martin Holst Swende
b324b02f88 Merge pull request #167 from spenneb/master
Experimental HitagS support
2016-04-05 21:12:24 +02:00
Ralf Spenneberg
5cfd18ac1e Changelog modified 2016-04-05 08:52:53 +02:00
Martin Holst Swende
90858b95ad Merge pull request #168 from zhovner/master
mfkey64: Added optional decryption of communication using keystream
2016-04-03 21:55:54 +02:00
marshmellow42
cf194819cc simplify some code, add comments
ABS simplification from Iceman1001
2016-03-19 00:09:58 -04:00
Pavel Zhovner
c36d994b32 remove binary files 2016-03-09 03:52:54 +03:00
Pavel Zhovner
8eea1dc264 Optional decryption of communication using keystream 2016-03-09 03:32:39 +03:00
Pavel Zhovner
a78238349c Optional decryption of communication using keystream 2016-03-09 02:41:20 +03:00
marshmellow42
29ada8fc08 add ST to ask/manchester sim, finish presco...
...as it is currently understood - need to add base 12 printed ID to
demod output...
add Q5 option to pyramid
fix missing include I mistakenly removed in cmdlf
2016-03-07 01:01:40 -05:00
marshmellow42
e3c992a92f fix comment typo error 2016-03-05 23:46:34 -05:00
marshmellow42
6923d3f14f Add @iceman1001 s presco and pyramid functions +
plus comment some includes.
fix indala error checking bugs
cmddata.h previously relied on several headers being included prior to
cmddata.h, now self contained.
2016-03-05 23:45:28 -05:00
Ralf Spenneberg
4e12287d19 Experimental HitagS support 2016-03-04 17:28:05 +01:00
marshmellow42
31e8a4f21b fix uint8 vs uint32 and use sprint_hex
thanks @iceman1001 for the suggestion.
2016-02-29 18:17:51 -05:00
marshmellow42
39611e3d68 fix ask/Biphase sim bug 2016-02-29 18:05:47 -05:00
marshmellow42
88e85bde41 refactor gProxII demod... add 0 spacer to ...
... parity functions (remove, add)
make MAX_GRAPH_TRACE_LEN match with client side
2016-02-29 17:05:02 -05:00
marshmellow42
72c5877a74 some minor lf fixes from @iceman1001 2016-02-21 17:05:53 -05:00
Martin Holst Swende
d889dacc9d Merge pull request #166 from marshmellow42/master
Add LF ASK ST detect and demodulate...
2016-02-21 17:41:58 +01:00
marshmellow42
b66ff08113 fix clock detection when ST used
ST = sequence terminator
fixes t55xx auto detection of tags with ST used.
2016-02-20 16:53:59 -05:00
marshmellow42
29b757391a remove errant 'void'
have to watch my copy and paste...
2016-02-20 10:22:45 -05:00
marshmellow42
01d7272d5b Merge remote-tracking branch 'upstream/master' 2016-02-20 10:10:10 -05:00
marshmellow42
3cec706139 move the clear buffer outside of potentially time..
... sensitive routines
see http://www.proxmark.org/forum/viewtopic.php?id=2820
2016-02-20 10:07:44 -05:00
marshmellow42
35cfcfc7a1 fix detection of lf t55x7 if xtd bits set but...
...not used
2016-02-19 15:54:32 -05:00
marshmellow42
8e90cd4174 fix wrong type in print bug 2016-02-19 15:11:44 -05:00
marshmellow42
b96bcc795b finish LF ASK Sequence Terminator detection 2016-02-19 15:09:51 -05:00
Martin Holst Swende
12bad10c46 Merge pull request #165 from wllm-rbnt/master
Typos
2016-02-17 16:15:39 +01:00
William Robinet
63744b5681 Typos 2016-02-17 15:44:18 +01:00
marshmellow42
e452cfb4be update changelog 2016-02-16 21:10:48 -05:00
marshmellow42
d1869c3336 Add LF ASK Sequence Terminator detection...
...and demodulate data beginning after the first ST
also add some type casts in print calls.
2016-02-16 12:49:30 -05:00
Martin Holst Swende
b12f076b0d Merge pull request #164 from marshmellow42/master
fix issue #163, prevent two calls to getFromGraphBuf - fix char array pointer...
2016-02-16 15:39:52 +01:00
marshmellow42
38b3509542 use memcpy instead of re-assign pointer 2016-02-16 09:38:37 -05:00
marshmellow42
9e4cee22b7 clear char array with each call 2016-02-15 22:36:51 -05:00
marshmellow42
0c50084a2b fix char* pointer not assigned
fix
2016-02-15 22:31:21 -05:00
marshmellow42
a0cc89b479 use different fsk field clock detection routine ...
... to prevent double call to getFromGraphBuf()...
also adjust %hu to u and as there is a possible problem with %hu in
printf.
2016-02-15 21:39:34 -05:00
marshmellow42
7f0d592636 Merge remote-tracking branch 'upstream/master' into pm3+reveng 2016-02-15 14:13:49 -05:00
Martin Holst Swende
b31ef4f510 Merge pull request #162 from marshmellow42/CoverityFixes
Coverity fixes - mainly from @iceman1001 s fork
2016-02-15 18:43:25 +01:00
Martin Holst Swende
b5cefff12c Merge pull request #160 from marshmellow42/master
lf viking and standalone bug fixes
2016-02-15 18:39:42 +01:00
marshmellow42
7c5e0ebe7a undo adjustments to cmdhf14a.c and cmdhfmf.c
as these will be adjusted with the magic command adjustments
2016-02-14 18:37:09 -05:00
marshmellow42
d0168f2f49 clear array before assigning 2016-02-14 18:08:14 -05:00
marshmellow42
e7707cdb17 verify wait isn't null 2016-02-14 17:41:16 -05:00
marshmellow42
776f7e6160 put back viking clone bug fix
forgot i added this on a different computer recently - forgot to merge
it in...
2016-02-14 17:00:20 -05:00
marshmellow42
38d618baa9 remove redundant llx prix64 defines
remove unused commented out #includes
coverity indicates compressed_fpga_stream.opaque needs to be initialized
to Z_NULL
fgetc returns int
define llu
2016-02-14 14:43:19 -05:00
marshmellow42
d23411ef61 resource leak and malloc(x) cannot be negative
thanks iceman1001
2016-02-14 13:41:25 -05:00
marshmellow42
735136e6a3 lf t55 bruteforce lots of resource leaks...
plus strlen(Cmd) can never be less than 0
iceman1001 fixes...
2016-02-14 13:37:05 -05:00
marshmellow42
8ea5706047 additional memory leaks, overflow and unchecked ...
return values fixed

thanks to iceman1001
2016-02-14 13:24:03 -05:00
marshmellow42
568377946c FIX: Coverity, Out-of-bounds. In the loop, variable i, can...
...be as much as 1051, overflowing the databuf with size 1024.
2016-02-14 12:36:55 -05:00
marshmellow42
165e0775b1 fix possible null if no file found
also initialize filename variable so not null

found by iceman1001
2016-02-14 12:33:07 -05:00
marshmellow42
b0c68b72d3 fix keyNbr entry error checking
coverity scan by iceman1001 found.
2016-02-14 12:26:03 -05:00
marshmellow42
eb5b63b4a6 FIX, Coverity, Argument can't be negative. CID# 212322, ftell(f) can …
…be negative. Not allowed in malloc...
from iceman1001
2016-02-14 12:13:22 -05:00
marshmellow42
7a616c0d70 FIX, Coverity, Argument can't be negative. CID# 212322, ftell(f) can …
…be negative. Not allowed in malloc...
from @iceman1001
2016-02-14 12:06:29 -05:00
marshmellow42
3d4982ddbf FIX: Coverity, unintended sign extention, CID #121363, (numbits << 16…
…) becomes int, then uint64_t. But the signness might set all upper bits
to 1 in the process.
from @iceman1001 .
2016-02-14 11:42:34 -05:00
marshmellow42
fd9172d5c2 @iceman1001 s coverity fixes
resource leak in hf mf sniff
possible overflow in hf 14a raw - add check to fix
2016-02-14 11:26:00 -05:00
marshmellow42
33c795d0bd add check to fread call 2016-02-14 11:07:16 -05:00
ikarus
d2736c4e20 Merge pull request #161 from wllm-rbnt/master
Fix typos
2016-02-11 23:35:28 +01:00
William Robinet
b8140ab108 Fix typos 2016-02-11 23:03:15 +01:00
marshmellow42
098015eb75 fix bug in lf standalone mode
clone command mixed up parameters.
2016-02-10 10:03:28 -05:00
marshmellow42
0c1cb4aef0 fix lf viking clone mask bug
should be a 32 bit mask not a 16 bit mask
also added client feedback.
2016-02-09 13:40:01 -05:00
Martin Holst Swende
2a99a73055 Merge pull request #158 from marshmellow42/master
q5 fixes plus a couple coverity scan fixes from @iceman1001
2016-02-09 12:55:36 +01:00
marshmellow42
9fc602c835 fix print clock as decimal instead of uint8_t 2016-01-28 00:27:53 -05:00
marshmellow42
c4c3af7c16 some @iceman1001 s coverty scan fixes
great work!
2016-01-08 18:26:56 -05:00
marshmellow42
3975d477e1 comment out unused includes and defines
prep for permanent removal.
2016-01-07 21:54:32 -05:00
marshmellow42
3069198066 Merge remote-tracking branch 'upstream/master' 2016-01-05 21:36:16 -05:00
marshmellow42
5490c2d6d2 add broken_bad and @iceman1001 s q5 trace and ...
wipe adjustments
2016-01-05 21:21:06 -05:00
ikarus
7ede3c7122 Remove include statement that causes trouble (fix #151).
See: https://github.com/Proxmark/proxmark3/issues/151
2015-12-23 23:51:49 +01:00
marshmellow42
254687260c Merge remote-tracking branch 'upstream/master' 2015-12-21 23:56:55 -05:00
Martin Holst Swende
c578d3412c Merge pull request #153 from AdamLaurie/master
add support for raw block 3/4 iclass keys
2015-12-20 21:13:51 +01:00
Adam Laurie
59296346a0 document iclass raw key changes 2015-12-20 12:37:22 +00:00
Adam Laurie
bc37cfb3eb add support for raw block 3/4 iclass keys 2015-12-19 16:37:32 +00:00
marshmellow42
af5384bc90 additional Q5 lf t55xx fixes 2015-12-14 17:36:08 -05:00
marshmellow42
6ca1477c74 fix occasional strange printed clock value with...
...fskdemod
Fix Q5 tag detection in lf t55xx detect
Fix param_get8 reversed parameters
2015-12-14 16:51:11 -05:00
Martin Holst Swende
2c7928874b Merge pull request #149 from marshmellow42/T55xx_tests
Add lf viking, lf demod/clock detection improvements
2015-12-10 10:44:44 +01:00
marshmellow42
534678c3e9 Fix incorrect memset parameters in lf t55xx wipe
thanks @iceman1001 for the catch

add added a restore graphbuffer after lf t55xx psk demodulation
2015-12-09 22:44:01 -05:00
marshmellow42
7bc6fac3ce fix sprint_bin bug i made :( 2015-12-09 20:40:12 -05:00
marshmellow42
6bfac25573 update changelog 2015-12-08 22:26:55 -05:00
marshmellow42
ace26dbdfd Fix printdemodbuffer length tests + add length...
parameter
increase askdemod MaxBits
fix util.c sprint_bin_break and increase buffer size (had memory
overflow possible before)
2015-12-07 21:18:30 -05:00
marshmellow42
51923aca85 minor help text changes 2015-12-04 12:09:26 -05:00
marshmellow42
6e083f0412 include default password dictionary for lf t55xx...
...bruteforce
2015-12-03 16:44:06 -05:00
marshmellow42
506672c48b icemans lf fixes & adjustments + lf t55xx bruteforce
Fix small fskdemod clock bug
2015-12-02 17:27:12 -05:00
marshmellow42
fe876493f8 include cmdlfviking.c in makefile and cmdlf
fix minor typos
2015-11-26 21:05:46 -05:00
marshmellow42
ab5ffe3bef iceman's finished t55xx detect parameter adjustments 2015-11-26 20:30:58 -05:00
marshmellow42
d1cea2a4a0 fix const vs static... 2015-11-22 16:42:13 -05:00
Martin Holst Swende
f9e1816b95 Merge pull request #147 from ha7dcd/pcb
Updates and fixes to the PCB schematics
2015-11-22 15:05:47 +01:00
marshmellow42
709665b5d1 lf viking build / lf awid refactor / lfdemod.c debugMode==2
lf viking from other users - just put my spin on it
lf awid refactored code - possible to make it not 26bit specific now
with minor chanages
lfdemod.c now supports extra debug printing if `data setdebug` = 2 when
not on device (on client not arm)
2015-11-22 00:00:32 -05:00
marshmellow42
6fe5c94bda lf demod cleanup nrz clock detect fixes
slight adjustment to lf t55xx sampling code to start at the same spot
more consistently
reduce indala detection false positives
lf t55xx commands heavily tested and seem to be stable and reliable on
most modulations/bitrates (excluding Sequence Terminator configured
cards).
2015-11-18 00:10:11 -05:00
marshmellow42
93507a3375 remove old comment 2015-11-16 18:55:46 -05:00
marshmellow42
db8296025f lf t55xx and some lf demod fixes/adjustments
finally think I like the lf t55xx detect and read cmds.  pretty reliable
now.
2015-11-16 18:49:20 -05:00
Martin Holst Swende
9983a92943 Merge pull request #143 from marshmellow42/master
lfops cleanup, t55xx additions/fixes, PCF7931 input cleanup
2015-11-15 13:22:26 +01:00
Martin Holst Swende
fa0503b03f Merge pull request #144 from dnet/makefile-paren-fix
fixed target "help" in Makefile
2015-11-15 13:20:51 +01:00
Martin Holst Swende
88715fe122 Merge pull request #146 from dnet/patch-1
Fixed copypasted hex output to match input
2015-11-15 13:20:25 +01:00
Zoltan Doczi
a20fe6d61f corrected Eagle files
check change_log.txt
2015-11-13 17:24:26 +01:00
Zoltan Doczi
9c3cc9012a cad, cam file commit
adding modified CAD and CAM file sets. Checked against DRC issues, all
looks okay, ready to manufacturing!
2015-11-13 17:13:51 +01:00
marshmellow42
f665067919 add some Q5 functionality - add t55xx wipe cmd
not fully tested yet
2015-11-12 00:27:24 -05:00
marshmellow42
14331320c4 Fix viking demod bug - clean my indala demod code
NOTE lf indalademod is still available as it uses a different technique
to demodulating, which sometimes works better (and sometimes worse).
2015-11-10 11:59:41 -05:00
marshmellow42
3ea7254a57 add checksum to viking demod 2015-11-09 23:48:39 -05:00
marshmellow42
415274a7c3 Add Viking demod,
fix compiler warning for int vs uint8_t for em410x sim clock variable
2015-11-09 23:09:26 -05:00
András Veres-Szentkirályi
7cdf6236cb Fixed copypasted hex output to match input
The value `x0` was obviously copypasted but not edited to reflect the real values used in `case` matching.
2015-11-09 21:06:58 +01:00
András Veres-Szentkirályi
16f54ead2a fixed target "help" in Makefile
Without this commit, running `make help` produced the below output.

    $ make help
    Multi-OS Makefile, you are running on Linux
    Possible targets:
    + all - Make bootrom, armsrc and the OS-specific host directory
    + client - Make only the OS-specific host directory
    + flash-bootrom - Make bootrom and flash it
    /bin/sh: 1: Syntax error: "(" unexpected
    Makefile:20: recipe for target 'help' failed
    make: *** [help] Error 2

This issue was introduced in e335ca2846
six months ago, the above output was produced on Debian GNU/Linux, where
`/bin/sh` is usually a symbolic link to `/bin/dash`.
2015-11-09 19:40:27 +01:00
marshmellow42
daa4fbaeec fix em410xsim help - add clock input to em410xsim 2015-11-07 21:02:30 -05:00
pwpiwi
2487dfeb07 fix: .history was never written 2015-11-06 11:34:43 +01:00
pwpiwi
5d0e190169 fixing hf snoop:
- add: clear the trace buffer before snooping
- fix: allow trigger on odd samples as well
- fix: don't use Dbprintf() in timing tight loops
2015-11-06 09:02:05 +01:00
marshmellow42
8949e04584 Merge remote-tracking branch 'upstream/master' 2015-11-03 20:19:46 -05:00
marshmellow42
76346455d2 minor lf updates/cleanup 2015-11-03 20:18:16 -05:00
pwpiwi
b2fe0e77c5 Merge branch 'topaz'
Conflicts:
	CHANGELOG.md
	client/cmdhf.c
2015-11-03 21:06:59 +01:00
pwpiwi
6e2f85c44c Merge pull request #141 from etmatrix/tosubmit
HF snoop ported by enio's repository
2015-11-03 07:44:01 +01:00
etmatrix
edc9ce00b3 - Little change to description in client
- Added description to CHANGELOG.md
2015-11-03 07:15:56 +01:00
etmatrix
82d589348c - Correct little distraction on fpga/Makefile
- New patch from pwpiwi works very well for hi_sniffer.v
- Restored previous fpga_lf.bit
2015-11-02 09:08:21 +01:00
marshmellow42
9f669cb26f minor cleanups 2015-10-31 23:12:42 -04:00
marshmellow42
78711df115 update changelog 2015-10-30 23:30:12 -04:00
marshmellow42
66837a0302 Add lf t55xx resetread cmd + fix clone cmds
resetread cmd to determine start of streaming bits of ata5577 or
compatible chips...
fixed lf clone bugs introduced while refactoring recently...
2015-10-30 23:23:27 -04:00
pwpiwi
d9cc4e1ae2 Merge branch 'master' into topaz. Update Changelog. 2015-10-27 20:57:16 +01:00
etmatrix
031311c7ae LED D is on while snoop, when user button is pressed snoop is stopped 2015-10-25 08:10:17 +01:00
marshmellow42
3606ac0a2b refactor lfops t55xx functions
share t55xx configuration register definitions with client for later use
(warning - compiled but not fully tested yet)
2015-10-24 09:54:04 -04:00
marshmellow42
88f475cf6b update changelog 2015-10-23 13:13:29 -04:00
marshmellow42
0c8200f11c text cleanup t55xx cmds 2015-10-23 13:05:40 -04:00
etmatrix
0472d76de4 The great work of Enio hf snoop is now ported into latest version in git
you can find original work here https://github.com/EnioArda/proxmark3
2015-10-23 15:40:35 +02:00
marshmellow42
be2d41b73a updates to lf t55xx commands
fix wakeup cmd per @iceman1001
fix dump and read cmds
clean up write command
allow page 1 read/write (block 3 is writable)(ata5577 only)
remove duplicate code
2015-10-22 16:19:23 -04:00
marshmellow42
8e99ec25ed add wake option to t55xx read command 2015-10-17 15:01:26 -04:00
marshmellow42
21a615cb3b begin update lf commands with help text and
cmd structure.
update changelog for recent changes
2015-10-17 10:48:54 -04:00
marshmellow42
f1b74c3089 add lf t5 read w/pwd warning and checks
ideas from @iceman1001 for issue #136
2015-10-15 21:26:23 -04:00
marshmellow42
7cfc777b0e lf t55xx code cleanup +
@iceman1001 s cleanup of some t55xx read code, plus some timing tests to
improve lf t5 detect/read...
small typo in pcf 16 address bytes instead of 4...
add option for verbose or not on bigbuf clear cmd.
2015-10-15 14:53:49 -04:00
marshmellow42
59b5b7e14c PCF-fix bytepos range from 0-3 to 0-15 2015-10-15 01:31:52 -04:00
marshmellow42
f4eadf8a50 adjust lf t55xx read commands
seems to make them a lot more accurate for me
2015-10-15 01:09:49 -04:00
marshmellow42
d10e08ae6e Clean up pcf7931
@iceman1001 s cleanup of pcf7931 commands on client side
and split out pcf7931 from lfops.c as it is getting large
2015-10-14 16:17:56 -04:00
Martin Holst Swende
be6250d31b Merge pull request #140 from marshmellow42/iclass
iClass major updates
2015-10-13 09:39:04 +02:00
pwpiwi
8c6b22980c hf mf mifare: (finally) fix watchdog reset
- minor changes to sync
- try alternative strategies when debugging
2015-10-10 15:04:17 +02:00
marshmellow42
f1f1aceaba fix changelog conflict 2015-10-07 09:38:07 -04:00
marshmellow42
c54dff4f4a Merge remote-tracking branch 'Proxmark/master' into iclass
Conflicts:
	CHANGELOG.md
2015-10-07 09:34:47 -04:00
marshmellow42
4ff341efff fix help typo 2015-10-07 09:32:50 -04:00
marshmellow42
1a5a73abae Add mifare crypto trace decryption utility
allows manual decryption of hf 14a snoop traces of a mf card.
someday we should fix hf mf sniff...
2015-10-07 00:24:55 -04:00
pwpiwi
dfb387bf0f hf mf mifare:
- gracefully exit on unsuccessful syncs instead of hard watchdog reset
2015-09-30 20:59:50 +02:00
pwpiwi
7624e8b21b hf topaz reader implementation:
- read and display dynamic memory as well
- display "locked" status per byte instead per block
2015-09-28 08:26:00 +02:00
Martin Holst Swende
9dd0ac57ed Merge pull request #138 from Dake01/master
Add : writing on PCF7931 tags
2015-09-08 21:04:24 +02:00
Dake
29c90533eb remove debug 2015-08-27 08:58:15 +02:00
Dake
fff58476af syntax corrective 2015-08-26 16:01:08 +02:00
Dake
940d53098c corrective values 2015-08-26 15:57:41 +02:00
Dake
dc4300bafb add : writing on PCF7931 tags 2015-08-26 15:53:49 +02:00
pwpiwi
8e21541e77 Merge branch 'master' into topaz 2015-08-25 07:53:00 +02:00
Martin Holst Swende
5d01f50ae1 Minor corrections 2015-07-31 23:30:48 +02:00
Martin Holst Swende
f68211671c Implemented data hex2bin and data bin2hex as per suggestion in http://www.proxmark.org/forum/viewtopic.php?pid=17504 2015-07-31 23:28:32 +02:00
pwpiwi
67b7d6fa31 fix: avoid USB Speed Test timeout in case of slow transfer speeds
fix: don't add CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K commands into command buffer
2015-07-31 20:11:37 +02:00
pwpiwi
bfb01844fb add: USB Speed Test to hw status
fix: choose Real Time Clock divider based on actual slow clock frequency
2015-07-29 18:52:43 +02:00
marshmellow42
e1c6e9e8f1 iclass Write doMAC_N - rename variables to correct descriptions. 2015-07-28 15:20:19 -04:00
Martin Holst Swende
da721c6b30 Merge pull request #134 from VERTCraig/master
Updating StandAloneMode14a
2015-07-28 19:00:19 +02:00
Craig Young
73d336ae1d Adding STL files for 3D printed coil forms 2015-07-26 11:55:50 -04:00
marshmellow42
bbd19beced update books to app_areas. clearer. 2015-07-25 23:24:53 -04:00
marshmellow42
b82d809852 update iClass chip identification 2015-07-25 23:09:07 -04:00
marshmellow42
85f581c79f fix typo 2015-07-25 22:22:19 -04:00
marshmellow42
7a8344d0c9 document iclass additions 2015-07-25 22:11:54 -04:00
Craig Young
d976c9ddb2 Merging changes from main repo 2015-07-25 14:38:57 -04:00
Craig Young
c89274cc60 Stand Alone Mode changes for NFC (part 2) 2015-07-25 14:35:14 -04:00
marshmellow42
3ac22ee1cf use read instead of readcheck except to auth 2015-07-23 01:12:02 -04:00
Martin Holst Swende
987dfb66e2 changelog docs 2015-07-21 23:21:16 +02:00
Martin Holst Swende
e2012d1bd3 Implemented 'hw status' and 'hw ping', put back client-side cacheing of 'hw version' 2015-07-21 23:18:51 +02:00
marshmellow42
4d68ec02b2 iclass refactor/cleanup 2015-07-21 14:26:46 -04:00
marshmellow42
6b659d2406 Merge remote-tracking branch 'upstream/master' into iclass 2015-07-20 21:26:35 -04:00
Martin Holst Swende
85f011a550 Merge pull request #133 from marshmellow42/master
14b additions + some bug fixes
2015-07-21 00:27:09 +02:00
Martin Holst Swende
86a83668b5 Minor changes in iso1443-standalone mode 2015-07-21 00:13:06 +02:00
marshmellow42
a40680f3ac Merge remote-tracking branch 'upstream/master' 2015-07-20 17:29:52 -04:00
Martin Holst Swende
865279ba89 Merge pull request #130 from VERTCraig/StandAlone14a
ISO14443a Stand-Alone Mode
2015-07-20 23:23:44 +02:00
Martin Holst Swende
1adb2023ce Merge pull request #131 from holiman/master
Fixes to PR #129
2015-07-20 23:22:53 +02:00
Martin Holst Swende
23931c11d5 Minor fix with previous cache-removal 2015-07-20 23:22:33 +02:00
Martin Holst Swende
d2deaf7bcf Fixed some indentation 2015-07-20 23:18:46 +02:00
Martin Holst Swende
db2dc28d34 Reverted previous change to , I made it no longer cache previous results 2015-07-20 23:17:55 +02:00
marshmellow42
aa53efc340 iclass additions
multiple contributors - thanks!
2015-07-20 13:41:40 -04:00
Martin Holst Swende
40c5f34265 Clear command buffer 2015-07-17 21:49:27 +02:00
Martin Holst Swende
83f3f8ac40 Potential fix for 0-length usb packets seen on OSX 2015-07-17 00:01:58 +02:00
Martin Holst Swende
976627d5ba Fixed (?) issues from PR #129 2015-07-16 23:50:41 +02:00
Martin Holst Swende
37824afe63 Changed indentation to tabs 2015-07-16 22:47:14 +02:00
Martin Holst Swende
b067125f98 Merge pull request #129 from VERTCraig/master
AWID26 Extended Support
2015-07-16 22:41:22 +02:00
marshmellow42
d5810937bd Merge remote-tracking branch 'upstream/master'
Conflicts:
	armsrc/iso14443b.c
2015-07-15 22:25:11 -04:00
Craig Young
e46fe04430 Introducing a stand-alone mode for working with NFC (ISO14443a) tag UIDs. 2015-07-13 18:46:42 -04:00
Craig Young
bcffcca25f Adding usage information to 'lf awid' commands 2015-07-13 18:14:12 -04:00
Craig Young
d6b455ed4e Adding 'lf awid' context to cmdlf.c 2015-07-13 16:47:11 -04:00
Craig Young
769791d440 Updated CHANGELOG.md 2015-07-13 16:41:50 -04:00
Craig Young
c0c35f9bb6 Adding CMD_AWID_DEMOD_FSK to commands.lua 2015-07-13 16:18:59 -04:00
Craig Young
dbf6e824f9 Adding support for AWID26 realtime demodulation as well as cloning and simulation from facility code and card number 2015-07-13 15:45:28 -04:00
Martin Holst Swende
a83d091885 Merge pull request #127 from frederikmoellers/master
ISO 14443 type B support for (German) electronic ID cards
2015-07-13 12:22:10 +02:00
Frederik Möllers
2c3c08bd2f Mention EPA Type A/B support in CHANGELOG.md 2015-07-13 11:37:28 +02:00
Frederik Möllers
a704cbe89d Merge upstream/master
A new release has been pushed in the meantime and the changelog reflects
this. Things to be added to the changelog should thus go into the new
unreleased block.
2015-07-13 11:29:33 +02:00
Martin Holst Swende
5ebdce44c0 New release with FPGA compression 2015-07-12 23:44:34 +02:00
Martin Holst Swende
60034782f9 Some info in the changelog 2015-07-12 23:39:27 +02:00
Martin Holst Swende
40c514454d Fixed issue #94, so lua-script 'mifare_autopwn' reacts correctly to card that are not vulnerable to darkside-attacks 2015-07-12 23:38:52 +02:00
marshmellow42
b362de6262 initialize global variables. 2015-07-11 00:35:27 -04:00
pwpiwi
5330f5329f - fix: trace of hf mf mifare had always been cleared by mfCheckKeys() in nonce2key()
- fix: parity was not checked for reader commands in hf list 14a
- add: enable tracing for hf mf nested
2015-07-07 09:02:00 +02:00
marshmellow42
dd57061c11 fix white spaces 2015-07-06 15:47:03 -04:00
Frederik Möllers
4be2708381 ISO 14443 type B support for EPA functionality
Added iso14443b_setup and iso14443b_apdu for general setup and
communication with ISO 14443 type B tags.
Updated EPA (German electronic ID card) functionality to support both
card types.
2015-07-06 18:01:34 +02:00
Frederik Möllers
bee99bbf90 Small spacing-related cleanups 2015-07-06 17:59:23 +02:00
marshmellow42
29b6cacc6f more verification on FDX-B tag demod - reduce...
... false positives
2015-07-05 23:35:00 -04:00
marshmellow42
7ce6e2c0b5 add -ss to hf 14b raw for select of SRx chips 2015-07-03 23:15:08 -04:00
marshmellow42
146600578c fix my understanding of REQB vs WUPB 2015-07-03 22:35:03 -04:00
marshmellow42
f3b83bee83 small fixes to 14b info, added 14b sim cmds 2015-07-02 15:04:09 -04:00
pwpiwi
db2b81ba11 Merge branch 'master' into topaz
Conflicts:
	client/Makefile
	client/cmdhf.c
	client/cmdhf14a.c
2015-07-01 08:17:00 +02:00
pwpiwi
6e6f1099c8 hf topaz reader: add support for dynamic lock areas 2015-07-01 07:12:10 +02:00
marshmellow42
5f605b8fc8 re-add piwi's trace memory fixes 2015-06-30 13:00:51 -04:00
marshmellow42
9d84e68964 fix 14b raw -s option, + get rid of...
<empty trace - possible error>
2015-06-30 09:46:37 -04:00
marshmellow42
463871be6e Merge remote-tracking branch 'upstream/master' 2015-06-29 22:30:18 -04:00
marshmellow42
1c7d367e24 update comments and changelog 2015-06-29 21:41:48 -04:00
marshmellow42
b8edab0f83 add -s to hf 14b raw to select a std 14b tag first 2015-06-29 21:33:10 -04:00
marshmellow42
c3ebcce424 fixed output bug in sri4k info output.
too many parameters line 299
2015-06-29 16:34:41 -04:00
marshmellow42
8e00825a34 fixed improper printBits usage. 2015-06-29 14:33:44 -04:00
pwpiwi
09ffd16ee2 - fix: ensure that FpgaDownloadAndGo() is always called before requesting
any memory from BigBuf[]. This is required because FpgaDownloadAndGo() might
  allocate, use, and free most of BigBuf[] when decompressing FPGA configs.
- cleanup: remove rests of deprecated "end of trace markers" (0x44)
2015-06-29 09:08:52 +02:00
pwpiwi
a88c28271c Merge pull request #125 from pwpiwi/hf_mifare_fix
(implementing suggestion #94)
2015-06-29 07:50:52 +02:00
marshmellow42
bf7ebb7b20 Merge remote-tracking branch 'upstream/master' into pm3+reveng
Conflicts:
	client/Makefile
2015-06-29 00:06:59 -04:00
marshmellow42
cc34cc7b56 add SRx tag lock bit to hf 14b info 2015-06-28 23:47:30 -04:00
marshmellow42
8a258b5880 re-order 14b reader/info functions to avoid warnings 2015-06-27 23:10:00 -04:00
marshmellow42
3e553c0817 Merge remote-tracking branch 'upstream/master' 2015-06-27 22:54:55 -04:00
marshmellow42
b29d55f24b change lf config threshold, hf 14b reader,
adjust lf config threshold to coincide with graph values and trigger on
highs over the threshold or lows under the threshold * -1

split general hf 14b reader from full info printing
2015-06-27 22:49:26 -04:00
Martin Holst Swende
86ed606758 Merge pull request #122 from marshmellow42/master
add hf 14b info command +
2015-06-27 21:51:23 +02:00
pwpiwi
377d692be1 fix compile error (issue #116): remove #include <time.h> in ARM sources 2015-06-25 16:58:54 +02:00
pwpiwi
dc8ba239fb (implementing suggestion #94)
hf mf mifare: gracefully exit if tag isn't vulnerable to this attack
hf mf nested: dito
2015-06-25 08:32:29 +02:00
pwpiwi
7b242c1ca2 fix: fpga_compressor file size check
- commit 61611f5 fixed the check in case of correct filesizes but fails
  in case of files which are too big to fit in fpga_config[]
- fix exit codes and Makefile to handle errors correctly during make
2015-06-25 08:16:48 +02:00
marshmellow42
9152bda817 Merge remote-tracking branch 'upstream/master' 2015-06-24 19:56:15 -04:00
Martin Holst Swende
a94349fc47 Merge pull request #123 from frederikmoellers/master
Fix comparison error in fpga_compress
2015-06-24 18:31:44 +02:00
Frederik Möllers
61611f5b85 Fix comparison error in fpga_compress
The comparison would check for greater-than-or-equal the maximum amount
of bytes to read/write when it should check for greater-than only.
2015-06-24 14:57:08 +02:00
pwpiwi
2da2e92837 Merge pull request #109 from pwpiwi/image_shrink
Compress FPGA configs and initialized data
2015-06-24 07:47:45 +02:00
marshmellow42
b7eddc14db update change log for adjusted 14b write cmd 2015-06-23 17:45:48 -04:00
marshmellow42
ff4fdb321f add 14b info command
add 14b to hf search
update change log
2015-06-23 17:41:24 -04:00
Martin Holst Swende
dd3d1b7012 Changelog 2015-06-23 22:24:55 +02:00
Martin Holst Swende
1e1de234ac Merge pull request #121 from frederikmoellers/master
Add PACE replay functionality
2015-06-23 22:23:08 +02:00
Martin Holst Swende
623e9da448 Merge branch 'master' of github.com:Proxmark/proxmark3 2015-06-23 22:19:15 +02:00
Martin Holst Swende
b8d34d0598 Merge pull request #118 from marshmellow42/master
fix t55xx write timing
2015-06-23 22:18:50 +02:00
Martin Holst Swende
475aefa595 Updated changelog 2015-06-23 22:12:03 +02:00
marshmellow42
2ec8773314 fix bug in pskdemod return value if no samples...
... caused crash in data psknexwatchdemod if no samples were in the
graphbuffer.
also fixed hf mfu wrbl and rdbl to allow printing of help without a tag
being present.
2015-06-23 12:16:23 -04:00
pwpiwi
01b7a6a898 Merge pull request #114 from pwpiwi/iso14443b_fix
fixing iso14443b (issue #103): fix bug introduced during Bigbuf rework
2015-06-23 07:14:52 +02:00
pwpiwi
705bfa1058 fixing iso14443b (issue #103):
- increased DMA_BUFFER_SIZE to avoid occasional circular buffer overflows.
- minor code cleanups
2015-06-22 22:03:43 +02:00
Frederik Möllers
3bb07d96c8 Add PACE replay functionality
This function allows the user to specify APDUs which are sent to a card
supporting the PACE protocol. The response times are measured and
printed.
The code was pulled from the old Google Code repository (branch "epa")
and modified to fit into the new code base.
2015-06-22 14:20:13 +02:00
pwpiwi
467340996e fixing iso14443b (issue #103):
- fix hf 14b snoop
- fix hf 14b sim
2015-06-21 18:04:24 +02:00
marshmellow42
7c8b5e6811 comment fudan check possibilities 2015-06-20 21:33:42 -04:00
marshmellow42
f4217d58b6 add ultralight compatible test 2015-06-18 17:19:43 -04:00
pwpiwi
da586b1702 fixing iso14443b (issue #103):
- revert removal of FPGA_HF_READER_RX_XCORR_848_KHZ. Need to be able to switch to 424kHz for ISO15693.
2015-06-18 15:41:30 +02:00
pwpiwi
9f9b6b7469 Merge pull request #120 from pwpiwi/fix_compile_errors
fix issue #116: remove includes of stdio.h in armsrc
2015-06-18 11:38:58 +02:00
pwpiwi
50365fedcb fix issue #116: remove includes of stdio.h in armsrc 2015-06-18 11:33:53 +02:00
pwpiwi
132a02179c fixing iso 14443b (issue #103):
- fix: treat empty commands as error
- deleting dead code
- rename USB-Commands (ISO14443 -> iso14443B)
2015-06-18 09:49:22 +02:00
pwpiwi
d5875804a3 fixing iso14443b (issue #103):
fix: don't waste time to calculate parity bits. Instead add void parity bits to trace and ignore them on client side
2015-06-18 07:56:08 +02:00
pwpiwi
51d4f6f114 fixing iso14443b (issue #103):
- fix: IQ demodulator (FPGA)
- fix: approximately align reader signal delay to tag response delay (FPGA)
- fix: remove deprecated RSSI calculation to improve decoder speed (iso14443b.c)
- fix: better approximation of signal amplitude to avoid false carrier detection (iso14443b.c)
- fix: remove initial power off in iso14443b raw command (iso14443b.c)
- add: enable tracing for iso14443b raw command (iso14443b.c)
- fix: client crashed when checking CRC for incomplete responses (iso14433b.c)
- speeding up snoop to avoid circular buffer overflow
- added some comments for better documentation
- rename functions (iso14443 -> iso14443b)
- remove unused code in hi_read_rx_xcorr.v
2015-06-17 20:27:36 +02:00
marshmellow42
c3dca45114 reveng - add some common use examples to -h help 2015-06-16 23:10:54 -04:00
marshmellow42
eb17726afa remove unused "width" 2015-06-15 22:40:30 -04:00
marshmellow42
6ac4cb270a minor fixes
see @icemant1001 -
0ad1a1d492
for more details
2015-06-15 00:44:57 -04:00
marshmellow42
954767dd95 added iceman1001 s latest reveng script version 2015-06-15 00:23:58 -04:00
marshmellow42
d679c29a4f @iceman1001 s compiler warning adjustment 2015-06-15 00:22:49 -04:00
marshmellow42
b43607e995 add reveng compile directory 2015-06-15 00:09:28 -04:00
marshmellow42
cf9aa77db0 remove commented out code from testing
also put back CMD_BUFFER_SIZE as I didn't need to change it in the first
place..
2015-06-15 00:03:16 -04:00
marshmellow42
ddcb2bb5ca Merge pull request #6 from marshmellow42/master
fix biphase
2015-06-14 18:12:16 -04:00
marshmellow42
9c823c1c87 comment change in config.h
this line indicates potential platform compatibility issues
2015-06-14 17:48:06 -04:00
Martin Holst Swende
26fbe1fbd9 Merge pull request #117 from marshmellow42/master
askbiphase bug fix
2015-06-14 19:32:36 +02:00
marshmellow42
fd227f4e7d add comment 2015-06-14 11:11:00 -04:00
marshmellow42
c7d6721290 bug fix. askdemod edits invert pointer, cannot be 0 2015-06-14 10:54:55 -04:00
Martin Holst Swende
0f5b97d92c Merge pull request #115 from marshmellow42/master
add-ons and bug fixes
2015-06-14 09:02:13 +02:00
marshmellow42
4a3f1a3793 revert t55xx start gap and write timing changes
also noted specs in comments
2015-06-11 23:52:40 -04:00
marshmellow42
330f65fbaf undo ARC rename, bug was fixed in scripting.c earlier 2015-06-11 23:09:15 -04:00
marshmellow42
5afe9838eb fix reveng CRC-16 bug 2015-06-10 11:01:01 -04:00
marshmellow42
d2219cae51 reveng -g (model search given just hexstr with crc) 2015-06-10 01:33:37 -04:00
marshmellow42
53ee28cb3a reveng- iceman1001 s scripting updates 2015-06-09 21:21:51 -04:00
marshmellow42
2e16354693 fix reveng memory bug + @iceman1001 s scripting 2015-06-09 13:40:01 -04:00
marshmellow42
7a23fca13a reveng RunModel - add endian switches 2015-06-08 23:14:11 -04:00
marshmellow42
37f4270a24 reveng add api RunModel 2015-06-08 21:22:18 -04:00
marshmellow42
2d3c535ec9 fixed bug in util getpraram8 + reveng adjustments
reveng:
fixed error handling some.
added -s option to GetModels()
2015-06-08 13:37:22 -04:00
marshmellow42
7e59994713 begin reveng add-ons for lua 2015-06-08 12:25:50 -04:00
marshmellow42
8e2e6c8eb0 add clock to ask rawdemod outputs
fix biphase invert bug (correctly)
2015-06-07 00:42:57 -04:00
marshmellow42
f46c366321 Fix reveng 2015-06-07 00:10:54 -04:00
marshmellow42
fe81b47811 add reveng-1.30
new command menu:
crc help
crc calc
crc calc -h for help on command set
2015-06-06 01:09:54 -04:00
marshmellow42
07b5a3c3ba Modified kermit crc to use existing crc calc code 2015-06-05 22:39:56 -04:00
marshmellow42
c2c7f6c271 fdx-b clean up 2015-06-04 13:10:33 -04:00
marshmellow42
6eaa8da9dc Add CCITT Kermit CRC check for FDX-B demod 2015-06-04 12:53:19 -04:00
marshmellow42
cf4d3e21b0 add fdx-b to cmddata.h 2015-06-04 00:05:37 -04:00
marshmellow42
ecfcb34cc5 add fdx-b to lf search 2015-06-04 00:04:49 -04:00
marshmellow42
b2c330b367 bug fix - biphase invert + fdx-b adjustments 2015-06-03 23:59:22 -04:00
marshmellow42
fd1d30cb76 addition animal tags demod info 2015-06-03 18:28:56 -04:00
marshmellow42
04bb05670d Testing animal tags 2015-06-03 16:52:20 -04:00
pwpiwi
09c66f1f09 fixing iso14443b (issue #103): fix timing issue (speeding up
the decoders)
2015-06-03 13:28:28 +02:00
pwpiwi
5b95953d42 fixing iso14443b (issue #103):
- most significant bit of tag data (which happens to be the sign bit)
had been dropped when snooping (FPGA change)
- avoid trying to decode both tag and reader data when snooping (we don't
have the time to do so).
2015-06-02 22:50:16 +02:00
pwpiwi
67ac4bf75c fix issue #103: revert type change. Samples from FPGA are signed.
Renamed iso14443.c to iso14443b.c
2015-06-02 07:28:47 +02:00
pwpiwi
01d5b635cf Merge pull request #113 from pwpiwi/iso14443b_fix
Fix issue #103 (hopefully). Quite an old bug which was previously
2015-06-01 20:02:40 +02:00
Martin Holst Swende
6a2e5adffd Merge pull request #108 from p-l-/fix-hf-mf-csave
Ported hf mf esave trick for unreadable UIDs to hf mf csave
2015-06-01 19:57:57 +02:00
Martin Holst Swende
daf8b85cda Merge pull request #111 from zhovner/master
Compiling manual for MAC OS X
2015-06-01 19:56:50 +02:00
pwpiwi
0d9a86c724 Fix issue #103 (hopefully). Quite an old bug which was previously
masked by a big DMA_BUFFER_SIZE.
2015-06-01 19:47:21 +02:00
marshmellow42
4a74e2be72 add my_d move lean identification. 2015-06-01 00:18:03 -04:00
marshmellow42
be290d68bd new lua script from @iceman1001 + bug fix in hf mfu 2015-05-31 16:08:58 -04:00
pwpiwi
97a0f5f4aa fix format strings for nit picking compilers 2015-05-31 19:51:44 +02:00
Martin Holst Swende
6cb08550c4 Merge pull request #112 from marshmellow42/master
combine mfu read/write commands + various bug/typo fixes
2015-05-31 13:08:36 +02:00
marshmellow42
1c4c0b0681 add @Iceman1001 s sha1 scripting changes. 2015-05-30 21:51:15 -04:00
pwpiwi
dc20a1f639 Fix linking under linux. liblua requires libld on linux. 2015-05-29 18:18:10 +02:00
marshmellow42
185e038c7d fixed further typo in lf t5 wr help
also fixed offset option char to uint8_t warning in the new offset
option in data printdemodbuffer
2015-05-28 23:14:06 -04:00
marshmellow42
5b37e87a24 fix help typo 2015-05-28 22:52:41 -04:00
marshmellow42
979bba376d add offset option to data printdemodbuffer
easily see demod buffer's hex values at different bit offsets by using:
data printdemodbuffer x o <offset>
2015-05-28 13:23:31 -04:00
pwpiwi
fbd0526b34 delete (yet) unnecessary file client/cmdhftopaz.c 2015-05-28 02:55:57 +02:00
marshmellow42
e35031d2b7 MFU code cleanup - final ?
fixed bug in debug print in MF 1k sim.
2015-05-27 17:21:42 -04:00
marshmellow42
4973f23d3c clean up mfu device side code
+ add xor calc to util (prep for desfire)
commented out MifareUWriteBlockCompat as it isn't used in client
currently (it is a command we could support..  but why?)
relabeled a few device side mfu functions to be clearer.
2015-05-27 12:24:13 -04:00
Pavel Zhovner
799b2e2e9d Compiling manual for MAC OS X 2015-05-27 11:30:50 +03:00
marshmellow42
be10fe2f11 update changelog 2015-05-27 00:32:01 -04:00
marshmellow42
dcbaa2b582 @iceman1001 s lua script fix 2015-05-26 20:31:07 -04:00
pwpiwi
8e074056ac also delete *.bin and fpga_compressor when "make clean".
Add target to make fpga_compressor when client is not yet compiled.
Get version information and cache it when client starts (avoids clearing
BigBuf when calling hw version).
Add some comments and remove debugging printouts.
Add version info and ChangeLog in modified zlib.
2015-05-26 18:12:40 +02:00
marshmellow42
22342f6dfe Add clearCommandBuffer before SendCommand
adjust output of mfu rdbl to be consistent
fix output of mfu dump in case startPage was specified. (also was
missing "i" in second print...)
2015-05-26 10:40:23 -04:00
pwpiwi
4b3f6d79ea Add option -d (decompress) to fpga_compress. Allows testing.
Improve zlib deflate (note: no change required to inflate).
2015-05-26 08:31:35 +02:00
pwpiwi
0fa01ec7da Compress the .data section as well (saves another 4KBytes and comes for free)
zlib tuning: prevent fpga_compress from generating fixed code blocks
armsrc/Makefile: replace osimage with fullimage
2015-05-26 08:31:32 +02:00
pwpiwi
28b9faccea Tailor zlib to our needs:
- disable support for fixed code blocks. Saves 2KByte code tables in ARM Flash memory
2015-05-26 08:31:30 +02:00
pwpiwi
fb22897415 fpga_compress: interleave (combine) fpga_lf.bit and fpga_hf.bit before compression.
fpga_loader.c: change to unweave fpga_lf and fpga_hf accordingly
prepare fpga_compress, fpga_loader and Makefile to handle more than two FPGA config files
revert removal of fullimage Makefile target. Remove osimage instead.
2015-05-26 08:31:28 +02:00
pwpiwi
f39198789b replaced gzip with an own compressor tool (fpga_compress.c, based on zlib)
This allows to remove the gzip header support and the z_crc32.[ch] files
(which saves more than 2KBytes of the ARM's flash memory)
2015-05-26 08:31:26 +02:00
pwpiwi
25056d8b47 Finish support for compressed FPGA images in fpgaloader.c
- move zlib source files to separate directory zlib
- rename zlib/crc32.[ch] to zlib/z_crc32.[ch]
2015-05-26 08:31:24 +02:00
pwpiwi
add4d47046 add: compress fpga images during compile, uncompress at run time 2015-05-26 08:31:21 +02:00
pwpiwi
e61530408c add: hw ver: show FPGA versions for both HF and LF FPGA configs
add: hw ver: show used and free flash memory
chg: prepare fpgaloader for compressed FPGA configs
2015-05-26 08:31:19 +02:00
Pierre LALET
1d537ad65c Ported hf mf esave trick for unreadable UIDs to hf mf csave
Thanks: iceman1001
2015-05-25 11:47:27 +02:00
marshmellow42
e406dd5cc9 Merge remote-tracking branch 'upstream/master' 2015-05-24 22:31:13 -04:00
marshmellow42
79d7bcbb51 updated mfu rdbl and wrbl commands
@iceman1001 s rdbl and wrbl cmd updates.
dump screen output adjusted
2015-05-24 22:28:21 -04:00
Martin Holst Swende
96c4f5517e Merge pull request #107 from p-l-/fix-hfmf
Fix filenames for hf mf cload / csave
2015-05-24 23:10:21 +02:00
Pierre LALET
292fe72535 Fix filenames for hf mf cload / csave 2015-05-24 22:43:08 +02:00
Martin Holst Swende
cae00c59ff Merge pull request #106 from p-l-/fix-hfmfeload
Fix filenames for hf mf esave / eload
2015-05-24 21:32:11 +02:00
Pierre LALET
0b14440dce Fix filenames for hf mf esave / eload 2015-05-24 20:14:22 +02:00
Martin Holst Swende
f0eaac9aca Merge pull request #102 from marshmellow42/master
fix mfu dump getbigbuffer bug
2015-05-24 07:22:09 +02:00
marshmellow42
0ce03d9ab0 fix mfu dump getbigbuffer bug
Thanks @iceman1001 for catching my oops, and fixing it :)
2015-05-23 22:35:50 -04:00
Martin Holst Swende
86724c17c9 Merge pull request #101 from marshmellow42/master
hf mfu updates + hf search + bug fixes
2015-05-22 21:55:34 +02:00
marshmellow42
012c0761bd hf mfu minor output adjustments
dump key placed properly for EV1 and NTAGs

config pages for ntags corrected in printout

note on config that PWD and PACK cannot
actually be read from memory  (probably could just delete them (other
than it shows what memory block they are stored in for changing...)
2015-05-22 13:17:51 -04:00
marshmellow42
8f2e50b4c5 mfu info authkeyptr fix
didn't follow @iceman1001 s l parameter changes fully...  fixed now..
:)
2015-05-22 07:29:18 -04:00
marshmellow42
06561c34ef fix to dump cmd print keys.
add l option to info cmd.
add ascii print to dump (screen only)
other minor clean up
2015-05-22 00:15:57 -04:00
marshmellow42
efd193519c hf mfu bug fixes, and help text fixes 2015-05-21 11:17:01 -04:00
marshmellow42
1c429594a1 further mfu info updates
needed to auth select when a command failed for locked tags.
some output cleanups from @iceman1001
2015-05-20 16:47:40 -04:00
marshmellow42
cd87ee9133 finish NTAG i2c +...
thanks iceman
2015-05-20 15:42:58 -04:00
marshmellow42
46fcd738e0 finish NTAG i2c +...
thanks @iceman1001
2015-05-20 15:41:48 -04:00
marshmellow42
8241872c47 ULEV1_48 had the wrong max block 2015-05-20 14:22:26 -04:00
marshmellow42
ea11861793 minor adjustments to hf mfu 2015-05-20 14:17:43 -04:00
marshmellow42
c7442b7673 Add NTAG i2c and bug fix
also streamlined select tag code
2015-05-20 14:06:46 -04:00
marshmellow42
a383f4b708 Add ntag 210, 212, 203 and bug fix 2015-05-20 11:27:44 -04:00
marshmellow42
a98b05b71d missed file in previous commit...
duh...
2015-05-19 15:03:35 -04:00
marshmellow42
d7acc6403e hf mfu dump - bigbuf allocation fix
some larger nfc tags can get large so set the allocation to the 4k
CARD_MEMORY_SIZE buffersize.
2015-05-19 11:30:50 -04:00
marshmellow42
29250969b0 @iceman1001 s comments/updates mfu cmds 2015-05-18 22:07:11 -04:00
marshmellow42
9d87eb6650 MF ultralight code cleanup 2015-05-18 13:11:00 -04:00
marshmellow42
8258f40969 Iceman1001 s MFU clean up
cleaned up MF UL_C auth code device side.
2015-05-17 20:49:25 -04:00
marshmellow42
cceabb79e6 mfu info / dump attempt at missing auths
NOT TESTED.  will test soon.  probably has bugs!
2015-05-16 01:00:31 -04:00
marshmellow42
ae8303c13c mfu dump - beginning of additions 2015-05-15 01:19:58 -04:00
marshmellow42
5b99376a8f hf mfu dump testing 2015-05-15 00:57:51 -04:00
marshmellow42
93737008ee @iceman1001 s default keys 2015-05-14 22:55:18 -04:00
marshmellow42
9ccfb3a8bc @iceman1001 's updated lualibs 2015-05-13 21:36:20 -04:00
marshmellow42
ab7fdfcbed @iceman1001 updated scripts 2015-05-13 21:20:23 -04:00
marshmellow42
d730878d8c scripting updates from @iceman1001
it compiles but i'm not sure how to fully test it...
:)
2015-05-13 21:14:35 -04:00
marshmellow42
6fdf42c61c minor hf mfu info adjustment from @iceman1001 2015-05-13 11:22:27 -04:00
marshmellow42
e6432f0579 @iceman1001 s coverity scan fixes 2015-05-13 11:14:17 -04:00
marshmellow42
2b3af97df2 various bug fixes 2015-05-13 11:07:47 -04:00
marshmellow42
a2e2bb8a15 hf mfu info - ICEMANS updates
plus slight change to UL_EV1 auth annotation.
2015-05-12 18:16:55 -04:00
marshmellow42
6ce0e5386a HF Search - refactoring cmds to work with it 2015-05-12 16:45:48 -04:00
marshmellow42
8ceb6b03e5 hf search - prelim - re-use hf mfu GetTagType...
in hf 14a reader to identify UL(+)

still a work in progress.
2015-05-12 00:19:44 -04:00
marshmellow42
2be768af57 hf mfu info bugs 2015-05-11 18:22:50 -04:00
marshmellow42
4693c188ab minor hf mfu output consistancies 2015-05-11 16:25:11 -04:00
marshmellow42
345fb24aaa hf mfu info - ICEMANS bug fixes. 2015-05-11 15:56:12 -04:00
marshmellow42
f04ef47311 hf mfu info bug fixes 2015-05-11 14:49:37 -04:00
marshmellow42
f805ac7a2b minor adjustments to mfu info 2015-05-08 13:01:27 -04:00
marshmellow42
c585a5cf0b further MFU info updates (mainly icemans) 2015-05-06 22:15:41 -04:00
marshmellow42
372a82570b MFU adj to allow 0 len returns on raw cmds 2015-05-06 10:17:39 -04:00
marshmellow42
45673b9457 MFU adjustment to allow 0 len returns from raw cmds 2015-05-06 10:16:31 -04:00
marshmellow42
abab60ae21 MFU info adjustments 2015-05-06 09:27:03 -04:00
marshmellow42
75377d29d6 MFU - Icemans further improvements
add UL-C device side read card with authentication
add MF_UL-Annotations
add ntag, and more ul descriptions in hf mfu info
2015-05-06 00:55:29 -04:00
marshmellow42
63e1d35a07 Merge remote-tracking branch 'upstream/master' 2015-05-03 23:31:58 -04:00
marshmellow42
f9848fd647 MFU dump UL-C with key
adding UL-C auth and keys to dump cmd
swapped endian for input of hf mfu crdbl to match output of hf mfu info
cmd and tag info app
2015-05-03 23:17:11 -04:00
Martin Holst Swende
4b36037948 Fixes to issue #100 2015-05-03 22:09:52 +02:00
marshmellow42
b3125340f3 Icemans UL-C Auth dev side fix plus a few other ...
... small UL fixes
2015-05-03 15:41:11 -04:00
marshmellow42
7eec1204e7 fix bug in mfu cauth 2015-04-30 10:34:20 -04:00
marshmellow42
92690507ab Iceman's updates to MFU info and dump 2015-04-30 09:28:43 -04:00
marshmellow42
f168b2633b MF Ultralight - Iceman's updates + mine
Beginning of Ultralight additions.
detection of Ultralight Types added
dump command now auto detects type
can authenticate Ultralight C
2015-04-29 18:27:31 -04:00
Martin Holst Swende
5023d4cea8 Merge pull request #99 from Drewgoo/patch-1
Update README.txt
2015-04-29 08:00:25 +02:00
Drewgoo
b0c76dd2cf Update README.txt
typo
2015-04-28 22:47:49 -06:00
Martin Holst Swende
2b90e3e670 Merge pull request #98 from marshmellow42/master
Iceman's fixes for #93, #96, #97
2015-04-28 23:08:28 +02:00
marshmellow42
bdfb62b405 Iceman's script aes fix #93
Thanks Iceman (note I did not have a tag to double test this one. :)
2015-04-28 15:53:07 -04:00
marshmellow42
e9b8d0dd6e Iceman's mf sim 7bt UID fix from #97 2015-04-28 15:43:58 -04:00
marshmellow42
4745afb647 Iceman's Issue #96 fix 2015-04-28 15:35:23 -04:00
Martin Holst Swende
a3abb02897 Merge branch 'master' of github.com:Proxmark/proxmark3 2015-04-23 09:51:04 +02:00
Martin Holst Swende
0e6c7336b0 Fixed issue with dumping iclass tags > 2KB in size 2015-04-23 09:50:44 +02:00
Martin Holst Swende
cb8220ee76 Merge pull request #92 from marshmellow42/master
lf cleanup, dedup & minor additions
2015-04-14 20:36:10 +02:00
marshmellow42
8e0cf02308 minor change to lf em4x menu & iceman script...
...updates
2015-04-10 00:06:59 -04:00
marshmellow42
664f658650 nexwatch fix .h file + icemans mf csetblk w arg
forgot to include the new nexwatch command in the header...
added icemans hf mf csetblk w parameter fix
2015-04-08 15:08:05 -04:00
marshmellow42
25d3e5cc83 Merge remote-tracking branch 'upstream/master' 2015-04-08 14:19:19 -04:00
marshmellow42
411105e036 added nexwatch demod & iceman lua
added nexwatch demod (also added to lf search)
added iceman's lua script adjustments
2015-04-08 14:19:03 -04:00
marshmellow42
322f7eb111 fix to lf t5 detect/read cmds
i think this functions fairly well...
still some issues with demod positioning for various reasons.
ASK/Biph/FSK work pretty well
the PSK Demod still needs a little attention to help it better demod
various carriers...
2015-04-08 11:18:29 -04:00
marshmellow42
9632ecbe3d update t5 detection test()
missed this file in last commit... sorry.
2015-04-08 10:12:24 -04:00
Martin Holst Swende
83602affe5 Fixed buffer initialization errors, as reported in http://www.proxmark.org/forum/viewtopic.php?pid=15337#p15337 2015-04-08 13:31:04 +02:00
marshmellow42
fef74fdce4 lf ask consolidation
backend:
askman and askraw demods merged into askdemod (args adjusted
accordingly)
re-arranged lfdemod.h in alphabetical order and by category

front end:
data detectclock a (ask) now also reports the selected best start
position for demod
data manrawdecode takes an invert arg now
2015-04-08 01:07:39 -04:00
marshmellow42
49bbc60af3 lf cleaning++
data askedgedetect - removed unneeded code
lf em em4x50read bug fix / error checking
graph-save/restore auto repaint after restore.
2015-04-07 00:53:06 -04:00
marshmellow42
cc15a1187b lf cleanup - fixes
more lf em em4x50read fixes
adjust heavy clipping ask clock detection
clean up t55xx minor items
2015-04-06 23:17:30 -04:00
Martin Holst Swende
2c772e6cf0 Added info to changelog about bootroom update 2015-04-06 21:47:09 +02:00
marshmellow42
1f918317e2 add maxErr to data manrawdecode 2015-04-05 21:59:36 -04:00
marshmellow42
224ce36eb1 lf t5xx - icemans update 2015-04-05 16:37:41 -04:00
pwpiwi
6306ff4bac Merge branch 'master' into topaz
Conflicts:
	armsrc/Makefile
	client/Makefile
2015-04-05 19:45:59 +02:00
marshmellow42
2767fc0291 lf cleaning
remove unneeded code/functions
fix lfdemod askmandemod bug with maxErr=0
silence output for getting samples in lf search
2015-04-05 00:58:57 -04:00
marshmellow42
643fb10b2d Merge remote-tracking branch 'upstream/master' 2015-04-04 21:29:16 -04:00
marshmellow42
acaeccf841 update changelog 2015-04-03 00:40:38 -04:00
marshmellow42
6e98444637 lfdemod reduce duplicate code
remove check for best start position in demods and adjust the clock
detect to always return best start position to the demods
also small bug fix in lf em em4x50read
2015-04-02 23:55:12 -04:00
marshmellow42
23f0a7d862 lfem4x cleanup/add/fix
changed spacing to tabs for cmdlfem4x.c
finished the partially built lf em em4x50read function
added save/restore GraphBuffer function in graph.c
adjusted some tolerances in lfdemod.c
added a maxLen argument to the askmandemod
2015-04-02 12:48:52 -04:00
Martin Holst Swende
9795e535c9 Compiler correctly identified a buffer overflow, fixed that and made the code use snprintf instead of unsafe sprintf 2015-04-01 09:24:29 +02:00
pwpiwi
f83c41c75b Merge pull request #89 from pwpiwi/image_shrink
Reclaim more than 19K of ARM flash memory.
2015-03-31 22:57:33 +02:00
Martin Holst Swende
d5d6f22718 Merge pull request #91 from marshmellow42/master
lfdemod.c refactoring  (+ bug fixes)
2015-03-31 22:11:19 +02:00
pwpiwi
7009555e44 temporarily revert lfdemod float removal 2015-03-31 21:38:58 +02:00
marshmellow42
a4669d6ef3 small fix in t5 trace data 2015-03-31 11:30:16 -04:00
marshmellow42
75cbbe9a69 remove floats per piwi 2015-03-31 10:49:06 -04:00
pwpiwi
e335ca2846 Reclaim more than 19K of ARM flash memory.
- added compiler options -fdata-sections and -ffunction-sections (thanks to iceman for the hint)
- removed float operations from common/lfdemod.c to avoid adding float libraries to the ARM os image
- moved the fpga images to the data section to avoid reserving unused space for a separate section
2015-03-31 08:07:26 +02:00
pwpiwi
c5847ae8af refactoring hf topaz reader 2015-03-31 07:09:55 +02:00
Martin Holst Swende
616970b3d1 Created a changelog, to be used in accordance with http://keepachangelog.com 2015-03-30 07:51:45 +02:00
Martin Holst Swende
caaf9618ae Minor mod to 'hf iclass read', it now also reads and prints the configuration of the tag found 2015-03-29 21:49:58 +02:00
marshmellow42
070e3c4305 Merge remote-tracking branch 'upstream/master' 2015-03-27 23:49:14 -04:00
marshmellow42
f8f894a50f rawdemod param cleanup
plus lfdemod.h cleanup
2015-03-27 23:47:31 -04:00
marshmellow42
2eec55c8a4 lfdemods streamline & bug fixes
removed duplicate code countPSK_FC - adjusted countFC to work.
bug fixes & streamlined code in:
lf hid fskdemod
lf em em410xdemod

cleaned up lfdemod.c some
2015-03-27 00:02:30 -04:00
pwpiwi
de15fc5fe3 add: hf topaz reader (basic functionality) 2015-03-25 22:00:48 +01:00
Martin Holst Swende
337288f9ac Merge pull request #86 from marshmellow42/master
Fixed indents to Tabs from Spaces
2015-03-25 20:23:41 +01:00
marshmellow42
e0165dcf3a Fixed indents to Tabs from Spaces
Spacing changes ONLY - no code changes
2015-03-25 14:24:36 -04:00
Martin Holst Swende
062e28912c Merge pull request #84 from marshmellow42/master
EM410x bug fix
2015-03-25 11:10:51 +01:00
marshmellow42
327a690813 EM410x bug fix 2015-03-24 23:05:46 -04:00
marshmellow42
c7d169ec02 clean up em410x output 2015-03-24 22:11:32 -04:00
marshmellow42
90677ad99b EM410x bug fix 2015-03-24 20:26:14 -04:00
Martin Holst Swende
90a8b82fb4 Merge pull request #82 from marshmellow42/master
lf ata55x7 commands and more
2015-03-24 11:10:16 +01:00
marshmellow42
9680b11d9e remove debugging print calls 2015-03-23 20:25:54 -04:00
marshmellow42
1fbf895616 lf updates
applies icemans full ata55x7 read/write settings
adds checksum to ioprox (thanks to iceman)
adds silent mode for lf read and getSamples
fix lf em em410xwatch and lf em410xspoof
improve data rawdemod ar -  for biphase demods
improve detectclock a for strong antennas
2015-03-23 16:29:50 -04:00
marshmellow42
13d77ef964 lf t5 read plus lf demod adjustments
lf t5xx commands updated from ICEMAN
lf em410x commands updated
lf search bug fix for 2 args
test scripts from iceman
lf demod:
better ask clock detection with Strong fully clipped waves
better ask raw demod with strong fully clipped waves
fsk demod add back in skipped bits during demod
nrz demod add back in skipped bits during demod
2015-03-22 15:28:48 -04:00
pwpiwi
48ece4a750 add: Topaz mode for "hf 14a raw" (new option -T)
chg: allow tracing without parity
chg: make "hf list topaz" aware of additional commands for Dynamic Memory Model
2015-03-20 21:06:51 +01:00
pwpiwi
05ddb52c43 fix: introduced a stupid error when refactoring the start bit detector in MillerDecoding()
chg: use -O2 instead of -Os when compiling ARM sources
chg: don't clear the Miller decoders input buffer on reset
chg: be more specific for the Miller decoders start bit pattern
add: new option c in hf list: mark CRC bytes (default is off)
2015-03-18 18:32:43 +01:00
pwpiwi
ef00343cb1 revert change "hf list topaz" to "hf list nfc"
refactored Startbit detection in MillerDecoding()
relaxed startbit detection in MillerDecoding()
fixed CRC checking and CRC bytes marking in hf list
fixed topaz multi frame command listing in hf list topaz
2015-03-17 07:41:08 +01:00
Martin Holst Swende
29a7954177 Merge pull request #80 from marshmellow42/master
FIX EM Error
2015-03-16 14:03:48 +01:00
marshmellow42
2147c30778 FIX EM Error
missed two files for last push..  sorry
2015-03-16 08:39:18 -04:00
Martin Holst Swende
2e7e107c82 Merge pull request #78 from marshmellow42/master
add pyramid CS, minor psk demod fixes, minor g-prox-ii demod fix, autocorrelate improvement
2015-03-16 11:39:03 +01:00
marshmellow42
b41534d142 adjust ask/biphase handling - more complete
also added XL EM410x formats
2015-03-15 22:03:50 -04:00
pwpiwi
a8904ebd46 Change "hf list topaz" to "hf list nfc"
fix: reduce length of expected unmodulated signal in Miller decoder in order
to allow decoding of NFC reader communications
add: hf list nfc: aggregate reader commands into one line
add: hf list nfc: CRC check for NFC communications
2015-03-15 16:49:09 +01:00
marshmellow42
7a8a982bde adjust pskdemod
add skipped bits before first phase back in
PSKDemod now returns 1 for success or 0 for fail like other demods
2015-03-13 20:49:34 -04:00
marshmellow42
e74fc2ecba give credit where credit is due
thanks iceman for the crc :)
2015-03-13 14:00:11 -04:00
pwpiwi
ee1eadee0f add: start to support Topaz tags
- hf 14a reader now exits gracefully in case of proprietary anticollision sequence
- changed miller decoder to handle Topaz 8 data bits/no parity frames from reader
- started to implement hf list topaz
2015-03-13 18:13:18 +01:00
marshmellow42
9f7bbd24c9 data autocorr additions 2015-03-13 12:23:26 -04:00
marshmellow42
5279085ae7 Merge remote-tracking branch 'upstream/master' 2015-03-13 11:20:00 -04:00
marshmellow42
d9d41e0f3f minor g-prox-ii demod fix
lf search was occasionally outputting false results.
2015-03-13 11:18:55 -04:00
marshmellow42
73d04bb417 data psk demod minor fixes, pyramid demod add CS
also adjusted autocorrelate and added a printout for lf search u
2015-03-13 11:09:12 -04:00
pwpiwi
9185099ed8 Merge pull request #75 from pwpiwi/qtmakefile
(issue #47) use Qt5 includes and libraries, if present
2015-03-13 07:24:56 +01:00
Martin Holst Swende
aaa9f05e31 Merge pull request #77 from Proxmark/usb_check
Implemented usb_poll() within LF sim.
2015-03-12 18:15:08 +01:00
Martin Holst Swende
f7048dc8a9 Implemented usb_poll() within LF sim. This means the LF sim will be aborted whenever something comes over the USB 2015-03-12 16:32:01 +01:00
pwpiwi
04bc1c660b fix: hf 14a raw was broken
(see http://www.proxmark.org/forum/viewtopic.php?id=2351)
2015-03-11 20:19:30 +01:00
pwpiwi
8c04722db6 (issue #47) use Qt5 includes and libraries, if present 2015-03-10 19:00:39 +01:00
Martin Holst Swende
58e93ff593 Merge pull request #74 from marshmellow42/master
new and fixed lf sim commands, lf demod refactoring, data gproxIIdemod
2015-03-10 00:25:51 +01:00
marshmellow42
1302428367 finish data printdemodbuffer command 2015-03-09 16:56:00 -04:00
pwpiwi
16a95d76ac fix: (issue #73) hf mf cload didn't work. Add more annotations for Magic Cards operation. 2015-03-09 21:36:27 +01:00
marshmellow42
5658e82e1e sim buffer max settings tests 2015-03-09 15:58:06 -04:00
marshmellow42
ada339a10f biphase bug fixes 2015-03-09 15:27:20 -04:00
pwpiwi
30364d2711 fix: broken edge detector implementation in hi_iso14443a.v resulted in decreased sensitivity 2015-03-09 20:01:37 +01:00
marshmellow42
d66d484347 fixed rawdemod help options 2015-03-08 18:07:01 -04:00
marshmellow42
712ebfa6df 1 bug fix + code trimming 2015-03-07 23:31:23 -05:00
marshmellow42
df51693f95 Merge remote-tracking branch 'upstream/master' 2015-03-06 12:30:16 -05:00
marshmellow42
78f5b1a77c lf sim fixes/creations correct now
fixed lf simpsk
fixed lf em em410xsim
fixed lf sim  (can go right from lf search to lf sim if you have a
strong antenna - if not use a demod first)
2015-03-06 12:28:54 -05:00
marshmellow42
e09f21fa7b Revert "lf sim fixes/creations"
This reverts commit 293de1bad7.
2015-03-06 12:26:33 -05:00
marshmellow42
293de1bad7 lf sim fixes/creations
fixed lf simpsk
fixed lf em em410xsim
fixed lf sim  (can go right from lf search to lf sim if you have a
strong antenna - if not use a demod first)
2015-03-06 12:25:36 -05:00
pwpiwi
7843130a58 fix: (issue #72) LF simulation didn't work with lo_edge_detect.v 2015-03-06 07:42:54 +01:00
ikarus
9cefee6f42 Fixed issue #36 & improved file consistency. 2015-03-04 11:00:39 +01:00
marshmellow42
39676885b4 Merge remote-tracking branch 'upstream/master' 2015-03-03 20:44:37 -05:00
marshmellow42
11081e0459 finish gProxII_Demod 2015-03-03 16:20:18 -05:00
Martin Holst Swende
c8387e85e3 iClass full simulation of tags now officially works, with some cheating regarding reader update and write commands 2015-03-02 21:30:22 +01:00
Martin Holst Swende
27eabcdccb Added brackets around crc field in protocol listings 2015-03-02 21:05:44 +01:00
marshmellow42
40b9bb85e6 oops... should this file should not have been there 2015-03-02 14:44:05 -05:00
marshmellow42
8d960002c8 lf cmds fix, add, show
show command to UI:
data printdemodbuffer - allow printing of demod buffer
Add:
data askgproxiidemod - demod a gproxii tag

Fix:
adjust lf simxxx commands further for testing
2015-03-02 14:42:55 -05:00
Martin Holst Swende
e5cd4ee4b4 Tag MAC finally works! (Full sim not yet, though) 2015-03-02 20:14:35 +01:00
Martin Holst Swende
61fe90736b Implemented the correct way to calculate MAC from a tag, feeding it an extra 32 zeroes. Also divided it up into two parts, one of which can be precalculated by the device before the simulation begins 2015-03-02 00:38:36 +01:00
marshmellow42
73da818743 lf simulation tests
added SimulateTagLowFrequencyTest function
with some adjustments that help ASK simulations
FSK and PSK still need help.  Left original HID sim alone as for some it
may partially work.
2015-02-28 14:33:05 -05:00
Martin Holst Swende
c99dc845b1 Added the ciphers also.. doh 2015-02-27 20:19:10 +01:00
Martin Holst Swende
188b2dbec4 Merge branch 'master' of github.com:Proxmark/proxmark3 2015-02-26 20:35:54 +01:00
Martin Holst Swende
10a8875c72 Implemented new optimized version of MAC-calculation for iclass 2015-02-26 20:35:35 +01:00
marshmellow42
ec9882b18c PSKDemod Bug Fix 2015-02-22 21:11:25 -05:00
marshmellow42
3f41e73c7f PSK demod adjustment
add carrier length test to weed out false positive demods
2015-02-22 20:09:58 -05:00
marshmellow42
3bc66a96fe added PSK2 to lf simpsk
testing still ongoing.
2015-02-21 22:54:52 -05:00
marshmellow42
872e3d4d6f NEW lf simpsk 2015-02-21 21:36:02 -05:00
marshmellow42
b4a2fcf676 Split output from nrz raw demod function
missed this one last time
2015-02-21 18:37:15 -05:00
Martin Holst Swende
b19caaefc2 Fixed minor bugs in iclass fullsim, does not work yet though 2015-02-21 20:47:40 +01:00
marshmellow42
4ac906d1c2 split output from rawdemod functions
now allows for non-verbose calling:
ASKmanDemod
ASKrawDemod
FSKrawDemod
PSKDemod
2015-02-21 00:27:48 -05:00
marshmellow42
40148ab609 Merge remote-tracking branch 'upstream/master' 2015-02-19 21:38:17 -05:00
marshmellow42
abd6112fc4 Revert "Revert "lf simask, lf simfsk and bug fixes""
This reverts commit e396001c47.
2015-02-19 21:35:34 -05:00
marshmellow42
e396001c47 Revert "lf simask, lf simfsk and bug fixes"
This reverts commit fb0c84c3df.
2015-02-19 21:22:05 -05:00
marshmellow42
fb0c84c3df lf simask, lf simfsk and bug fixes 2015-02-19 21:21:11 -05:00
Martin Holst Swende
0387cd3393 Merge pull request #68 from iceman1001/feature
ADD: identifications.
2015-02-19 10:51:10 +01:00
Martin Holst Swende
181e6db6a9 Merge pull request #67 from marshmellow42/master
Small help and command description updates
2015-02-19 10:50:51 +01:00
Martin Holst Swende
1defcf606f More work on iclass full simulation, and some work on iclass tag dump parsing 2015-02-19 10:48:33 +01:00
Martin Holst Swende
b67f7ec359 Further implementation of iclass 'fullsim'. Moved protocol definitions to shared file. Had to add some loclass-function to arm-side to support authentication in fullsim mode 2015-02-18 20:02:44 +01:00
Martin Holst Swende
9a9bcea82b Iclass decrypt error, shouldn't have decrypted block 6 according to Heart of darkness-paper 2015-02-17 23:17:43 +01:00
Martin Holst Swende
41524d8a39 Implemented 'hf iclass decrypt <tagdump>'. This performs the 3des decryption of iclass tag dumps, but requires the decryption file to be present on the filesystem 2015-02-17 22:07:40 +01:00
iceman1001
0853ffa29c ADD: added the missing EM identifications. Thanks to Asper for providing the needed information about LC ID's 2015-02-16 19:06:24 +01:00
iceman1001
33315928fb CHG: added some more token-tags. 2015-02-16 19:05:59 +01:00
marshmellow42
8db0534ed1 Merge remote-tracking branch 'upstream/master' 2015-02-14 21:16:27 -05:00
marshmellow42
cc2ea5ed82 Clean up Helps and command descriptions 2015-02-14 21:15:13 -05:00
Martin Holst Swende
e80aeb9695 Started iclass emulator support on device side. Not functional yet 2015-02-14 21:30:26 +01:00
Martin Holst Swende
a4749080d9 Removed un-implemented 'hf iclass write', it's confusing to have there since there's no actual support for this on the device side 2015-02-14 21:18:39 +01:00
Martin Holst Swende
534445139c Reformatted 2015-02-14 21:17:08 +01:00
Martin Holst Swende
7781a65656 Started work on 'hf iclass eload' - only client side so far, not yet supported in the device 2015-02-14 21:15:53 +01:00
Martin Holst Swende
428d622160 Fixed bug with iclass dump which prevented saving to file 2015-02-14 20:42:23 +01:00
Martin Holst Swende
0cd2a41ac0 Made 125KHz default sampling, instead of 134KHz for LF 2015-02-14 19:55:23 +01:00
marshmellow42
abd16c456a fix help on data rawdemod commands 2015-02-13 21:17:15 -05:00
Martin Holst Swende
2e2fc9fa6b Merge branch 'master' of github.com:Proxmark/proxmark3 2015-02-13 19:59:50 +01:00
Martin Holst Swende
699bb9dc27 Removed some dev- printouts 2015-02-13 19:59:28 +01:00
Martin Holst Swende
17c60b1248 Merge pull request #63 from marshmellow42/master
lf data combine rawdemods & depreciate cmds
2015-02-13 10:11:40 +01:00
Martin Holst Swende
37735250ca Merge pull request #66 from iceman1001/feature
ADD:  identification of EM4233
2015-02-13 10:11:09 +01:00
Martin Holst Swende
8b9393d3bd fixed issue #65 2015-02-12 08:21:58 +01:00
pwpiwi
19a700a8b5 hf 14a: if the tag supports it, set default timeout according to ATS
hf epa: remove explicit but arbitrary timeout settings
Bugfix: don't timeout when frame transmission has already started
2015-02-11 22:20:22 +01:00
pwpiwi
7554370c30 bugfix hf 14a sim / hf mf sim: polarity of tag subcarrier modulation was wrong 2015-02-11 21:14:34 +01:00
iceman1001
070e36d421 ADD: identification of EM4233 2015-02-11 17:14:26 +01:00
Martin Holst Swende
24cbeb3d27 Merge pull request #58 from Proxmark/GenericTracing
Generic tracing
2015-02-10 21:27:47 +01:00
Martin Holst Swende
61972abbdd Merge branch 'master' into GenericTracing
Conflicts:
	armsrc/iso14443a.c
2015-02-10 21:25:14 +01:00
pwpiwi
92bf686817 Merge pull request #64 from jessegit/csetuidfix
Add settable ATQA and SAK to hf mf csetuid command.
2015-02-10 07:27:06 +01:00
Jesse Hallio
3bba7deac0 Add settable ATQA and SAK to hf mf csetuid command. 2015-02-10 04:31:53 +02:00
marshmellow42
7e72f90a7f Merge remote-tracking branch 'upstream/master' 2015-02-09 16:47:24 -05:00
pwpiwi
0d0d049967 hw tune, data tune: adjusted "unusable" and "marginal" voltages. Display LF tuning graph only when LF antenna is connected. 2015-02-09 22:36:53 +01:00
marshmellow42
19ff0210fa lf data combine rawdemods & depreciate cmds
new:
data rawdemod
replaces:
data askmandemod
data askrawdemod
data fskrawdemod
data nrzrawdemod
data psk1rawdemod
data psk2rawdemod

also commented out of the CommandTable but did not remove the commands:
data askdemod
data bitstream
data fskdemod
data mandemod
data threshold
2015-02-09 16:25:12 -05:00
Martin Holst Swende
904a96cd80 Merge pull request #59 from marshmellow42/master
lf demod additions/fixes
2015-02-09 20:28:12 +01:00
marshmellow42
f3bf15e484 lf/data combined detectclock functions to one
cleaned up detect clock functions - now uses one main function that
takes a char argument to select which modulation to detect the clock for
REMOVED commands: pskdetectclock, nrzdetectclock, fskfcdetect.
renamed DetectClock function to DetectAskClock to be more descriptive.
2015-02-09 11:11:04 -05:00
pwpiwi
0c8d25ebd8 Fixed: hf mf sim failed on fast reader responses
In Miller Decoder: don't wait too long for a stable signal
In Miller Decoder: Don't accept sequences of four or more zeroes as start bit
In EmSendCmd14443aRaw: don't wait for emptying the FPGA delay queue if it isn't filled
2015-02-09 06:51:04 +01:00
pwpiwi
6d3e6c740b Merge pull request #60 from pwpiwi/master
Bugfix hw tune, hf tune: voltage measures were VERY wrong
2015-02-08 22:09:42 +01:00
marshmellow42
b4fb11ba92 fix inconsistent spacing within functions
did not convert spaces to tabs but made the functions consistent with
what it used so it can be auto converted.
(sorry for the annoying space/tab usage in the past.)
we can convert all to tabs later.
2015-02-08 00:48:00 -05:00
Martin Holst Swende
beefe5bc4d Minor dox 2015-02-07 21:22:53 +01:00
Martin Holst Swende
665775c844 Some documentation and formatting to LogTraceHitag 2015-02-07 21:05:14 +01:00
Martin Holst Swende
aabb719dc4 Moved LogTraceHitag to BigBuf (no changes to the function ... yet) 2015-02-07 20:55:17 +01:00
Martin Holst Swende
3000dc4e7e Generic tracing; removed iso14a_XX-functions, removed traceLen as global varible 2015-02-07 20:49:40 +01:00
pwpiwi
3b692427ac Bugfix hw tune, hf tune: voltage measures were VERY wrong
Modified hw detectreader: display reader field strength in mV units and to be less phony
2015-02-07 10:14:49 +01:00
marshmellow42
be2cf126bf Merge remote-tracking branch 'upstream/master' 2015-02-06 14:45:46 -05:00
marshmellow42
6de4350803 data askraw patches, data askedgedetect demod,
data askraw patches - added amp option (for stubborn waves)
NEW data askedgedetect demod for manual demod,
adjusted detectclock (ask clock) in case of cleaned (edgedetect) waves
finish maxErr args
finish psk detect
2015-02-06 14:36:25 -05:00
Martin Holst Swende
7d5ebac993 Merge branch 'master' into GenericTracing
Conflicts:
	armsrc/iso14443.c
	armsrc/iso14443a.c
	client/cmdhf.c
	client/cmdhf14b.c
2015-02-06 08:41:02 +01:00
marshmellow42
e770c64824 lf psk/nrz split, add maxErr argument
changed psk to use wave lengths instead of peaks
split out NRZ from psk demod
added maxErr argument to raw demods (except fsk)
2015-02-05 17:01:18 -05:00
Martin Holst Swende
146c201cbe Merge pull request #55 from jessegit/master
Add flasher from SVN r623 for HID bootprom and current Mac OS X kext
2015-02-05 19:43:46 +01:00
Martin Holst Swende
b37235637f Merge pull request #57 from iceman1001/feature
FIX:  LF TI WRITE inparameters didn't get copied by sscanf.
2015-02-05 19:43:26 +01:00
Martin Holst Swende
bb42a03ef1 Fix #1 for pm3 iclass simulation, remove erroneous extra bit after transmission 2015-02-05 19:40:47 +01:00
iceman1001
5c2b11eb3c FIX: LF TI WRITE inparameters didn't get copied by sscanf. This removes the "PRIu64" and uses the 012"llx" instead. 2015-02-05 15:46:23 +01:00
Martin Holst Swende
73a1c1bb97 Merge pull request #56 from iceman1001/feature
add: lots of new toytypes  in default_toys.lua
2015-02-05 15:28:18 +01:00
iceman1001
a6cfa75035 add: lots of new toytypes in default_toys.lua
fix: mixture between dec & hex numbers caused wrongly identifications of toytypes (default_toys.lua)
add: showing bytes for trap-types in tnp3dump.lua
2015-02-04 11:49:21 +01:00
Jesse Hallio
e9281ae812 Add flasher from SVN r623 for HID bootprom and current Mac OS X kext 2015-02-03 23:22:39 +02:00
Martin Holst Swende
1f78a4d305 Merge pull request #54 from Proxmark/lf_recorder
LF: Ability to do longer traces/snoops
2015-02-02 19:54:07 +01:00
Martin Holst Swende
0644d5e3a3 Merged with master 2015-01-31 18:21:38 +01:00
Martin Holst Swende
c856ceae8a Fixed undecimation command 2015-01-31 12:42:40 +01:00
Martin Holst Swende
698b649e0e Added undec to un-decimate data on the client side, so we can use all those sweet demodders even if the data has been decimated on the ARM side 2015-01-31 00:05:04 +01:00
Martin Holst Swende
31abe49fd3 Some more fixes to longer lf recordings. Now also supports longer snoops, and an additional command 'lf config' has been defined, instead of having to specify all params for every call 2015-01-30 23:03:44 +01:00
Martin Holst Swende
15491b2d73 Merge pull request #53 from iceman1001/feature
bounds check for loop - printDemodBuff
2015-01-30 15:18:18 +01:00
Iceman
0c5998c051 Update cmddata.c
as suggested,  a bitwise bounds check in cmddata.
2015-01-30 15:17:07 +01:00
iceman1001
33c7e2f3bc wrong letter in variable name
Conflicts:
	client/cmddata.c
2015-01-29 22:35:19 +01:00
Martin Holst Swende
92623113b4 Minor documentation on 'hf list' 2015-01-29 20:01:30 +01:00
Martin Holst Swende
b3cc5f2987 Reverted erroneous commit from bigbuf-rework 2015-01-29 19:58:46 +01:00
Martin Holst Swende
63e420b572 Merge pull request #51 from marshmellow42/master
fix hid prox standalone bug
2015-01-29 01:11:10 +01:00
Martin Holst Swende
f6d9fb173f Added client-side support for recording longer samples, fixed last (?) issues on device-side 2015-01-29 00:57:22 +01:00
marshmellow42
0892b968ce fix hid prox standalone bug
Fixed standalone bug by re-making the function return the hi and lo
values. (used only by samyrun function in appmain.c)
2015-01-28 12:55:04 -05:00
Martin Holst Swende
4c18913dd8 Merge pull request #50 from marshmellow42/master
lf hid fskdemod bug
2015-01-28 18:45:02 +01:00
marshmellow42
08ebca682c lf hid fskdemod bug
re-introduced in last bigbuf changes
2015-01-28 11:45:31 -05:00
pwpiwi
f71f4deb8f BigBuf and tracing rework: allow much longer traces in in hf commands
- provided a BigBuf_malloc() function to dynamically allocate parts of BigBuf
  e.g. for DMA-Buffers, Frame-Buffers, Emulator-Memory
- the whole rest of BigBuf is now available for traces (instead of a small fixed amount)
- send actual traceLen together with trace data
- changed client side to cope with varying traceLen
- changed small buffers to automatic variables instead of parts of BigBuf
2015-01-28 07:18:51 +01:00
pwpiwi
117d9ec25c Refactoring of BigBuf handling in order to prepare for more efficient memory allocation and longer traces. 2015-01-27 22:25:55 +01:00
Martin Holst Swende
936e0729f9 Merge pull request #49 from marshmellow42/master
LF Demod Bug Fix & new traces
2015-01-27 22:14:39 +01:00
marshmellow42
88a3e9433d Revert "Revert "Traces""
This reverts commit 58f478696d.
2015-01-27 16:08:15 -05:00
marshmellow42
003ac42c71 Revert "Revert "More Testing Traces""
This reverts commit eb0b5130f2.
2015-01-27 16:08:08 -05:00
marshmellow42
eb0b5130f2 Revert "More Testing Traces"
This reverts commit f4e739ed58.
2015-01-27 16:05:10 -05:00
marshmellow42
58f478696d Revert "Traces"
This reverts commit 7f9064c641.
2015-01-27 16:05:05 -05:00
marshmellow42
7f9064c641 Traces 2015-01-27 15:56:03 -05:00
Martin Holst Swende
383608a63a Minor fixes to iso14443a annotations 2015-01-27 21:55:08 +01:00
marshmellow42
f4e739ed58 More Testing Traces 2015-01-27 15:09:45 -05:00
marshmellow42
a1d17964a2 lf demod bug fix & refactor
fixed bug in lfops.c in hid fskdemod
refactored data fskXXXDemods for specific tags to use more common code.
2015-01-27 14:51:12 -05:00
Martin Holst Swende
08e8317c21 More annotations to iso14443b protocol listings 2015-01-27 16:34:45 +01:00
Martin Holst Swende
16b75f27c3 Minor tweaks to iso14443b snoop tracing 2015-01-27 16:34:11 +01:00
Martin Holst Swende
f50d457fa8 Merge pull request #48 from marshmellow42/master
lf demod additions & bugfixes from marshmellow
2015-01-27 10:21:22 +01:00
Martin Holst Swende
03dc174036 Minor refactoring 2015-01-27 09:06:01 +01:00
marshmellow42
8c65b650e8 clean up some comments 2015-01-26 17:49:30 -05:00
marshmellow42
04d2721b3c lf psk demods
clarify existing as psk1
added psk2 demod
2015-01-26 17:23:19 -05:00
marshmellow42
9c0f13d5dd Merge remote-tracking branch 'upstream/master' 2015-01-26 17:07:49 -05:00
Martin Holst Swende
aeadbdb216 Generic tracing: Some fixes in iso14443b snooping, to how DMA access is performed, sizes and buffers. 2015-01-26 22:10:05 +01:00
Martin Holst Swende
7c676e7269 Some documentation 2015-01-26 21:15:28 +01:00
Martin Holst Swende
2595390c6d Merge pull request #46 from holiman/master
Iceman's changes, part 2
2015-01-26 20:59:36 +01:00
Martin Holst Swende
dca558bf9e Removed last trace of crypto from makefile 2015-01-26 20:56:33 +01:00
Martin Holst Swende
7242efa07c bugfix 2015-01-22 23:04:59 +01:00
Martin Holst Swende
cb366e9dbd Added a lf acquisition-mode which can do decimation and quantization, in order to be able to record longer transactions 2015-01-22 23:01:29 +01:00
Martin Holst Swende
e629181f5a Fixed issue where -1 size_t was returned 2015-01-22 21:04:16 +01:00
Martin Holst Swende
afceaf4018 Removed openssl from the mfu-stuff 2015-01-22 21:02:21 +01:00
marshmellow42
03e6bb4aed lf FSK demod tools/fixes
added full ability to detect FSK clocks
applied autodetect of fsk clock to data fskrawdemod
this finished data fskfcdetect (now detects field clocks and bit clock)
2015-01-22 14:24:03 -05:00
Martin Holst Swende
3fd26a683d On another note; a nice udev-rule to have pm3 appear as /dev/pm3-1 (or /dev/pm3-2 if you have multiple) 2015-01-22 00:33:49 +01:00
Martin Holst Swende
388c92bde5 Generic tracing pt.4: Deprecated old 'hf 14b list' command 2015-01-22 00:19:20 +01:00
Martin Holst Swende
c54d1394c6 Fixed compiler error 2015-01-22 00:10:09 +01:00
Martin Holst Swende
9e8255d4e9 Generic tracing pt.3 : reworking how iso14443b-traces are stored in ARM-memory 2015-01-21 23:53:40 +01:00
iceman1001
df3e429d71 minor fix for a help in "hf 14a snoop" 2015-01-21 21:24:37 +01:00
marshmellow42
ec75f5c10a lf Bug Fixes and lf demod additions
added data fskparadoxdemod
added data setdebugmode (for demods)
added data shiftgraphzero (to help clean weak reads)
fixed a few bugs with the data detectaskclock
added data fskfcdetect to detect FSK clocks
adjusted most of my demods to put raw tag binary to demod buffer for
future sim and clone commands (psk still needs work)
2015-01-20 17:28:51 -05:00
iceman1001
a1557c4c2f Minor fixes: Array inits, some array bounds checks.
ADD: some extra help text for lf snoop
ADD: HasGraphData - function in graph.c
ADD: DetectHighLowInGraph  - function in graph.c
2015-01-20 22:14:56 +01:00
iceman1001
e469159145 FIX: another file_path found in loadTraceCard and saveTraceCard, is now corrected to follow FILE_PATH_SIZE variable.
FIX: some filehandles that didn't get closed.
2015-01-20 21:58:53 +01:00
iceman1001
80b1b53fa3 SUGGESTED FIX:
Issue: https://github.com/Proxmark/proxmark3/issues/35
Forum:  http://www.proxmark.org/forum/viewtopic.php?pid=7883#p7883

Where "hf mf csetuid"  empties the rest of the block0 bytes.
This fix loads the old block0 and replaces the uid+sak+ataq bytes only.
2015-01-20 21:55:19 +01:00
iceman1001
fe5b3a4424 FIX: The 14b write command (CmdHF14BWrite) now turns off antenna after call. 2015-01-20 21:50:49 +01:00
iceman1001
e3c235654f Minor fixes to some help-texts. 2015-01-20 21:48:39 +01:00
iceman1001
81740aa519 STEP 3 - the actual new files for Ultralight.
ADD: script remagic.lua  --  a script to make a "dead" Mifare s50 generation 1 alive again.
ADD: tracetest.lua  - This script will load several traces files in ../traces/ folder and do
"data load"
"lf search"
ADD: test_t55x7_psk.lua   -  iterates thru a lot of calls to check the new psk demods.

all new scripts implements the  "-h"  for help text.
2015-01-20 21:29:55 +01:00
iceman1001
5ee701292f Step 2 - Ultralight / Ultralight-C
With this the Pentura Labs / Midnitsnakes's original ultralight / ultralight-c implementation is enhanced and move to its own file. cmdhfmfu.c
2015-01-20 21:23:04 +01:00
iceman1001
c8b6da2295 Merge branch 'master' of https://github.com/holiman/proxmark3
Conflicts:
	armsrc/appmain.c
	armsrc/apps.h

Step 1 for the Ultralight / Ultralight-c
2015-01-20 20:59:24 +01:00
iceman1001
5149e37e66 Merge branch 'master' of https://github.com/Proxmark/proxmark3
Conflicts:
	armsrc/appmain.c
	armsrc/apps.h
2015-01-20 09:32:53 +01:00
marshmellow42
53d85a8fa1 Merge remote-tracking branch 'upstream/master' 2015-01-18 18:19:26 -05:00
marshmellow42
1e090a61a1 lf demod additions
data fskfcdetect (field clock and bit clock detect for FSK)
data fskdemodawid -AWID demod/decode
data fskdemodpyramid - AWID demod/decode
2015-01-18 18:13:32 -05:00
Martin Holst Swende
355c8b4a7d Generic trace pt2: made iso14443b use standard trace format 2015-01-18 20:23:58 +01:00
Martin Holst Swende
80fe723570 Generic trace pt1: Moved arm-side trace functionality into util-package 2015-01-18 20:21:53 +01:00
Martin Holst Swende
b689b842b6 Bugfix 'hf list 14b' and 'hf list raw' 2015-01-16 22:48:30 +01:00
Martin Holst Swende
41fdd0f061 First stab at adding 'hf list 14b' and 'hf list raw' 2015-01-16 22:41:19 +01:00
Martin Holst Swende
55c7e3520f Merge branch 'master' of github.com:Proxmark/proxmark3 2015-01-16 15:49:11 +01:00
Martin Holst Swende
49726b4088 Improved 'hf list iclass' a bit, better understanding of the protocol and when to apply CRC checks 2015-01-15 23:00:39 +01:00
Martin Holst Swende
5c72368e2d Merge pull request #44 from marshmellow42/master
small lf demod bug fixes and threshold adjustments
2015-01-15 21:53:18 +01:00
Martin Holst Swende
f164662363 Merge branch 'master' of https://github.com/iceman1001/ForPm3
Conflicts:
	armsrc/appmain.c
	armsrc/apps.h
2015-01-15 21:50:03 +01:00
Martin Holst Swende
d60418a05f Synchronized loclass library, imported the legal warning 2015-01-15 16:30:05 +01:00
Martin Holst Swende
758f1fd1f3 Fixed issue #43 on github 2015-01-15 16:07:58 +01:00
Martin Holst Swende
6b038d192a Minor dox 2015-01-15 15:45:54 +01:00
Martin Holst Swende
1eb874ee3f Merge branch 'master' of github.com:Proxmark/proxmark3 2015-01-15 15:45:15 +01:00
Martin Holst Swende
09b69422e2 This was resynthezised along with my hf-changes. Nothing changed though 2015-01-15 15:29:03 +01:00
Martin Holst Swende
7b941c8d7f Fixed memory corruption after reader-attack in armsrc, fixed annoying LED 2015-01-15 15:27:44 +01:00
Martin Holst Swende
645c960f61 Implemented new FPGA mode for iclass tag simulation. Reduces arm-side size of transfer/memory by a factor of 8. Makes for easier arm-side encoding of messages, for when we start needing to do that on the fly instead of using precalculated messages 2015-01-15 15:16:34 +01:00
marshmellow42
dc065b4e34 slight em410xdecode adjustments
a little faster
2015-01-13 17:52:48 -05:00
marshmellow42
84871873a4 Small lf bug fixes and threshold adjustments
adjusted lf demod thresholds based on additional testing
fixed bug in hid bit length calc in cmddata.c
fixed bugs in lf search
2015-01-13 17:21:36 -05:00
iceman1001
a631936e84 ADD: Midnitesnaks's & Pentura labs Ultralight-c modifications in ARMSRC.
ADD:  des.c  ,  aes.c  in ARMSRC
2015-01-13 23:18:04 +01:00
marshmellow42
ae6ead3dc8 Merge remote-tracking branch 'upstream/master'
Conflicts:
	client/cmdlf.c
2015-01-13 16:02:23 -05:00
Martin Holst Swende
4e3d8d0f76 Merge pull request #40 from holiman/master
Iceman's changes
2015-01-13 19:40:41 +01:00
Martin Holst Swende
896473399b Actually add the FILES also, doh 2015-01-12 22:16:46 +01:00
Martin Holst Swende
55eaed8f2a Documentation to apps.h, documentation/renaming to iclass 2015-01-12 22:08:57 +01:00
Martin Holst Swende
1f6417a9b2 Removed dependency on openssl, added AES implementation from polarssl instead 2015-01-12 21:47:36 +01:00
Martin Holst Swende
68033ed776 Fixed error when no match is found for uidmapping 2015-01-11 21:49:13 +01:00
marshmellow42
ac3ba7ee69 lf search use new psk, small demod adjustments
adjust thresholds for ask, fsk, io, psk based on more sample testing
adjust indala decode to set clock to 32 if no input (autodetect not
always correct)
2015-01-09 16:46:17 -05:00
Martin Holst Swende
473124be92 removed double include 2015-01-09 21:51:34 +01:00
Martin Holst Swende
f44a01235c Merge branch 'master' of https://github.com/iceman1001/ForPm3 2015-01-09 21:50:36 +01:00
iceman1001
952a8bb59b Merge branch 'master' of https://github.com/Proxmark/proxmark3
Conflicts:
	armsrc/lfops.c
	client/cmddata.c
	client/graph.c
2015-01-08 22:23:45 +01:00
Martin Holst Swende
07c808038c Merge pull request #38 from marshmellow42/master
Add PSK, space to tabs, new trace, bug fixes to clock & demods
2015-01-08 21:53:20 +01:00
Martin Holst Swende
31d1caa526 Reverted some minor things, altered other things to get it to compile cleanly 2015-01-08 17:51:52 +01:00
iceman1001
03d7b60f2b ADD: default_toys.lua a script which identify tnp3xx tags 2015-01-08 17:36:01 +01:00
marshmellow42
c12512e99a minor code cleanup 2015-01-07 23:02:00 -05:00
marshmellow42
d6d20c5435 cmddata.c changes by others - reapply
i overwrote some changes in cmdsamples.  i fixed that
i also removed some comments in graph.c
2015-01-07 19:06:29 -05:00
marshmellow42
3179383f85 put cmdlf.c back (only changes spaces to tabs)
to make my pull request easier to weed through
i did not make any changes to cmdlf just de-spaced it - so i put it back
for now.
2015-01-07 18:45:47 -05:00
iceman1001
8e863ab641 FIX: forgot to add the function in the header file. 2015-01-08 00:20:22 +01:00
iceman1001
c3bfb9c76b ADD: a CmdEM410xWatchnSpoof in cmdlfem4x.c , looks for a tag, then replays it.
minor code clean up.
2015-01-08 00:17:40 +01:00
marshmellow42
bce5d24494 Merge branch 'master' of https://github.com/marshmellow42/proxmark3 2015-01-07 18:15:14 -05:00
marshmellow42
3aa4014baa Fix Tune Samples (broken in commit 12/31 by me) 2015-01-07 18:14:28 -05:00
marshmellow42
ba1a299ce6 code cleanup. re-added psk commands.
also fixed a bug in detect clock functions.
sync with master prep for pull request
2015-01-07 18:14:27 -05:00
marshmellow42
c07b79fcbf sync with master lf files to resolve conflicts 2015-01-07 18:13:27 -05:00
marshmellow42
4118b74dc8 added data psk* cmds for pskdemod
fixed a couple small bugs in other lf functions as well including
detectaskclock,  stopped changes from being made to graphbuffer.
2015-01-07 18:13:26 -05:00
iceman1001
787b5bd8a4 CHG: minor code clean up in ArmSrc.
ADD: added some more default keys in Hf mf nested,  maybe it runs faster :)
2015-01-08 00:08:33 +01:00
iceman1001
79bf1ad2cc ADD: Jonor's timeout patch for "Hf 14a raw".
minor code clean up
2015-01-07 23:23:17 +01:00
iceman1001
b5be31f996 FIX: The input handling for "hf 14b write" is now correct. Thanks Asper for spotting the fault.
ADD: crc32.c functionality
2015-01-07 22:56:20 +01:00
iceman1001
024b97c507 Merge branch 'master' of https://github.com/Proxmark/proxmark3
Conflicts:
	client/cmdhf.c
2015-01-07 22:55:26 +01:00
marshmellow42
809fb6aeab Fix Tune Samples (broken in commit 12/31 by me) 2015-01-07 16:34:02 -05:00
iceman1001
b915fda392 FIX: a solution for the issue "hf mf esave - always saves 4K"
FIX: a solution for the issue "hf eload, esave, cload, save - filepath variable too short"
CHG: minor code clean up.
ADD: AES / CRC16 for lua. (and tnp3xx scripts.)
ADD: tnp3dump.lua  script to dump tnp3xx tags.
ADD: tnp3sim.lua script to let PM3 imitate an tnp3xx tag. Needs to be tested live
2015-01-07 22:00:29 +01:00
iceman1001
d91a31f935 CHG: minor code clean up.
ADD: tunesamples in cmddata.c  pullrequest #33,  was removed by Marshmellows other commits. I returned it.
2015-01-07 21:29:38 +01:00
Martin Holst Swende
4df54240c1 Added some more protocol support to the list annotation. Based on http://www.proxmark.org/forum/viewtopic.php?pid=13541#p13541 2015-01-07 21:14:32 +01:00
iceman1001
52ab55ab0d ADD: added a lot of ic ids to cmdhf15.c Thanks to Asper for the list.
ADD: added a manufacturer list in "hf 14a reader",  only viable when UID is double or triple size.  Thanks to Asper for the list.
ADD: detect chinese magic backdoor commands in "hf 14a reader"
CHG: minor code clean up.
2015-01-07 21:06:15 +01:00
iceman1001
79544b28ad CHG: minor code clean up
ADD: added some  helper-functions in util.c
2015-01-07 20:52:03 +01:00
iceman1001
3af373f352 CHG: Added support for tnp3xx in lua scripts.
ADD: a save file function in lua.
2015-01-07 20:45:43 +01:00
iceman1001
23b598ee23 CHG: Minor code clean up.
ADD: crc16.c - new crc16_ccitt calc.
2015-01-07 20:40:22 +01:00
iceman1001
002c1ce57a CHG: removed leftover debugging statements proxmark3.c
CHG: hint from Marshmellow that the flag "-lcrypto" needs be also in CFLAGS.
2015-01-07 11:10:46 +01:00
iceman1001
4888b28195 Merge branch 'master' of https://github.com/Proxmark/proxmark3 2015-01-07 11:09:05 +01:00
Martin Holst Swende
cb29e00a12 Save iclass dumps to file, like mifare-dump functionality works 2015-01-07 09:57:18 +01:00
marshmellow42
a6293168da code cleanup. re-added psk commands.
also fixed a bug in detect clock functions.
sync with master prep for pull request
2015-01-06 23:29:45 -05:00
iceman1001
9484ff3d6e ADD: tnp3xxx identification in luascripts.
CHG: minor code clean up.
2015-01-06 21:20:41 +01:00
iceman1001
bf8328e928 Merge branch 'master' of https://github.com/Proxmark/proxmark3 2015-01-06 20:51:11 +01:00
marshmellow42
9269081341 Merge pull request #4 from Proxmark/master
resync fork to master
2015-01-06 14:28:59 -05:00
Martin Holst Swende
d2197f967a Changed io threshold to 140, fixed boolean error in comparison 2015-01-06 18:59:59 +01:00
Martin Holst Swende
e47e52a2c8 Fixed thresholding of io fskdemod 2015-01-06 18:43:37 +01:00
marshmellow42
389d0360e1 Merge pull request #3 from Proxmark/master
re sync with masterB
2015-01-06 11:02:11 -05:00
marshmellow42
1c4b102cd5 sync with master lf files to resolve conflicts 2015-01-06 10:58:35 -05:00
marshmellow42
5644791bdb added data psk* cmds for pskdemod
fixed a couple small bugs in other lf functions as well including
detectaskclock,  stopped changes from being made to graphbuffer.
2015-01-06 09:20:36 -05:00
iceman1001
3fe4ff4f03 CHG: generic code clean up. Removal of commented code.
CHG: USB_CMD_DATA_SIZE is now used as maxsize for transfer of data between client and pm3device
CHG: suggested a fix for the underscore problem in ioclass\fileutils.c
ADD:  tnp3xx support
ADD:  nxp tag idents.
ADD:  identifiction of chinese backdoor commands to hf 14a reader.
2015-01-05 15:51:27 +01:00
Martin Holst Swende
6f101995b6 Added loclass-functionality into the pm3,the functionality provided by loclass can now be invoked directly from the pm3. Also fixed some issues with how prnlog called PrintAndLog, and added some testdata for the loclass self-tests 2015-01-05 09:16:06 +01:00
Martin Holst Swende
39d3ce5dd6 Moved iclass crc to be based on a lookup table 2015-01-04 22:10:25 +01:00
Martin Holst Swende
337818f7ab Minor dox 2015-01-04 21:26:10 +01:00
Martin Holst Swende
4c3de57ad2 Reworked how 'hf 14a list' and 'hf iclass list' works, to use the same method. Now. use 'hf list 14a' and 'hf list iclass' instead. Plus, the output is now annotated (although the annotation-engine could use a bit more love from someone more familiar with the available commands 2015-01-04 21:22:54 +01:00
Martin Holst Swende
c8dd9b092e Some work on iclass dump and iclass list, now the dumping is a lot more stable. I think the comms should be measured and tuned a bit more, right now it kind of works thanks to retry-functionality, but the retries are probably not needed if we are a bit more careful about timing, so we don't send commands too fast for the tag to handle 2015-01-04 14:53:26 +01:00
Martin Holst Swende
2e9d4b3ff4 Some work on iclass, started on some better support in 'hf iclass list' and also fixes to 'hf iclass reader' so it exits better when the button is pressed 2015-01-03 15:11:48 +01:00
Martin Holst Swende
d0d1e24590 Set lower threshold for lf iodemod, it had too high threshold for filtering out noise. Now it works better at least with my antenna/setup 2015-01-03 14:36:38 +01:00
Martin Holst Swende
3400a4358d Fixed indentation 2015-01-03 14:29:22 +01:00
Martin Holst Swende
854b9a233f Removed unused variable 2015-01-03 14:29:07 +01:00
Martin Holst Swende
ae8e8a4372 Corrected indentation to tabs only 2015-01-03 14:21:07 +01:00
Martin Holst Swende
6ca4c6463e Removed wrong size-count, sizeof(bigbuf) would always return 40000 in lfops 2015-01-03 14:17:59 +01:00
Martin Holst Swende
45dda9fcd7 Merge pull request #34 from marshmellow42/master
Fsk demod fixes and additions to client for offline demoding
2015-01-01 13:46:48 +01:00
marshmellow42
7eefddcc58 Revert "problems creating pull request with the new traces"
This reverts commit e33b652c53.
2014-12-31 15:24:37 -05:00
marshmellow42
e33b652c53 problems creating pull request with the new traces
will add these traces later
2014-12-31 15:16:02 -05:00
marshmellow42
ac914e56db minor adjustment to askmandemod for lf search
returns false if it finds data but not an EM410x format.
2014-12-31 14:55:58 -05:00
marshmellow42
9ec1416ad2 added data rtrim command
enter location to trim all samples after
2014-12-31 14:43:49 -05:00
marshmellow42
f822a063b3 lf demod code cleanup - added fskraw arguments
merged code and added arguments to data fskrawdemod to allow other fsk
mode demodulations (FSK2a = RF/10 & RF/8) another might be (RF/8 & RF/5)
2014-12-31 02:27:30 -05:00
marshmellow42
d5a72d2fee LF demod/cmd code cleanup + new lf search
cleaned up and error proof code.  plus added new command    lf search
when online it will lf read - data samples 20000 - and test for EM410x,
HID, IO Prox, and indala cards.  when offline it will test current
graphbuffer.
2014-12-30 16:08:33 -05:00
marshmellow42
6bfa18eab4 Merge pull request #1 from Proxmark/master
Test
2014-12-29 16:14:23 -05:00
marshmellow42
2df8c07907 minor setting adjustments/cleanup
clean up code
2014-12-29 15:58:59 -05:00
marshmellow42
66707a3b3c LF Demod bug fixes and add lf em em410xdemod
fixed a few bugs in lf demod that the streamlining added.  added new lf
em em410xdemod command that loops until button pressed. (similar to lf
hid fskdemod
2014-12-29 15:32:53 -05:00
marshmellow42
7db5f1ca25 slight adjustment to include
removed extra unneeded path
2014-12-28 21:29:33 -05:00
marshmellow42
eb191de615 LF Demod streamlining
one shared location for demoding lf for arm and client.  also added a
few raw demod commands.
2014-12-28 20:33:32 -05:00
marshmellow42
9e6dd4eb69 rename askrawdemod to askmandemod 2014-12-24 13:01:09 -05:00
marshmellow42
0e74c023bd Created new detectclock function + EM decode addons
new detectclock is somewhat more reliable for ASK modulated tags.  added
this detect to askrawdemod if no clock in passed as an argument.  also
added more EM ID formats to output
2014-12-24 11:48:41 -05:00
marshmellow42
cd48c19c31 minor askrawdemod adjustment if errors in demoding are found
if it can't find a demod position with no errors it will find the one
with fewest errors and mark errors with 77.
2014-12-23 15:16:53 -05:00
marshmellow42
2fc2150ea8 Add auto check for EM410x format to askrawdemod cmd
added EM410x format check and print to the data askrawdemod command.  if
it finds valid em410x format & parities it will print the EM ID and
Unique ID and a few others.
2014-12-23 12:00:13 -05:00
pwpiwi
4be9e7507b Merge branch 'master' of https://github.com/Proxmark/proxmark3 2014-12-23 11:44:41 +01:00
pwpiwi
a088364e9c Merge branch 'master' of https://github.com/pwpiwi/proxmark3 2014-12-23 11:26:10 +01:00
pwpiwi
52bfb95543 bugfixes in iso14443a.c and hf 14a reader
- introduced with the big frame and parity support (commit 6a1f2d82): tag responses with len%8 == 0 were dropped  - thanks iceman for testing and finding
- after unsuccessful hf 14a reader the field stayed on. Thanks to iceman for proposing the fix.
2014-12-23 11:21:42 +01:00
pwpiwi
7705bf4e37 fixed a bug in iso14443a.c which had been introduced with the big frame and parity support (commit 6a1f2d82) - thanks iceman for finding and testing 2014-12-23 11:11:52 +01:00
marshmellow42
ea7d657f75 minor fix - got too comment happy removing test code
should not have commented this code out
2014-12-22 22:50:13 -05:00
marshmellow42
e888ed8e62 added new data askrawdemod command
added new data askrawdemod command returned data fskdemod and separated
out new fskrawdemod commands
2014-12-22 17:46:28 -05:00
pwpiwi
e688629475 Merge pull request #33 from pwpiwi/master
Support for bigger iso14443 frames (including parity calculation)
unify hw tune and data tune
fix hf epa cnonces
adapt hf iclass list to new trace format
2014-12-20 21:56:12 +01:00
pwpiwi
545f203826 adapted hf iclass list to new trace format 2014-12-20 21:32:44 +01:00
marshmellow42
ae2f73c12d put ask demod and mandemod
put ask demod and mandemod back until i have time to test it
2014-12-19 12:39:41 -05:00
marshmellow42
b3b706693b Final touches on IO prox and HID prox demod
makes both more robust and handles various error situations.
2014-12-19 12:14:27 -05:00
pwpiwi
db4de4d82f Merge branch 'master' of https://github.com/Proxmark/proxmark3 2014-12-18 19:42:49 +01:00
pwpiwi
57642f63fa bugfixes hf epa cnonces
- extended length (more than 1 byte) not handled correctly
- nonces not printed on Windows due to type mismatch
2014-12-18 19:40:35 +01:00
pwpiwi
f10bf20c6c Format hf 14a list output for bigger frame sizes 2014-12-18 19:39:16 +01:00
Martin Holst Swende
8e9768399c minor change 2014-12-18 14:46:38 +01:00
Martin Holst Swende
0eea34a2a3 Fixed error in hash1 (from loclass), now it possibly calculates the KSel correctly for actually dumping data 2014-12-18 14:41:17 +01:00
Martin Holst Swende
7496d8d822 Merge pull request #32 from marshmellow42/master
Fixes and additions to lf io fskdemod  and addon parameter to lf hid fskdemod
2014-12-18 08:56:26 +01:00
pwpiwi
2bdd68c370 unify/refactor hw tune and data tune
- unified hw tune and Enio's great data tune
- don't use BigBuf (and hardcoded Offset)
- removed special handling of CMD_MEASURED_ANTENNA_TUNING
  in UsbCommandReceived()
2014-12-17 20:57:26 +01:00
marshmellow42
083ca3de73 LF HID & IO prox fixes/options 2014-12-17 09:51:40 -05:00
pwpiwi
471c514167 Merge branch 'master' of https://github.com/Proxmark/proxmark3 2014-12-16 07:47:02 +01:00
pwpiwi
6a1f2d82bb bugfixes iso14443a (hf 14a commands)
- buffers were too small to handle 256 byte frames
- parity bits were only handled for up to 32 byte frames
- trace format was inefficient
- removed parity calculation from decoders in iclass.c (parity not used on air anyway)
2014-12-16 07:41:07 +01:00
Martin Holst Swende
6116c79618 Reverted to original malicious CSNs from paper, it appears legit readers does not accept if they dont end with F7,FF,12,E0 2014-12-14 21:37:56 +01:00
Martin Holst Swende
b160432340 Merge branch 'master' of github.com:Proxmark/proxmark3 2014-12-14 18:07:38 +01:00
Martin Holst Swende
eabba3df7e Fix (iclass) 2014-12-14 18:07:12 +01:00
marshmellow42
4860172789 LF HID & IO prox demod translation addons
lf hid fskdemod - add bit format length, facility code and card numbers
for different formats
2014-12-13 20:23:59 -05:00
ikarus
f4bad97d92 Merge pull request #31 from dnet/patch-1
Typofix: occurrences
2014-12-10 19:10:12 +01:00
András Veres-Szentkirályi
0ff9a93966 Typofix: occurrences
It's spelled with two rs.
2014-12-10 16:42:31 +01:00
Martin Holst Swende
d6a120a25b Added Enios cool tuning-trick (LF) from forum-post: http://www.proxmark.org/forum/viewtopic.php?pid=13060#p13060 2014-11-30 22:30:36 +01:00
Martin Holst Swende
ca4714cd23 More coverity fixes 2014-10-30 21:49:18 +01:00
Martin Holst Swende
0ce5620254 Merge pull request #23 from holiman/master
LF operations fixes, and coverity code scan fixes
2014-10-30 20:08:29 +01:00
Martin Holst Swende
4c6f2d48fb Merge pull request #2 from holiman/coverity_fixes
Coverity fixes
2014-10-28 21:46:28 +01:00
Martin Holst Swende
2ed270a854 Coverity-fixes in armsrc 2014-10-28 21:44:17 +01:00
Martin Holst Swende
97d582a692 More coverity findings 2014-10-27 22:33:37 +01:00
Martin Holst Swende
90e278d3da Fixed several issues found using a coverity-scan 2014-10-27 21:46:04 +01:00
Martin Holst Swende
77dfaa26db Merge pull request #1 from holiman/ioprox_fixes
Ioprox fixes
2014-10-27 19:13:30 +01:00
Martin Holst Swende
9cc8a1e588 Some more docs, also made lf hid fskdemod a bit more stable. Should be no more false readings now 2014-10-25 22:42:27 +02:00
Martin Holst Swende
b225678574 Some minor changes and some documentation 2014-10-24 21:12:31 +02:00
Martin Holst Swende
1a5a0d7590 Fixed compilation issues, but functionality not tested 2014-10-24 20:53:43 +02:00
Martin Holst Swende
f97d4e2378 First try att merging with head 2014-10-24 20:46:02 +02:00
Martin Holst Swende
92d255d3dc Merge pull request #22 from Proxmark/PenturaLabs-iclass-research
Pentura labs iclass research
2014-09-19 09:50:56 +02:00
Martin Holst Swende
e6ee6c4cd1 Merge remote-tracking branch 'origin/master' into PenturaLabs-iclass-research 2014-09-19 09:45:38 +02:00
pwpiwi
c626c56ef5 hf mf dump bugfix: wrongly tried key A instead of key B for a specific Access Condition 2014-09-12 07:45:04 +02:00
pwpiwi
79db03ef63 hf mf dump error handling, revive hf mf chk d option, provide known keys dictionary file
- hf mf dump: abort on unrecoverable errors. Don't create file dumpdata.bin in this case.
- hf mf chk: re-enabled and fixed option d (dump keys to dumpkeys.bin).
  if there are unknown keys, write 0xffffffffffff instead to the file.
- provide a default key dictionary file for hf mf chk (default_keys.dic). Contents taken from
  mf_default_keys.lua
2014-09-11 20:58:34 +02:00
pwpiwi
baeaf57950 fix/add support for 4K (and other non 1K) card sizes in hf mf commands
- hf mf rdsc (fix): didn't account for 16 block sectors, allowed max sector 63 instead of 39
- hf mf ecfill (add): added (optional) card size parameter and support for non 1K cards
- hf mf dump (add): added (optional) card size parameter and support for non 1K cards
- hf mf dump (fix): Access Condition 011 not handled correctly (tried to access with key A)
- hf mf restore (add): added (optional) card size parameter and support for non 1K cards
- hf mf nested (fix): didn't account for 16 block sectors, allowed max sector 63 instead of 39
- hf mf nested (fix): always dumped 16 keys to dumpkeys.bin instead of correct number
- hf mf chk (fix): always dumped 16 keys to dumpkeys.bin instead of correct number
- hf mf eget (fix): displayed three instead of one block
- hf mf eload (add): load 4K .eml files (but accepts 1K .eml files for backwards compatibility)
- hf mf esave (add): always save the whole emulator memory (4K) instead of 1K only
- hf mf ecfill (add): added (optional) card size parameter and support for non 1K cards
2014-09-10 19:04:50 +02:00
Martin Holst Swende
fdefed663f Some more lua-scripts and library fixes from iceman, including more default keys 2014-08-29 09:11:36 +02:00
Martin Holst Swende
5b1311fba2 Various scripts from iceman 2014-08-29 09:09:23 +02:00
pwpiwi
6e2f51a06e add *.eml to .gitignore 2014-08-05 18:45:37 +02:00
pwpiwi
bfb6a143ea bugfix hf mf sim
- an additional erronous byte was sent after SAK
2014-08-05 18:40:19 +02:00
pwpiwi
b03c0f2d86 bugfixes hf mf sim
- output of debug messages caused communication failures due to timing issues.
  hf mf dbg 4 now required to see these debug messages.
- changed help text for hf mf dbg
- fixed minor bugs in help texts for hf mf sim and hf mf ecset
- display "key A" or "key B" instead of "key=0" or "key=1 in hf mf sim
2014-07-30 21:23:02 +02:00
pwpiwi
991f13f27d minor bugfixes to hf mf sniff and hf 14a snoop
- tracing was not always enabled when starting hf mf sniff or hf 14a snoop
- ATQA was displayed in wrong byte order in hf mf sniff
- 4 Byte UIDs were displayed as 7 Byte UIDs (padded with 0x000000) in hf mf sniff
- same for logfile names.
- assignment (=) had been used instead of == in comparisons (shouldn't have been relevant though)
2014-07-15 08:39:56 +02:00
pwpiwi
9a573554e0 minor bugfix and enhancement to hf 14a reader
- "SAK incorrectly claims ... " message was displayed incorrectly
- now decodes FSCI, SFGI, FWI and displays FSC, SFGT, FWT resp.
2014-07-15 08:35:27 +02:00
Martin Holst Swende
9e28ee9f14 Only documentation and minor changes 2014-06-30 11:23:14 +02:00
Martin Holst Swende
9b82de75f4 more work towards iclass elite dumping.. not quite finished yet though :( 2014-06-30 00:20:40 +02:00
Martin Holst Swende
aa41c6058a Merged two iclass-reader functions into one to remove duplicated code, update loclass library with hash2 algo 2014-06-29 23:34:24 +02:00
Martin Holst Swende
d2d0af8ca6 Merge branch 'PenturaLabs-iclass-research' of github.com:Proxmark/proxmark3 into PenturaLabs-iclass-research 2014-06-29 13:52:05 +02:00
Martin Holst Swende
dbf732ee41 Minor 2014-06-29 13:48:13 +02:00
Midnitesnake
74a3880283 Changes inorder for iclass dump to work correctly 2014-06-29 09:25:31 +01:00
Martin Holst Swende
26c0d833ac Some minor changes [iclass-related] 2014-06-28 22:57:48 +02:00
Martin Holst Swende
3ad48540d4 Merge branch 'iclass-research' of https://github.com/PenturaLabs/proxmark3 into PenturaLabs-iclass-research
Conflicts:
	README.txt
	armsrc/apps.h
	client/Makefile
	client/cmdhficlass.c
	client/cmdhficlass.h
2014-06-28 20:52:37 +02:00
penturalabs
fecd8202a5 implemented 'hf iclass dump xxxx',
all you need is the magic key to dump contents of an iclass card
2014-06-17 10:55:37 +01:00
penturalabs
fe53c0311c improved calc_iclass_mac to work independant of size 2014-05-02 23:30:03 +01:00
Andrew Davies
a66fca86b9 Updated proxmark research with Holiman's loclass framework 2014-05-02 11:11:54 +01:00
penturalabs
c3963755b7 Implement replay command. 2014-04-15 11:47:01 +01:00
Martin Holst Swende
07976a256d Refactoring low frequency operations, now 'lf hid fskdemod' is more stable. Also did changes to handling ioprox tags, this is yet untested, so until it's been tested it should be kept off 'stable' branch 2014-03-31 17:57:14 +02:00
Martin Holst Swende
69d88ec463 Major refactoring of lfops, removed a lot of duplicate code 2014-03-30 15:59:54 +02:00
1005 changed files with 861624 additions and 23044 deletions

3
.gitattributes vendored
View file

@ -1,4 +1,5 @@
# .gitattributes
# prevent binary files from CRLF handling, diff and merge:
fpga/fpga.bit -crlf -diff
*.bin -crlf -diff
*.z -crlf -diff

21
.gitignore vendored
View file

@ -1,7 +1,9 @@
# .gitignore
# don't push these files to the repository
.history
*.log
*.eml
*.o
*.a
*.d
@ -9,15 +11,28 @@
*.s19
*.map
*.bin
!client/hardnested/*.bin
!client/sc_upgrade_firmware/*.bin
*.dll
*.moc.cpp
*.z
!client/hardnested/tables/*.z
usb_cmd.lua
version.c
armsrc/fpga_version_info.c
client/ui/ui_overlays.h
*.Td
.DS_Store
*.exe
proxmark
hardnested_stats.txt
proxmark3
flasher
version.c
lua
luac
fpga_compress
mfkey32
mfkey64
fpga/*
!fpga/tests
@ -30,5 +45,3 @@ fpga/*
!fpga/xst_hf.scr
!fpga/go.bat
!fpga/sim.tcl

283
CHANGELOG.md Normal file
View file

@ -0,0 +1,283 @@
# Change Log
All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
### Changed
- Changed hf mfp security. Now it works in all the modes. (drHatson)
- `hf fido` - show/check DER certificate and signatures (Merlok)
- Changed `lf hitag reader 0x ... <firstPage> <tagmode>` - to select first page to read and tagmode (0=STANDARD, 1=ADVANCED, 2=FAST_ADVANCED)
- Accept hitagS con0 tags with memory bits set to 11 and handle like 2048 tag
### Fixed
- AC-Mode decoding for HitagS
- Wrong UID at HitagS simulation
- `hf 15 sim` now works as expected (piwi)
- `hf mf chk t` save to emulator memory now works as expected (mwalker)
- Fix `hf mf sim` - wrong access rights to write key B in trailer (@McEloff)
- allow files > 512Bytes in 'hf iclass eload' (@Sherhannn79)
- `hf mf nested` now works with fixed nonce tags too (uzlonewolf, piwi)
### Added
- Added to `hf 14a apdu` print apdu and compose apdu (@merlokk)
- Added `hf 15 csetuid` - set UID on ISO-15693 Magic tags (t0m4)
- Added `lf config s xxxx` option to allow skipping x samples before capture (marshmellow)
- Added `lf em 4x05protect` to support changing protection blocks on em4x05 chips (marshmellow)
- Support Standard Communication Mode in HITAG S
- Added `hf emv scan` - commands for scan EMV card and dump data to json file (Merlok)
- `hf mfp` group of commands (Merlok)
- Added `hf fido` - FIDO U2F authenticator commands https://fidoalliance.org/ (Merlok)
- Added `lf hitag reader 03` - read block (instead of pages)
- Added `lf hitag reader 04` - read block (instead of pages)
- Added `hf fido` `assert` and `make` commands from fido2 protocol (authenticatorMakeCredential and authenticatorGetAssertion) (Merlok)
- Added `lf paradox clone` to clone a Paradox card
- Added `emv` commands working for both contactless and smart cards (Merlok)
- Added `hf 15 snoop` (piwi)
- Added support for standard USB Smartcard Readers (piwi)
- Added `hf plot` (piwi)
- Added `hf mfp mad` `hf mf mad` parsing MAD1 and MAD2 (Merlok)
- Added `hf mfp ndef` `hf mf ndef` parsing NDEF records (Merlok)
- Added Mifare Mini, Mifare 2K and 4K support to `hf mf sim` (piwi)
- Added Legic detection to `hf search` (dnet)
- Added Home (Pos1) and End key bindings to the plot GUI (based on @mcd1992)
- Added downlink reference mode option r <mode> [ 0 - (or missing) default/fixed bit, 1 - long leading, 2 - leading 0 and 3 - 1 of 4 ] to `lf t55xx detect`, `lf t55xx read`, `lf t55xx write`, and `lf t55xx bruteforce`
- Added special option `r 4` to bruteforce, to try all downlink modes (0,1,2 and 3) for each password
- `hf mfu info` now checks the NXP Originality Signature if availabe (piwi)
- Added `hf mf personalize` to personalize the UID option of Mifare Classic EV1 cards (piwi)
## [v3.1.0][2018-10-10]
### Changed
- Adjusted `lf cmdread` to respond to client when complete and the client will then automatically call `data samples`
- Improved backdoor detection misbehaving magic s50/1k tag (Fl0-0)
- Deleted wipe functionality from `hf mf csetuid` (Merlok)
- Changed `hf mf nested` logic (Merlok)
- Added `hf mf nested` mode: autosearch keys for attack (from well known keys) (Merlok)
- `hf mf nested` Check keys after they have found (Merlok)
- `hf mf chk` Move main cycle to arm (Merlok)
- Changed proxmark command line parameter `flush` to `-f` or `-flush` (Merlok)
- Changed `hf 14a reader` to just request-anticolission-select sequence (Merlok)
- Changed `hf 14a raw` - works with LED's and some exchange logic (Merlok)
- Changed TLV parser messages to more convenient (Merlok)
- Rewritten Legic Prime reader (`hf legic reader`, `write` and `fill`) - it is using xcorrelation now (AntiCat)
- `hf 14a` commands works via argtable3 commandline parsing library (Merlok)
- HID LF operations on firmware updated for complete native support of long (>37 bit) HID tags (grauerfuchs)
- Changed Legic Prime tag simulator (`hf legic sim`) to run from 212 kHz SSP clock for better reliability (AntiCat)
### Fixed
- Changed start sequence in Qt mode (fix: short commands hangs main Qt thread) (Merlok)
- Changed driver file proxmark3.inf to support both old and new Product/Vendor IDs (piwi)
- Changed all command line parsers in `hf emv` commands to argtable (Merlok)
- Implemented AppNap API, fixing #283 and #627 OSX USB comm issues (AntiCat)
### Added
- Added `sc` smartcard (contact card) commands - reader, info, raw, upgrade, setclock, list (hardware version RDV4.0 only) must turn option on in makefile options (Willok, Iceman, marshmellow)
- Added a bitbang mode to `lf cmdread` if delay is 0 the cmd bits turn off and on the antenna with 0 and 1 respectively (marshmellow)
- Added PAC/Stanley detection to lf search (marshmellow)
- Added lf pac demod and lf pac read - extracts the raw blocks from a PAC/Stanley tag (marshmellow)
- Added hf mf c* commands compatibility for 4k and gen1b backdoor (Fl0-0)
- Added backdoor detection for gen1b magic s70/4k tag (Fl0-0)
- Added data fsktonrz, a fsk cleaning/demodulating routine for weak fsk signal. Note: follow this up with a `data rawdemod nr` to finish demoding your signal. (marshmellow)
- Added lf em 410xbrute, LF EM410x reader bruteforce attack by simulating UIDs from a file (Fl0-0)
- Added `hf mf cwipe` command. It wipes "magic Chinese" card. For 1a generation it uses card's "wipe" command. For gen1a and gen1b it uses a write command. (Merlok)
- Added to `hf mf nested` source key check before attack (Merlok)
- Added to `hf mf nested` after attack it checks all found keys on non-open sectors (Merlok)
- `hf mf chk` Added settings to set iso14443a operations timeout. default timeout set to 500us (Merlok)
- Added to `hf mf nested` parameters `s` and `ss` for checking slow cards (Merlok)
- Added to proxmark command line parameters `w` - wait 20s for serial port (Merlok)
- Added to proxmark command line parameters `c` and `l` - execute command and lua script from command line (Merlok)
- Added to proxmark ability to execute commands from stdin (pipe) (Merlok)
- Added `hf 14a info` and moved there functionality from `hf 14a reader` (Merlok)
- Added to `hf 14a info` detection of weak prng from Iceman1001 fork (Merlok)
- Added to `hf 14a apdu` - exchange apdu via iso1443-4 (Merlok)
- Added to `hf 14a apdu` - apdu and tlv results parser (Merlok)
- Added `hf emv` group of commands (Merlok)
- Added `hf emv search` `hf emv pse` - commands for selection of EMV application (Merlok)
- Added `hf emv select` - command for select EMV application (Merlok)
- Added `hf emv exec` - command for execute EMV transaction (Merlok)
- Added to `hf emv exec` MSD path for VISA and Mastercard and some other compatible EMV cards (Merlok)
- Added to `hf emv exec` SDA, DDA, fast DDA, CDA calculations for VISA and Mastercard and some other compatible EMV cards (Merlok)
- Added `hf emv test` - crypto tests for DES, AES, SHA, RSA, SDA, DDA, CDA and some other crypto functions (Merlok)
- Added `hf list mf` - deciphers crypto1 stream and works with first authentication and weak nested authentications (Merlok)
- Added to `hf emv` commands: `gpo`, `readrec`, `genac`, `challenge`, `intauth` - commands working with EMV cards (Merlok)
- Added `lf hid encode` and `lf hid decode` commands to translate printed HID card data to and from the packed data transmitted by a prox tag (grauerfuchs)
- Added `lf hid write` command, which operates as a macro for encode followed by clone operations (grauerfuchs)
## [3.0.1][2017-06-08]
### Fixed
- Compiles on OS X
- Compiles with gcc 4.9
- Compiles for non-Intel CPUs
## [3.0.0][2017-06-05]
### Added
- Added lf hitag write 24, the command writes a block to hitag2 tags in crypto mode (henjo)
### Added
- Added hf mf hardnested, an attack working for hardened Mifare cards (EV1, Mifare Plus SL1) where hf mf nested fails (piwi)
- Added experimental testmode write option for t55xx (danger) (marshmellow)
- Added t55xx p1detect to `lf search` chip detections (marshmellow)
- Added lf t55xx p1detect, detect page 1 of a t55xx tag based on E015 mfg code (marshmellow)
- Added lf noralsy demod, read, clone, sim commands (iceman)
- Added lf jablotron demod, read, clone, sim commands (iceman)
- Added lf nexwatch read - reads a nexwatch tag from the antenna
- Added lf paradox read - reads a paradox tag from the antenna
- Added lf fdx sim (iceman)
- Added lf fdx clone - clones an fdx-b animal tag to t55x7 or q5 (iceman)
- Added lf fdx read - reads a fdx-b tag from the antenna (iceman)
- Added lf gproxii read - reads a gproxii tag from the antenna (marshmellow)
- Added lf indala read - reads an indala tag from the antenna (marshmellow)
- Added lf visa2000 demod, read, clone, sim commands (iceman)
- Added markers in the graph around found Sequence Terminator after askmandemod.
- Added data mtrim <start> <stop> command to trim out samples between start and stop
- Added data setgraphmarkers <orange> <blue> command to set two extra markers on the graph (marshmellow)
- Added EM4x05/EM4x69 chip detection to lf search (marshmellow)
- Added lf em 4x05dump command to read and output all the blocks of the chip (marshmellow)
- Added lf em 4x05info command to read and display information about the chip (marshmellow)
- Added lf cotag read, and added it to lf search (iceman)
- Added hitag2 read UID only and added that to lf search (marshmellow)
- Added lf pyramid commands (iceman)
- Added lf presco commands - some bits not fully understood... (iceman)
- Added experimental HitagS support (Oguzhan Cicek, Hendrik Schwartke, Ralf Spenneberg)
see https://media.ccc.de/v/32c3-7166-sicherheit_von_125khz_transpondern_am_beispiel_hitag_s
English video available
- Added a LF ASK Sequence Terminator detection option to the standard ask demod - and applied it to `lf search u`, `lf t55xx detect`, and `data rawdemod am s` (marshmellow)
- `lf t55xx bruteforce <start password> <end password> [i <*.dic>]` - Simple bruteforce attack to find password - (iceman and others)
- `lf viking clone`- clone viking tag to t55x7 or Q5 from 4byte hex ID input
- `lf viking sim` - sim full viking tag from 4byte hex ID input
- `lf viking read` - read viking tag and output ID
- `lf t55xx wipe` - sets t55xx back to factory defaults
- Added viking demod to `lf search` (marshmellow)
- `lf viking demod` demod viking id tag from graphbuffer (marshmellow)
- `lf t55xx resetread` added reset then read command - should allow determining start of stream transmissions (marshmellow)
- `lf t55xx wakeup` added wake with password (AOR) to allow lf search or standard lf read after (iceman, marshmellow)
- `hf iclass managekeys` to save, load and manage iclass keys. (adjusted most commands to accept a loaded key in memory) (marshmellow)
- `hf iclass readblk` to select, authenticate, and read 1 block from an iclass card (marshmellow)
- `hf iclass writeblk` to select, authenticate, and write 1 block to an iclass card (or picopass) (marshmellow + others)
- `hf iclass clone` to take a saved dump file and clone selected blocks to a new tag (marshmellow + others)
- `hf iclass calcnewkey` - to calculate the div_key change to change a key - (experimental) (marshmellow + others)
- `hf iclass encryptblk` - to encrypt a data block hex to prep for writing that block (marshmellow)
- ISO14443a stand-alone operation with ARM CFLAG="WITH_ISO14443a_StandAlone". This code can read & emulate two banks of 14a tag UIDs and write to "magic" cards (Craig Young)
- AWID26 command context added as 'lf awid' containing realtime demodulation as well as cloning/simulation based on tag numbers (Craig Young)
- Added 'hw status'. This command makes the ARM print out some runtime information. (holiman)
- Added 'hw ping'. This command just sends a usb packets and checks if the pm3 is responsive. Can be used to abort certain operations which supports abort over usb. (holiman)
- Added `data hex2bin` and `data bin2hex` for command line conversion between binary and hexadecimal (holiman)
- Added 'hf snoop'. This command take digitalized signal from FPGA and put in BigBuffer. (pwpiwi + enio)
- Added Topaz (NFC type 1) protocol support ('hf topaz reader', 'hf list topaz', 'hf 14a raw -T', 'hf topaz snoop'). (piwi)
- Added option c to 'hf list' (mark CRC bytes) (piwi)
### Changed
- Adjusted the lf demods to auto align and set the grid for the graph plot.
- `lf snoop` now automatically gets samples from the device
- `lf read` now accepts [#samples] as arg. && now automatically gets samples from the device
- adjusted lf t5 chip timings to use WaitUS. and adjusted the readblock timings
appears to have more consistent results with more antennas.
- `lf t5 wakeup` has been adjusted to not need the p in front of the pwd arg.
- `data psknexwatchdemod` has been moved to `lf nexwatch demod` (reads from graphbuffer)
- `data fskparadoxdemod` has been moved to `lf paradox demod` (reads from graphbuffer)
- `data fdxdemod` has been moved to `lf fdx demod` (reads from graphbuffer)
- `data askgproxiidemod has been moved to `lf gproxii demod` (reads from graphbuffer)
- `lf indalaclone` has been moved to `lf indala clone`
- `lf indalademod` has been moved to `lf indala altdemod` (reads from graphbuffer)
- `data pskindalademod` has been moved to `lf indala demod` (reads from graphbuffer)
- `data askvikingdemod` has been moved to `lf viking demod` (reads from graphbuffer)
- `data fskpyramiddemod` has been moved to `lf pyramid demod` (reads from graphbuffer)
- `data fskiodemod` has been moved to `lf io demod` (reads from graphbuffer)
- `lf io fskdemod` has been renamed to `lf io read` (reads from antenna)
- `data fskawiddemod` has been moved to `lf awid demod` (reads from graphbuffer)
- `lf awid fskdemod` has been renamed to `lf awid read` (reads from antenna)
- `data fskhiddemod` has been moved to `lf hid demod` (reads from graphbuffer)
- `lf hid demod` has been renamed to `lf hid read` (reads from antenna)
- all em410x demod and print functions moved to cmdlfem4x.c
- `data askem410xdemod` has been moved to `lf em 410xdemod` (reads from graphbuffer)
- `lf em 410xdemod` has been renamed to `lf em 410xread` (reads from antenna)
- hf mf dump - added retry loops to try each read attempt up to 3 times. makes getting a complete dump easier with many antennas.
- small changes to lf psk and fsk demods to improve results when the trace begins with noise or the chip isn't broadcasting yet (marshmellow)
- NOTE CHANGED ALL `lf em4x em*` cmds to simpler `lf em ` - example: `lf em4x em410xdemod` is now `lf em 410xdemod`
- Renamed and rebuilt `lf em readword` && readwordpwd to `lf em 4x05readword` - it now demods and outputs the read block (marshmellow/iceman)
- Renamed and rebuilt `lf em writeword` && writewordpwd to `lf em 4x05writeword` - it now also reads validation output from the tag (marshmellow/iceman)
- Fixed bug in lf sim and continuous demods not turning off antenna when finished
- Fixed bug(s) in hf iclass write
- Fixed bug in lf biphase sim - `lf simask b` (and any tagtype that relies on it - gproxii...) (marshmellow)
- Fixed bug in lf viking clone/sim (iceman)
- Fixed broken `data askedgedetect` (marshmellow)
- Adjusted hf mf sim command (marshmellow)
added auto run mfkey32 to extract all keys
also added f parameter to allow attacking with UIDs from a file (implies x and i parameters)
also added e parameter to allow adding the extracted keys to emulator memory for the next simulation
added 10 byte uid option
- Added `[l] <length>` option to data printdemodbuffer (marshmellow)
- Adjusted lf awid clone to optionally clone to Q5 tags (marshmellow)
- Adjusted lf t55xx detect to find Q5 tags (t5555) instead of just t55x7 (marshmellow)
- Adjusted all lf NRZ demods - works more accurately and consistently (as long as you have strong signal) (marshmellow)
- Adjusted lf pskindalademod to reduce false positive reads. (marshmellow)
- Small adjustments to psk, nrz, and ask clock detect routines - more reliable. (marshmellow)
- Adjusted lf em410x em410xsim to accept a clock argument (marshmellow)
- Adjusted lf t55xx dump to allow overriding the safety check and warning text (marshmellow)
- Adjusted lf t55xx write input variables (marshmellow)
- Adjusted lf t55xx read with password safety check and warning text and adjusted the input variables (marshmellow & iceman)
- Adjusted LF FSK demod to account for cross threshold fluctuations (898 count waves will adjust the 9 to 8 now...) more accurate. (marshmellow)
- Adjusted timings for t55xx commands. more reliable now. (marshmellow & iceman)
- `lf cmdread` adjusted input methods and added help text (marshmellow & iceman)
- changed `lf config t <threshold>` to be 0 - 128 and will trigger on + or - threshold value (marshmellow)
- `hf iclass dump` cli options - can now dump AA1 and AA2 with different keys in one run (does not go to multiple pages for the larger tags yet) (marshmellow)
- Revised workflow for StandAloneMode14a (Craig Young)
- EPA functions (`hf epa`) now support both ISO 14443-A and 14443-B cards (frederikmoellers)
- 'hw version' only talks to ARM at startup, after that the info is cached. (pwpiwi)
- Added `r` option to iclass functions - allows key to be provided in raw block 3/4 format
## [2.2.0][2015-07-12]
### Changed
- Added `hf 14b raw -s` option to auto select a 14b std tag before raw command
- Changed `hf 14b write` to `hf 14b sriwrite` as it only applied to sri tags (marshmellow)
- Added `hf 14b info` to `hf search` (marshmellow)
- Added compression of fpga config and data, *BOOTROM REFLASH REQUIRED* (piwi)
- Implemented better detection of mifare-tags that are not vulnerable to classic attacks (`hf mf mifare`, `hf mf nested`) (piwi)
### Added
- Add `hf 14b info` to find and print info about std 14b tags and sri tags (using 14b raw commands in the client) (marshmellow)
- Add PACE replay functionality (frederikmoellers)
### Fixed
- t55xx write timing (marshmellow)
## [2.1.0][2015-06-23]
### Changed
- Added ultralight/ntag tag type detection to `hf 14a read` (marshmellow)
- Improved ultralight dump command to auto detect tag type, take authentication, and dump full memory (or subset specified) of known tag types (iceman1001 / marshmellow)
- Combined ultralight read/write commands and added authentication (iceman1001)
- Improved LF manchester and biphase demodulation and ask clock detection especially for reads with heavy clipping. (marshmellow)
- Iclass read, `hf iclass read` now also reads tag config and prints configuration. (holiman)
- *bootrom* needs to be flashed, due to new address boundaries between os and fpga, after a size optimization (piwi)
### Fixed
- Fixed EM4x50 read/demod of the tags broadcasted memory blocks. 'lf em4x em4x50read' (not page read) (marshmellow)
- Fixed issue #19, problems with LF T55xx commands (iceman1001, marshmellow)
- Fixed various problems with iso14443b, issue #103 (piwi, marshmellow)
### Added
- Added `hf search` - currently tests for 14443a tags, iclass tags, and 15693 tags (marshmellow)
- Added `hf mfu info` Ultralight/NTAG info command - reads tag configuration and info, allows authentication if needed (iceman1001, marshmellow)
- Added Mifare Ultralight C and Ultralight EV1/NTAG authentication. (iceman1001)
- Added changelog
## [2.0.0] - 2015-03-25
### Changed
- LF sim operations now abort when new commands arrive over the USB - not required to push the device button anymore.
### Fixed
- Mifare simulation, `hf mf sim` (was broken a long time) (pwpiwi)
- Major improvements in LF area and data operations. (marshmellow, iceman1001)
- Issues regarding LF simulation (pwpiwi)
### Added
- iClass functionality: full simulation of iclass tags, so tags can be simulated with data (not only CSN). Not yet support for write/update, but readers don't seem to enforce update. (holiman).
- iClass decryption. Proxmark can now decrypt data on an iclass tag, but requires you to have the HID decryption key locally on your computer, as this is not bundled with the sourcecode.

60
CI/.travis.yml Normal file
View file

@ -0,0 +1,60 @@
# Travis-CI config
# variable REPOSITORY_EP must be filled with repository name. as sample: "merlokk/proxmark3"
language: c
compiler: gcc
# Test on Linux and MacOS
jobs:
include:
- os: osx
osx_image: xcode9.4 # OS X 10.13
- os: osx
osx_image: xcode10 # OS X 10.13
- os: osx
osx_image: xcode11 # OS X 10.14
- os: linux
dist: trusty # Ubuntu 14.04
- os: linux
dist: xenial # Ubuntu 16.04
- os: linux
dist: bionic # Ubuntu 18.04
git:
depth: false
before_install:
## Install ARM toolchain on Linux.
## add our homebrew tap for MacOS
## Note: all dependencies on MacOS should be resolved by the brew install command
echo $REPOSITORY_EP;
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
sudo apt-get update -qq;
sudo apt-get install -y gcc-arm-none-eabi libnewlib-arm-none-eabi libpcsclite-dev;
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update;
if [[ "$REPOSITORY_EP" == "" ]]; then
brew tap --full proxmark/proxmark3;
else
brew tap --full "$REPOSITORY_EP" --env=std;
fi
fi
install:
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew info proxmark3;
brew install -v --HEAD proxmark3;
elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
make all;
fi
before_script:
script:
## for the time being we are satisfied if it can be build and hf mf hardnested runs
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
proxmark3 /dev/notexists travis_test_commands.scr ;
elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
./client/proxmark3 /dev/notexists travis_test_commands.scr ;
fi

321
CI/appveyor.yml Normal file
View file

@ -0,0 +1,321 @@
version: 3.0.1.{build}
image: Visual Studio 2017
clone_folder: C:\ProxSpace\pm3
init:
- ps: >-
$psversiontable
#Get-ChildItem Env:
$releasename=""
$env:APPVEYOR_REPO_COMMIT_SHORT = $env:APPVEYOR_REPO_COMMIT.Substring(0, 8)
if ($env:appveyor_repo_tag -match "true"){
$releasename=$env:APPVEYOR_REPO_TAG_NAME + "/"
}
$releasename+=$env:APPVEYOR_BUILD_VERSION + " [" + $env:APPVEYOR_REPO_COMMIT_SHORT + "]"
Write-Host "repository: $env:appveyor_repo_name branch:$env:APPVEYOR_REPO_BRANCH release: $releasename" -ForegroundColor Yellow
Add-AppveyorMessage -Message "[$env:APPVEYOR_REPO_COMMIT_SHORT]$env:appveyor_repo_name($env:APPVEYOR_REPO_BRANCH)" -Category Information -Details "repository: $env:appveyor_repo_name branch: $env:APPVEYOR_REPO_BRANCH release: $releasename"
iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
clone_script:
- ps: >-
Write-Host "Removing ProxSpace..." -NoNewLine
cd \
Remove-Item -Recurse -Force -Path c:\ProxSpace\*
Write-Host "[ OK ]" -ForegroundColor Green
Write-Host "Git clone ProxSpace..." -NoNewLine
git clone -q https://github.com/Gator96100/ProxSpace c:\ProxSpace
Write-Host "[ OK ]" -ForegroundColor Green
Write-Host "Removing pm3 dir..." -NoNewLine
Remove-Item -Recurse -Force -Path c:\ProxSpace\pm3\*
Write-Host "[ OK ]" -ForegroundColor Green
Write-Host "Cloning repository <$env:appveyor_repo_name> to $env:appveyor_build_folder ..." -NoNewLine
if(-not $env:appveyor_pull_request_number) {
git clone -q --branch=$env:appveyor_repo_branch https://github.com/$env:appveyor_repo_name.git $env:appveyor_build_folder
cd $env:appveyor_build_folder
git checkout -qf $env:appveyor_repo_commit
} else {
git clone -q https://github.com/$env:appveyor_repo_name.git $env:appveyor_build_folder
cd $env:appveyor_build_folder
git fetch -q origin +refs/pull/$env:appveyor_pull_request_number/merge:
git checkout -qf FETCH_HEAD
}
Write-Host "[ OK ]" -ForegroundColor Green
Write-Host "Fill msys2\etc\fstab file..." -NoNewLine
New-Item c:\ProxSpace\msys2\etc\fstab -type file -force -value "# For a description of the file format, see the Users Guide`n# http://cygwin.com/cygwin-ug-net/using.html#mount-table`nnone / cygdrive binary,posix=0,noacl,user 0 0 `nC:\ProxSpace\pm3 /pm3 ntfs noacl 0 0 `nC:\ProxSpace\gcc-arm-none-eabi /gcc-arm-none-eabi ntfs noacl 0 0 `n"
Write-Host "[ OK ]" -ForegroundColor Green
Write-Host "Update msys2 packages..." -NoNewLine
$env:Path = "C:\ProxSpace\msys2\usr\bin;C:\ProxSpace\msys2\mingw32\bin;C:\ProxSpace\gcc-arm-none-eabi\bin;$env:Path"
C:\ProxSpace\msys2\msys2_shell.cmd -mingw32 -defterm -no-start /dev/null 1> msys1.txt 2>&1
C:\ProxSpace\msys2\msys2_shell.cmd -mingw32 -defterm -no-start /dev/null 1> msys1.txt 2>&1
Write-Host "[ OK ]" -ForegroundColor Green
install:
- ps: >-
function Exec-External {
param(
[Parameter(Position=0,Mandatory=1)][scriptblock] $command
)
& $command
if ($LASTEXITCODE -ne 0) {
throw ("Command returned non-zero error-code ${LASTEXITCODE}: $command")
}
}
build_script:
- ps: >-
"C:\ProxSpace\msys2\usr\bin;C:\ProxSpace\msys2\mingw32\bin;C:\ProxSpace\gcc-arm-none-eabi\bin;$env:Path"
$env:MINGW_HOME="C:\ProxSpace\msys2\mingw32"
$env:MSYS_HOME="C:\ProxSpace\msys2"
$env:MSYSTEM="MINGW32"
$env:MINGW_PREFIX="/mingw32"
$env:SHELL="/bin/bash"
$env:MSYSTEM_CHOST="i686-w64-mingw32"
#make
bash -c -i 'pwd;make clean;make all'
#some checks
if(!(Test-Path C:\ProxSpace\pm3\client\proxmark3.exe)){
throw "Main file proxmark3.exe not exists."
}
if(!(Test-Path C:\ProxSpace\pm3\armsrc\obj\fullimage.elf)){
throw "ARM file fullimage.elf not exists."
}
if(!(Test-Path C:\ProxSpace\pm3\client\hardnested\tables\*.bin.z)){
throw "Files in hardnested\tables not exists."
}
#copy
Write-Host "Copy release files..." -NoNewLine -ForegroundColor Yellow
New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release
Copy-Item C:\ProxSpace\pm3\client\*.exe C:\ProxSpace\Release
New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\arm
Copy-Item C:\ProxSpace\pm3\armsrc\obj\*.elf C:\ProxSpace\Release\arm
Copy-Item C:\ProxSpace\pm3\bootrom\obj\*.elf C:\ProxSpace\Release\arm
New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\scripts
Copy-Item C:\ProxSpace\pm3\client\scripts\*.lua C:\ProxSpace\Release\scripts
New-Item -ItemType Directory -Force -Path C:\ProxSpace\Release\hardnested\tables
Copy-Item C:\ProxSpace\pm3\client\hardnested\*.bin C:\ProxSpace\Release\hardnested
Copy-Item C:\ProxSpace\pm3\client\hardnested\tables\*.bin.z C:\ProxSpace\Release\hardnested\tables
Write-Host "[ OK ]" -ForegroundColor Green
#archive and push
$releasename=""
if ($env:appveyor_repo_tag -match "true"){
$releasename=$env:APPVEYOR_REPO_TAG_NAME + "/"
}
$releasename+=$env:APPVEYOR_BUILD_VERSION + " [" + $env:APPVEYOR_REPO_COMMIT.Substring(0, 7) + "]"
Write-Host "Archive and publish release files ($releasename)..." -NoNewLine -ForegroundColor Yellow
cd C:\ProxSpace
7z a release.zip C:\ProxSpace\Release
Push-AppveyorArtifact release.zip -DeploymentName "$releasename"
Write-Host "[ OK ]" -ForegroundColor Green
Write-Host "Builded..." -ForegroundColor Yellow
test_script:
- ps: >-
$env:Path = "C:\ProxSpace\msys\bin;$env:Path"
cd c:\ProxSpace\pm3
$global:TestsPassed=$true
Function ExecTest($Name, $File, $Cmd, $CheckResult) {
#--- begin Job
$Job = Start-Job -ScriptBlock {
[bool]$res=$false
$TestTime=[System.Environment]::TickCount
$env:Path = "C:\ProxSpace\msys\bin;$env:Path"
Set-Location $using:PWD
$sb=[scriptblock]::Create("$using:Cmd")
#execute scriptblock
Write-host "Test [$using:Name] job: $using:Cmd"
$Cond=&$sb
if ($Cond -eq $null){
} ElseIf($using:CheckResult -ne $null) {
[String]$searchstr=""
if ($Cond -is [Object]){
ForEach($line in $Cond){
Write-host $line -ForegroundColor Gray
$searchstr += $line
}
}else{
Write-host "$Cond" -ForegroundColor Gray
$searchstr = $Cond
}
If($searchstr -like "*$using:CheckResult*") {
$res=$true
}
$Cond="*$using:CheckResult*"
} Else {
If (!($Cond -is [bool] -or $Cond -is [byte] -or $Cond -is [int16] -or $Cond -is [int32] -or $Cond -is [int64] -or $Cond -is [float])){
if ($Cond -is "String" -and $Cond -like "*passed*"){
$res= $true
}
if ($Cond -is "String" -and $Cond -like "*true*"){
$res= $true
}
} Else {
$res=$Cond
}
}
If ($res) {
Write-host "Result[$using:Name]: $Cond" -ForegroundColor Green
Add-AppveyorTest -Name "$using:Name" -Framework NUnit -Filename "$using:File" -Outcome Passed -Duration "$([System.Environment]::TickCount-$TestTime)"
}Else {
Write-host "Result[$using:Name]: $Cond" -ForegroundColor Red
Add-AppveyorTest -Name "$using:Name" -Framework NUnit -Filename "$using:File" -Outcome Failed -Duration "$([System.Environment]::TickCount-$TestTime)" -ErrorMessage "command:$using:Cmd`nresult:$Cond"
}
return $res
}
#--- end Job
[bool]$res=$false
# Wait 120 sec timeout for Job
if(Wait-Job $Job -Timeout 150){
$Results = $Job | Receive-Job
if($Results -like "true"){
$res=$true
}
} else {
Write-host "Test [$Name] timeout" -ForegroundColor Red
Add-AppveyorTest -Name "$Name" -Framework NUnit -Filename "$File" -Outcome Failed -Duration 60000 -ErrorMessage "timeout"
}
Remove-Job -Force $Job
if(!$res){
$global:TestsPassed=$false
}
}
Write-Host "Running tests..." -ForegroundColor Yellow
#file test
ExecTest "proxmark3 exists" "proxmark3.exe" {Test-Path C:\ProxSpace\Release\proxmark3.exe}
ExecTest "arm image exists" "\arm\fullimage1.elf" {Test-Path C:\ProxSpace\Release\arm\fullimage.elf}
ExecTest "bootrom exists" "bootrom.elf" {Test-Path C:\ProxSpace\Release\arm\bootrom.elf}
ExecTest "hardnested tables exists" "hardnested" {Test-Path C:\ProxSpace\Release\hardnested\tables\*.z}
ExecTest "release exists" "release.zip" {Test-Path C:\ProxSpace\release.zip}
#proxmark logic tests
ExecTest "proxmark help" "proxmark3 -h" {bash -lc 'cd ~/client;./proxmark3 -h | grep -q Execute && echo Passed || echo Failed'}
ExecTest "proxmark help hardnested" "proxmark3 -h" {bash -lc 'cd ~/client;./proxmark3 -h | grep -q hardnested && echo Passed || echo Failed'}
ExecTest "hf mf offline text" "hf mf" {bash -lc "cd ~/client;./proxmark3 comx -c 'hf mf'"} "at_enc"
ExecTest "hf mf hardnested" "hf mf hardnested" {bash -lc "cd ~/client;./proxmark3 comx -c 'hf mf hardnested t 1 000000000000'"} "found:"
#proxmark crypto tests
ExecTest "hf emv test" "hf emv test" {bash -lc "cd ~/client;./proxmark3 comx -c 'hf emv test'"} "Tests ?OK"
if ($global:TestsPassed) {
Write-Host "Tests [ OK ]" -ForegroundColor Green
} else {
Write-Host "Tests [ ERROR ]" -ForegroundColor Red
throw "Tests error."
}
on_success:
- ps: Write-Host "Build success..." -ForegroundColor Green
on_failure:
- ps: Write-Host "Build error." -ForegroundColor Red
on_finish:
- ps: $blockRdp = $false; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

20
CI/readme.md Normal file
View file

@ -0,0 +1,20 @@
# How to configure continuous integration
Here 2 CI configuration files:
1. for [travis](travis-ci.org)
2. for [appveyor](appveyor.com)
It needs to put files from this directory to repository root and then configure CI from appropriate WEB portal.
## travis
- Copy .travis.yml and travis_test_commands.scr files to repository root
- Configure CI from http://travis-ci.org
- It needs to fork https://github.com/Proxmark/homebrew-proxmark3 from your proxmark repository home
- Put to file `proxmark3.rb` in line `head "https://github.com/proxmark/proxmark3.git"` your repository link. As sample: `head "https://github.com/merlokk/proxmark3.git"`
## appveyor
- Just copy appveyor.yml file to root and configure it from http://appveyor.com

View file

@ -0,0 +1,3 @@
hf mf hardnested t 1 000000000000
emv test
exit

View file

@ -3,7 +3,7 @@ The project compiles on Linux, Mac OS X and Windows (MinGW/MSYS).
it requires:
- gcc >= 4.4
- libpthread
- libreadline
- GNU libreadline or BSD libedit (editline)
- libusb
- perl
- an ARM cross-compiler to compile the firmware
@ -81,7 +81,55 @@ Download the ProxSpace environment archive and extract it to C:\
= Mac OS X =
============
macport stuff should do ;)
Installing from HomeBrew tap
---------------------------
This method is recommended and tested on macOS Sierra 10.12.3
1. Install homebrew if you haven't yet already done so: http://brew.sh/
2. Tap proxmark repo:
brew tap proxmark/proxmark3
3. Install Proxmark3:
Stable release
brew install proxmark3
Latest non-stable from GitHub (use this if previous command fails)
brew install --HEAD proxmark3
For more information go to https://github.com/Proxmark/homebrew-proxmark3
Compilling from source manually (Legacy)
---------------------------
Tested on OSX 10.10 Yosemite
1 - Install Xcode and Xcode Command Line Tools
2 - Install Homebrew and dependencies
brew install libusb p7zip libusb-compat wget qt5 pkgconfig
3 - Install DevKitARM for OSX
Option 1:
http://sourceforge.net/projects/devkitpro/files/devkitARM/devkitARM_r44/
Unpack devkitARM_r44-osx.tar.bz2 to proxmark3 directory.
Option 2:
brew tap nitsky/stm32
brew install arm-none-eabi-gcc
4 - Edit proxmark3/client/Makefile adding path qt5
LDLIBS = -L/usr/local/opt/qt5/lib -L/opt/local/lib -L/usr/local/lib ../liblua/liblua.a -lreadline -lpthread -lm
CFLAGS = -std=c99 -I/usr/local/opt/qt5/include -I. -I../include -I../common -I../zlib -I/opt/local/include -I../liblua -Wall $(COMMON_FLAGS) -g -O4
5 - Set Environment
export DEVKITPRO=$HOME/proxmark3/
export DEVKITARM=$DEVKITPRO/devkitARM
export PATH=${PATH}:${DEVKITARM}/bin
============
= Linux =

View file

@ -1,49 +1,65 @@
include common/Makefile.common
GZIP=gzip
# Windows' echo echos its input verbatim, on Posix there is some
# amount of shell command line parsing going on. echo "" on
# Windows yields literal "", on Linux yields an empty line
ifeq ($(shell echo ""),)
# This is probably a proper system, so we can use uname
DELETE=rm -rf
FLASH_TOOL=client/flasher
platform=$(shell uname)
ifneq (,$(findstring MINGW,$(platform)))
FLASH_PORT=com3
PATHSEP=\\#
else
FLASH_PORT=/dev/ttyACM0
PATHSEP=/
endif
else
# Assume that we are running on native Windows
DELETE=del /q
FLASH_TOOL=client/flasher.exe
platform=Windows
FLASH_PORT=com3
PATHSEP=\\#
endif
all clean: %: bootrom/% armsrc/% client/% recovery/%
all clean: %: client/% bootrom/% armsrc/% recovery/% mfkey/%
bootrom/%: FORCE
$(MAKE) -C bootrom $(patsubst bootrom/%,%,$@)
$(MAKE) -C bootrom $(patsubst bootrom/%, %, $@)
armsrc/%: FORCE
$(MAKE) -C armsrc $(patsubst armsrc/%,%,$@)
$(MAKE) -C armsrc $(patsubst armsrc/%, %, $@)
client/%: FORCE
$(MAKE) -C client $(patsubst client/%,%,$@)
$(MAKE) -C client $(patsubst client/%, %, $@)
recovery/%: FORCE
$(MAKE) -C recovery $(patsubst recovery/%,%,$@)
$(MAKE) -C recovery $(patsubst recovery/%, %, $@)
mfkey/%: FORCE
$(MAKE) -C tools/mfkey $(patsubst mfkey/%, %, $@)
FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites)
.PHONY: all clean help _test flash-bootrom flash-os flash-all FORCE
.PHONY: all clean help _test flash-bootrom flash-os flash-fpga flash-both flash-all FORCE
help:
@echo Multi-OS Makefile, you are running on $(DETECTED_OS)
@echo Possible targets:
@echo + all - Make bootrom, armsrc and the OS-specific host directory
@echo + client - Make only the OS-specific host directory
@echo + flash-bootrom - Make bootrom and flash it
@echo + flash-os - Make armsrc and flash os
@echo + flash-fpga - Make armsrc and flash fpga
@echo + flash-both - Make armsrc and flash os and fpga image
@echo + flash-all - Make bootrom and armsrc and flash bootrom, os and fpga image
@echo + flash-os - Make armsrc and flash os \(includes fpga\)
@echo + flash-all - Make bootrom and armsrc and flash bootrom and os image
@echo + clean - Clean in bootrom, armsrc and the OS-specific host directory
client: client/all
mfkey: mfkey/all
flash-bootrom: bootrom/obj/bootrom.elf $(FLASH_TOOL)
$(FLASH_TOOL) $(FLASH_PORT) -b $(subst /,$(PATHSEP),$<)
flash-os: armsrc/obj/osimage.elf $(FLASH_TOOL)
flash-os: armsrc/obj/fullimage.elf $(FLASH_TOOL)
$(FLASH_TOOL) $(FLASH_PORT) $(subst /,$(PATHSEP),$<)
flash-fpga: armsrc/obj/fpgaimage.elf $(FLASH_TOOL)
$(FLASH_TOOL) $(FLASH_PORT) $(subst /,$(PATHSEP),$<)
flash-both: armsrc/obj/osimage.elf armsrc/obj/fpgaimage.elf $(FLASH_TOOL)
$(FLASH_TOOL) $(FLASH_PORT) $(subst /,$(PATHSEP),$(filter-out $(FLASH_TOOL),$^))
flash-all: bootrom/obj/bootrom.elf armsrc/obj/osimage.elf armsrc/obj/fpgaimage.elf $(FLASH_TOOL)
flash-all: bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf $(FLASH_TOOL)
$(FLASH_TOOL) $(FLASH_PORT) -b $(subst /,$(PATHSEP),$(filter-out $(FLASH_TOOL),$^))
newtarbin:

View file

@ -1,51 +1,43 @@
NOTICE:
(2014-03-26)
This is now the official Proxmark repository!
INTRODUCTION:
# proxmark3: the official Proxmark repository!
The proxmark3 is a powerful general purpose RFID tool, the size of a deck
of cards, designed to snoop, listen and emulate everything from
Low Frequency (125kHz) to High Frequency (13.56MHz) tags.
**Low Frequency (125kHz)** to **High Frequency (13.56MHz)** tags.
This repository contains enough software, logic (for the FPGA), and design
documentation for the hardware that you could, at least in theory,
do something useful with a proxmark3.
RESOURCES:
## Resources
* This repository!
https://github.com/Proxmark/proxmark3
* The Wiki
https://github.com/Proxmark/proxmark3/wiki
* The GitHub page
http://proxmark.github.io/proxmark3/
* The Forum
http://www.proxmark.org/forum
* The IRC chanel
irc.freenode.org #proxmark3
-or-
http://webchat.freenode.net/?channels=#proxmark3
* [This repository!](https://github.com/Proxmark/proxmark3)
* [The Wiki](https://github.com/Proxmark/proxmark3/wiki)
* [The GitHub Pages website](http://proxmark.github.io/proxmark3/)
* [The Forum](http://www.proxmark.org/forum)
* The IRC channel: irc.freenode.org #proxmark3 ([chat in your browser](http://webchat.freenode.net/?channels=#proxmark3))
* [The Homebrew formula repository](https://github.com/Proxmark/homebrew-proxmark3)
* [Proxmark3 community discord server](https://discord.gg/86VcRtS)
DEVELOPMENT:
## Development
The tools required to build or run the project will vary depending on
your operating system. Please refer to the Wiki for details.
your operating system. Please refer to [the wiki](https://github.com/Proxmark/proxmark3/wiki) for details.
* https://github.com/Proxmark/proxmark3/wiki
## Obtaining hardware
OBTAINING HARDWARE:
The Proxmark 3 is available for purcahse (assembled and tested) from the
The Proxmark3 is available for purchase (assembled and tested) from the
following locations:
* http://proxmark3.com/
* http://www.xfpga.com/
| Distributor Name | Warehouse Location | Entity Location |
|------------------|--------------------|-----------------|
| [RyscCorp](https://proxmark3.com/) | USA | USA |
| [Hackerwarehouse](https://hackerwarehouse.com/) | USA | USA |
| [Elechouse](http://www.elechouse.com/) | HK | HK |
| [Lab401](https://lab401.com/) | EU | HK |
| [RFxSecure](http://www.rfxsecure.com/) | CN | SG |
| [Sneaktechnology](https://www.sneaktechnology.com/) | CN | CN |
Most of the ultra-low-volume contract assemblers could put
something like this together with a reasonable yield. A run of around
a dozen units is probably cost-effective. The BOM includes (possibly-
@ -64,7 +56,7 @@ The printed circuit board artwork is also available, as Gerbers and an
Excellon drill file.
LICENSING:
## License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -85,4 +77,3 @@ Jonathan Westhues
user jwesthues, at host cq.cx
May 2007, Cambridge MA

295
armsrc/BigBuf.c Normal file
View file

@ -0,0 +1,295 @@
//-----------------------------------------------------------------------------
// Jonathan Westhues, Aug 2005
// Gerhard de Koning Gans, April 2008, May 2011
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// BigBuf and functions to allocate/free parts of it.
//-----------------------------------------------------------------------------
#include <stdint.h>
#include "proxmark3.h"
#include "apps.h"
#include "string.h"
#include "util.h"
// BigBuf is the large multi-purpose buffer, typically used to hold A/D samples or traces.
// Also used to hold various smaller buffers and the Mifare Emulator Memory.
/* BigBuf memory layout:
Pointer to highest available memory: BigBuf_hi
high BIGBUF_SIZE
reserved = BigBuf_malloc() subtracts amount from BigBuf_hi,
low 0x00
*/
// declare it as uint32_t to achieve alignment to 4 Byte boundary
static uint32_t BigBuf[BIGBUF_SIZE/sizeof(uint32_t)];
// High memory mark
static uint16_t BigBuf_hi = BIGBUF_SIZE;
// pointer to the emulator memory.
static uint8_t *emulator_memory = NULL;
// trace related variables
static uint32_t traceLen = 0;
static bool tracing = true;
// get the address of BigBuf
uint8_t *BigBuf_get_addr(void)
{
return (uint8_t *)BigBuf;
}
// get the address of the emulator memory. Allocate part of Bigbuf for it, if not yet done
uint8_t *BigBuf_get_EM_addr(void)
{
// not yet allocated
if (emulator_memory == NULL) {
emulator_memory = BigBuf_malloc(CARD_MEMORY_SIZE);
}
return emulator_memory;
}
// clear ALL of BigBuf
void BigBuf_Clear(void)
{
BigBuf_Clear_ext(true);
}
// clear ALL of BigBuf
void BigBuf_Clear_ext(bool verbose)
{
memset(BigBuf, 0, BIGBUF_SIZE);
if (verbose)
Dbprintf("Buffer cleared (%i bytes)", BIGBUF_SIZE);
}
void BigBuf_Clear_EM(void){
memset(BigBuf_get_EM_addr(), 0, CARD_MEMORY_SIZE);
}
void BigBuf_Clear_keep_EM(void)
{
memset(BigBuf, 0, BigBuf_hi);
}
// allocate a chunk of memory from BigBuf. We allocate high memory first. The unallocated memory
// at the beginning of BigBuf is always for traces/samples
uint8_t *BigBuf_malloc(uint16_t chunksize)
{
if (BigBuf_hi - chunksize < 0) {
return NULL; // no memory left
} else {
chunksize = (chunksize + 3) & 0xfffc; // round to next multiple of 4
BigBuf_hi -= chunksize; // aligned to 4 Byte boundary
return (uint8_t *)BigBuf + BigBuf_hi;
}
}
// free ALL allocated chunks. The whole BigBuf is available for traces or samples again.
void BigBuf_free(void)
{
BigBuf_hi = BIGBUF_SIZE;
emulator_memory = NULL;
}
// free allocated chunks EXCEPT the emulator memory
void BigBuf_free_keep_EM(void)
{
if (emulator_memory != NULL) {
BigBuf_hi = emulator_memory - (uint8_t *)BigBuf;
} else {
BigBuf_hi = BIGBUF_SIZE;
}
}
void BigBuf_print_status(void)
{
Dbprintf("Memory");
Dbprintf(" BIGBUF_SIZE.............%d", BIGBUF_SIZE);
Dbprintf(" Available memory........%d", BigBuf_hi);
Dbprintf("Tracing");
Dbprintf(" tracing ................%d", tracing);
Dbprintf(" traceLen ...............%d", traceLen);
}
// return the maximum trace length (i.e. the unallocated size of BigBuf)
uint16_t BigBuf_max_traceLen(void)
{
return BigBuf_hi;
}
void clear_trace() {
traceLen = 0;
}
void set_tracing(bool enable) {
tracing = enable;
}
bool get_tracing(void) {
return tracing;
}
/**
* Get the number of bytes traced
* @return
*/
uint16_t BigBuf_get_traceLen(void)
{
return traceLen;
}
/**
This is a function to store traces. All protocols can use this generic tracer-function.
The traces produced by calling this function can be fetched on the client-side
by 'hf list raw', alternatively 'hf list <proto>' for protocol-specific
annotation of commands/responses.
**/
bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag)
{
if (!tracing) return false;
uint8_t *trace = BigBuf_get_addr();
uint32_t num_paritybytes = (iLen-1)/8 + 1; // number of valid paritybytes in *parity
uint32_t duration = timestamp_end - timestamp_start;
// Return when trace is full
uint16_t max_traceLen = BigBuf_max_traceLen();
if (traceLen + sizeof(iLen) + sizeof(timestamp_start) + sizeof(duration) + num_paritybytes + iLen >= max_traceLen) {
tracing = false; // don't trace any more
return false;
}
// Traceformat:
// 32 bits timestamp (little endian)
// 16 bits duration (little endian)
// 16 bits data length (little endian, Highest Bit used as readerToTag flag)
// y Bytes data
// x Bytes parity (one byte per 8 bytes data)
// timestamp (start)
trace[traceLen++] = ((timestamp_start >> 0) & 0xff);
trace[traceLen++] = ((timestamp_start >> 8) & 0xff);
trace[traceLen++] = ((timestamp_start >> 16) & 0xff);
trace[traceLen++] = ((timestamp_start >> 24) & 0xff);
// duration
trace[traceLen++] = ((duration >> 0) & 0xff);
trace[traceLen++] = ((duration >> 8) & 0xff);
// data length
trace[traceLen++] = ((iLen >> 0) & 0xff);
trace[traceLen++] = ((iLen >> 8) & 0xff);
// readerToTag flag
if (!readerToTag) {
trace[traceLen - 1] |= 0x80;
}
// data bytes
if (btBytes != NULL && iLen != 0) {
for (int i = 0; i < iLen; i++) {
trace[traceLen++] = *btBytes++;
}
}
// parity bytes
if (num_paritybytes != 0) {
if (parity != NULL) {
for (int i = 0; i < num_paritybytes; i++) {
trace[traceLen++] = *parity++;
}
} else {
for (int i = 0; i < num_paritybytes; i++) {
trace[traceLen++] = 0x00;
}
}
}
return true;
}
int LogTraceHitag(const uint8_t * btBytes, int iBits, int iSamples, uint32_t dwParity, int readerToTag)
{
/**
Todo, rewrite the logger to use the generic functionality instead. It should be noted, however,
that this logger takes number of bits as argument, not number of bytes.
**/
if (!tracing) return false;
uint8_t *trace = BigBuf_get_addr();
uint16_t iLen = nbytes(iBits);
// Return when trace is full
if (traceLen + sizeof(rsamples) + sizeof(dwParity) + sizeof(iBits) + iLen > BigBuf_max_traceLen()) {
return false;
}
//Hitag traces appear to use this traceformat:
// 32 bits timestamp (little endian,Highest Bit used as readerToTag flag)
// 32 bits parity
// 8 bits size (number of bits in the trace entry, not number of bytes)
// y Bytes data
rsamples += iSamples;
trace[traceLen++] = ((rsamples >> 0) & 0xff);
trace[traceLen++] = ((rsamples >> 8) & 0xff);
trace[traceLen++] = ((rsamples >> 16) & 0xff);
trace[traceLen++] = ((rsamples >> 24) & 0xff);
if (!readerToTag) {
trace[traceLen - 1] |= 0x80;
}
trace[traceLen++] = ((dwParity >> 0) & 0xff);
trace[traceLen++] = ((dwParity >> 8) & 0xff);
trace[traceLen++] = ((dwParity >> 16) & 0xff);
trace[traceLen++] = ((dwParity >> 24) & 0xff);
trace[traceLen++] = iBits;
for (int i = 0; i < iLen; i++) {
trace[traceLen++] = *btBytes++;
}
return true;
}
// Emulator memory
uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length){
uint8_t* mem = BigBuf_get_EM_addr();
if (offset+length < CARD_MEMORY_SIZE) {
memcpy(mem+offset, data, length);
return 0;
} else {
Dbprintf("Error, trying to set memory outside of bounds! %d > %d", (offset+length), CARD_MEMORY_SIZE);
return 1;
}
}

44
armsrc/BigBuf.h Normal file
View file

@ -0,0 +1,44 @@
//-----------------------------------------------------------------------------
// Jonathan Westhues, Aug 2005
// Gerhard de Koning Gans, April 2008, May 2011
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// BigBuf and functions to allocate/free parts of it.
//-----------------------------------------------------------------------------
#ifndef __BIGBUF_H
#define __BIGBUF_H
#include <stdbool.h> // for bool
#include "common.h" // for ramfunc
#define BIGBUF_SIZE 40000
#define MAX_FRAME_SIZE 256 // maximum allowed ISO14443 frame
#define MAX_PARITY_SIZE ((MAX_FRAME_SIZE + 7) / 8)
#define MAX_MIFARE_FRAME_SIZE 18 // biggest Mifare frame is answer to a read (one block = 16 Bytes) + 2 Bytes CRC
#define MAX_MIFARE_PARITY_SIZE 3 // need 18 parity bits for the 18 Byte above. 3 Bytes are enough to store these
#define CARD_MEMORY_SIZE 4096
#define DMA_BUFFER_SIZE 128
extern uint8_t *BigBuf_get_addr(void);
extern uint8_t *BigBuf_get_EM_addr(void);
extern uint16_t BigBuf_max_traceLen(void);
extern void BigBuf_Clear(void);
extern void BigBuf_Clear_ext(bool verbose);
extern void BigBuf_Clear_keep_EM(void);
extern void BigBuf_Clear_EM(void);
extern uint8_t *BigBuf_malloc(uint16_t);
extern void BigBuf_free(void);
extern void BigBuf_free_keep_EM(void);
extern void BigBuf_print_status(void);
extern uint16_t BigBuf_get_traceLen(void);
extern void clear_trace(void);
extern void set_tracing(bool enable);
extern bool get_tracing(void);
extern bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag);
extern int LogTraceHitag(const uint8_t * btBytes, int iBits, int iSamples, uint32_t dwParity, int bReader);
extern uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length);
#endif /* __BIGBUF_H */

View file

@ -9,82 +9,136 @@
APP_INCLUDES = apps.h
#remove one of the following defines and comment out the relevant line
#in the next section to remove that particular feature from compilation
APP_CFLAGS = -DWITH_LF -DWITH_ISO15693 -DWITH_ISO14443a -DWITH_ISO14443b -DWITH_ICLASS -DWITH_LEGICRF -DWITH_HITAG
#-DWITH_LCD
#in the next section to remove that particular feature from compilation
APP_CFLAGS = -DON_DEVICE \
-fno-strict-aliasing -ffunction-sections -fdata-sections
#SRC_LCD = fonts.c LCD.c
SRC_LF = lfops.c hitag2.c
SRC_ISO15693 = iso15693.c iso15693tools.c
SRC_ISO14443a = epa.c iso14443a.c mifareutil.c mifarecmd.c mifaresniff.c
SRC_ISO14443b = iso14443.c
SRC_CRAPTO1 = crapto1.c crypto1.c
include ../common/Makefile_Enabled_Options.common
ifneq (,$(findstring WITH_LCD,$(APP_CFLAGS)))
SRC_LCD = fonts.c LCD.c
else
SRC_LCD =
endif
SRC_LF = lfops.c hitag2.c hitagS.c lfsampling.c pcf7931.c lfdemod.c protocols.c
SRC_ISO15693 = iso15693.c
SRC_ISO14443a = epa.c iso14443a.c mifareutil.c mifarecmd.c mifaresniff.c mifaresim.c
SRC_ISO14443b = iso14443b.c
SRC_CRAPTO1 = crypto1.c
SRC_DES = platform_util_arm.c des.c
SRC_CRC = iso14443crc.c crc.c crc16.c crc32.c parity.c iso15693tools.c
SRC_SMARTCARD = i2c.c
#the FPGA bitstream files. Note: order matters!
FPGA_BITSTREAMS = fpga_lf.bit fpga_hf.bit
#the zlib source files required for decompressing the fpga config at run time
SRC_ZLIB = inflate.c inffast.c inftrees.c adler32.c zutil.c
#additional defines required to compile zlib
ZLIB_CFLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED
APP_CFLAGS += $(ZLIB_CFLAGS)
# zlib includes:
APP_CFLAGS += -I../zlib
# Compile these in thumb mode (small size)
THUMBSRC = start.c \
$(SRC_LCD) \
$(SRC_ISO15693) \
$(SRC_LF) \
appmain.c printf.c \
$(SRC_ZLIB) \
$(SRC_SMARTCARD) \
appmain.c \
printf.c \
util.c \
string.c \
usb_cdc.c \
cmd.c
usb_cdc.c
# Compile these in thumb mode optimized for speed (still smaller than ARM mode)
THUMBOPTSRC = $(SRC_ISO15693)
# These are to be compiled in ARM mode
ARMSRC = fpgaloader.c \
legicrf.c \
iso14443crc.c \
crc16.c \
legicrfsim.c \
legic_prng.c \
$(SRC_ISO14443a) \
$(SRC_ISO14443b) \
$(SRC_CRAPTO1) \
legic_prng.c \
$(SRC_DES) \
$(SRC_CRC) \
iclass.c \
crc.c
BigBuf.c \
optimized_cipher.c \
hfsnoop.c
# stdint.h provided locally until GCC 4.5 becomes C99 compliant
APP_CFLAGS += -I.
VERSIONSRC = version.c \
fpga_version_info.c
# Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC
# Do not move this inclusion before the definition of {THUMB,THUMBOPT,ASM,ARM}SRC
include ../common/Makefile.common
OBJS = $(OBJDIR)/osimage.s19 $(OBJDIR)/fpgaimage.s19
OBJS = $(OBJDIR)/fullimage.s19
FPGA_COMPRESSOR = ../client/fpga_compress
all: $(OBJS)
$(OBJDIR)/fpga_lf.o: fpga_lf.bit
$(OBJCOPY) -O elf32-littlearm -I binary -B arm --redefine-sym _binary____fpga_fpga_lf_bit_start=_binary_fpga_lf_bit_start --redefine-sym _binary____fpga_fpga_lf_bit_end=_binary_fpga_lf_bit_end --prefix-sections=fpga_lf_bit $^ $@
.DELETE_ON_ERROR:
$(OBJDIR)/fpga_hf.o: fpga_hf.bit
$(OBJCOPY) -O elf32-littlearm -I binary -B arm --redefine-sym _binary____fpga_fpga_hf_bit_start=_binary_fpga_hf_bit_start --redefine-sym _binary____fpga_fpga_hf_bit_end=_binary_fpga_hf_bit_end --prefix-sections=fpga_hf_bit $^ $@
# version.c and fpga_version_info.c to be remade on every compilation
.PHONY: version.c fpga_version_info.c
$(OBJDIR)/fullimage.elf: $(VERSIONOBJ) $(OBJDIR)/fpga_lf.o $(OBJDIR)/fpga_hf.o $(THUMBOBJ) $(ARMOBJ)
version.c: default_version.c
perl ../tools/mkversion.pl .. > $@ || $(COPY) $^ $@
fpga_version_info.c: $(FPGA_BITSTREAMS) $(FPGA_COMPRESSOR)
$(FPGA_COMPRESSOR) -v $(filter %.bit,$^) $@
$(OBJDIR)/fpga_all.o: $(OBJDIR)/fpga_all.bit.z
$(OBJCOPY) -O elf32-littlearm -I binary -B arm --prefix-sections=fpga_all_bit $^ $@
$(OBJDIR)/fpga_all.bit.z: $(FPGA_BITSTREAMS) $(FPGA_COMPRESSOR)
$(FPGA_COMPRESSOR) $(filter %.bit,$^) $@
$(FPGA_COMPRESSOR):
make -C ../client $(notdir $(FPGA_COMPRESSOR))
$(OBJDIR)/fullimage.stage1.elf: $(VERSIONOBJ) $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(THUMBOPTOBJ) $(ARMOBJ)
$(CC) $(LDFLAGS) -Wl,-T,ldscript,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ $(LIBS)
$(OBJDIR)/fpgaimage.elf: $(OBJDIR)/fullimage.elf
$(OBJCOPY) -F elf32-littlearm --only-section .fpgaimage $^ $@
$(OBJDIR)/fullimage.nodata.bin: $(OBJDIR)/fullimage.stage1.elf
$(OBJCOPY) -O binary -I elf32-littlearm --remove-section .data $^ $@
$(OBJDIR)/osimage.elf: $(OBJDIR)/fullimage.elf
$(OBJCOPY) -F elf32-littlearm --remove-section .fpgaimage $^ $@
$(OBJDIR)/fullimage.nodata.o: $(OBJDIR)/fullimage.nodata.bin
$(OBJCOPY) -O elf32-littlearm -I binary -B arm --rename-section .data=stage1_image $^ $@
$(OBJDIR)/fullimage.data.bin: $(OBJDIR)/fullimage.stage1.elf
$(OBJCOPY) -O binary -I elf32-littlearm --only-section .data $^ $@
$(OBJDIR)/fullimage.data.bin.z: $(OBJDIR)/fullimage.data.bin $(FPGA_COMPRESSOR)
$(FPGA_COMPRESSOR) $(filter %.bin,$^) $@
$(OBJDIR)/fullimage.data.o: $(OBJDIR)/fullimage.data.bin.z
$(OBJCOPY) -O elf32-littlearm -I binary -B arm --rename-section .data=compressed_data $^ $@
$(OBJDIR)/fullimage.elf: $(OBJDIR)/fullimage.nodata.o $(OBJDIR)/fullimage.data.o
$(CC) $(LDFLAGS) -Wl,-T,ldscript,-e,_osimage_entry,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^
tarbin: $(OBJS)
$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(OBJS:%=armsrc/%) $(OBJS:%.s19=armsrc/%.elf)
clean:
$(DELETE) $(OBJDIR)$(PATHSEP)*.o
$(DELETE) $(OBJDIR)$(PATHSEP)*.elf
$(DELETE) $(OBJDIR)$(PATHSEP)*.s19
$(DELETE) $(OBJDIR)$(PATHSEP)*.map
$(DELETE) $(OBJDIR)$(PATHSEP)*.d
$(DELETE) version.c
$(DELETE) $(OBJDIR)$(PATHSEP)*.z
$(DELETE) $(OBJDIR)$(PATHSEP)*.bin
$(DELETE) version.c fpga_version_info.c
.PHONY: all clean help
help:
@echo Multi-OS Makefile, you are running on $(DETECTED_OS)
@echo Possible targets:
@echo + all - Make both:
@echo + $(OBJDIR)/osimage.s19 - The OS image
@echo + $(OBJDIR)/fpgaimage.s19 - The FPGA image
@echo + clean - Clean $(OBJDIR)
@echo + all - Build the full image $(OBJDIR)/fullimage.s19
@echo + clean - Clean $(OBJDIR)

File diff suppressed because it is too large Load diff

View file

@ -15,35 +15,16 @@
#include <stdint.h>
#include <stddef.h>
#include "common.h"
#include "hitag2.h"
#include "usb_cmd.h"
#include "hitagS.h"
#include "mifare.h"
// The large multi-purpose buffer, typically used to hold A/D samples,
// maybe processed in some way.
uint32_t BigBuf[10000];
// BIG CHANGE - UNDERSTAND THIS BEFORE WE COMMIT
#define TRACE_OFFSET 0
#define TRACE_SIZE 3000
#define RECV_CMD_OFFSET 3032
#define RECV_CMD_SIZE 64
#define RECV_RES_OFFSET 3096
#define RECV_RES_SIZE 64
#define DMA_BUFFER_OFFSET 3160
#define DMA_BUFFER_SIZE 4096
#define FREE_BUFFER_OFFSET 7256
#define FREE_BUFFER_SIZE 2744
#include "../common/crc32.h"
#include "BigBuf.h"
extern const uint8_t OddByteParity[256];
extern uint8_t *trace; // = (uint8_t *) BigBuf;
extern int traceLen; // = 0;
extern int rsamples; // = 0;
extern int tracing; // = TRUE;
extern uint8_t trigger;
// This may be used (sparingly) to declare a function to be copied to
// and executed from RAM
#define RAMFUNC __attribute((long_call, section(".ramfunc")))
/// appmain.h
void ReadMem(int addr);
void __attribute__((noreturn)) AppMain(void);
@ -53,164 +34,82 @@ void DbpString(char *str);
void Dbprintf(const char *fmt, ...);
void Dbhexdump(int len, uint8_t *d, bool bAsci);
// ADC Vref = 3300mV, and an (10M+1M):1M voltage divider on the HF input can measure voltages up to 36300 mV
#define MAX_ADC_HF_VOLTAGE_LOW 36300
// ADC Vref = 3300mV, and an (10000k+240k):240k voltage divider on the LF input can measure voltages up to 140800 mV
#define MAX_ADC_HF_VOLTAGE_HIGH 140800
#define MAX_ADC_LF_VOLTAGE 140800
int AvgAdc(int ch);
void ToSendStuffBit(int b);
void ToSendReset(void);
void ListenReaderField(int limit);
void AcquireRawAdcSamples125k(int at134khz);
void SnoopLFRawAdcSamples(int divisor, int trigger_threshold);
void DoAcquisition125k(int trigger_threshold);
extern int ToSendMax;
extern uint8_t ToSend[];
extern uint32_t BigBuf[];
/// fpga.h
void FpgaSendCommand(uint16_t cmd, uint16_t v);
void FpgaWriteConfWord(uint8_t v);
void FpgaDownloadAndGo(int bitstream_version);
int FpgaGatherBitstreamVersion();
void FpgaGatherVersion(char *dst, int len);
void FpgaSetupSsc(void);
void SetupSpi(int mode);
bool FpgaSetupSscDma(uint8_t *buf, int len);
#define FpgaDisableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
#define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
void SetAdcMuxFor(uint32_t whichGpio);
// Definitions for the FPGA commands.
#define FPGA_CMD_SET_CONFREG (1<<12)
#define FPGA_CMD_SET_DIVISOR (2<<12)
#define FPGA_CMD_SET_USER_BYTE1 (3<<12)
// Definitions for the FPGA configuration word.
// LF
#define FPGA_MAJOR_MODE_LF_ADC (0<<5)
#define FPGA_MAJOR_MODE_LF_EDGE_DETECT (1<<5)
#define FPGA_MAJOR_MODE_LF_PASSTHRU (2<<5)
// HF
#define FPGA_MAJOR_MODE_HF_READER_TX (0<<5)
#define FPGA_MAJOR_MODE_HF_READER_RX_XCORR (1<<5)
#define FPGA_MAJOR_MODE_HF_SIMULATOR (2<<5)
#define FPGA_MAJOR_MODE_HF_ISO14443A (3<<5)
// BOTH
#define FPGA_MAJOR_MODE_OFF (7<<5)
// Options for LF_ADC
#define FPGA_LF_ADC_READER_FIELD (1<<0)
// Options for LF_EDGE_DETECT
#define FPGA_CMD_SET_EDGE_DETECT_THRESHOLD FPGA_CMD_SET_USER_BYTE1
#define FPGA_LF_EDGE_DETECT_READER_FIELD (1<<0)
#define FPGA_LF_EDGE_DETECT_TOGGLE_MODE (1<<1)
// Options for the HF reader, tx to tag
#define FPGA_HF_READER_TX_SHALLOW_MOD (1<<0)
// Options for the HF reader, correlating against rx from tag
#define FPGA_HF_READER_RX_XCORR_848_KHZ (1<<0)
#define FPGA_HF_READER_RX_XCORR_SNOOP (1<<1)
#define FPGA_HF_READER_RX_XCORR_QUARTER_FREQ (1<<2)
// Options for the HF simulated tag, how to modulate
#define FPGA_HF_SIMULATOR_NO_MODULATION (0<<0)
#define FPGA_HF_SIMULATOR_MODULATE_BPSK (1<<0)
#define FPGA_HF_SIMULATOR_MODULATE_212K (2<<0)
#define FPGA_HF_SIMULATOR_MODULATE_424K (4<<0)
// Options for ISO14443A
#define FPGA_HF_ISO14443A_SNIFFER (0<<0)
#define FPGA_HF_ISO14443A_TAGSIM_LISTEN (1<<0)
#define FPGA_HF_ISO14443A_TAGSIM_MOD (2<<0)
#define FPGA_HF_ISO14443A_READER_LISTEN (3<<0)
#define FPGA_HF_ISO14443A_READER_MOD (4<<0)
/// lfops.h
extern uint8_t decimation;
extern uint8_t bits_per_sample ;
extern bool averaging;
void AcquireRawAdcSamples125k(int divisor);
void ModThenAcquireRawAdcSamples125k(int delay_off,int period_0,int period_1,uint8_t *command);
void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command);
void ReadTItag(void);
void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc);
void AcquireTiType(void);
void AcquireRawBitsTI(void);
void SimulateTagLowFrequency(int period, int gap, int ledcontrol);
void CmdHIDsimTAG(int hi, int lo, int ledcontrol);
void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol);
void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol);
void CopyIOtoT55x7(uint32_t hi, uint32_t lo, uint8_t longFMT); // Clone an ioProx card to T5557/T5567
void SimulateTagLowFrequencyBidir(int divisor, int max_bitlen);
void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT); // Clone an HID card to T5557/T5567
void CmdHIDsimTAG(int hi2, int hi, int lo, int ledcontrol);
void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream);
void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream);
void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream);
void CmdHIDdemodFSK(int findone, int *high2, int *high, int *low, int ledcontrol);
void CmdAWIDdemodFSK(int findone, int *high, int *low, int ledcontrol); // Realtime demodulation mode for AWID26
void CmdEM410xdemod(int findone, int *high, int *low, int ledcontrol);
void CmdIOdemodFSK(int findone, int *high, int *low, int ledcontrol);
void CopyIOtoT55x7(uint32_t hi, uint32_t lo); // Clone an ioProx card to T5557/T5567
void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT, uint8_t preamble); // Clone an HID-like card to T5557/T5567
void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5);
void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo);
void CopyIndala64toT55x7(int hi, int lo); // Clone Indala 64-bit tag by UID to T55x7
void CopyIndala224toT55x7(int uid1, int uid2, int uid3, int uid4, int uid5, int uid6, int uid7); // Clone Indala 224-bit tag by UID to T55x7
void CopyIndala64toT55x7(uint32_t hi, uint32_t lo); // Clone Indala 64-bit tag by UID to T55x7
void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7); // Clone Indala 224-bit tag by UID to T55x7
void T55xxResetRead(void);
void T55xxWriteBlock(uint32_t Data, uint32_t Block, uint32_t Pwd, uint8_t PwdMode);
void T55xxReadBlock(uint32_t Block, uint32_t Pwd, uint8_t PwdMode );
void T55xxReadTrace(void);
int DemodPCF7931(uint8_t **outBlocks);
int IsBlock0PCF7931(uint8_t *Block);
int IsBlock1PCF7931(uint8_t *Block);
void ReadPCF7931();
void T55xxReadBlock(uint16_t arg0, uint8_t Block, uint32_t Pwd);
void T55xxWakeUp(uint32_t Pwd);
void TurnReadLFOn();
//void T55xxReadTrace(void);
void EM4xReadWord(uint8_t Address, uint32_t Pwd, uint8_t PwdMode);
void EM4xWriteWord(uint32_t Data, uint8_t Address, uint32_t Pwd, uint8_t PwdMode);
void EM4xWriteWord(uint32_t flag, uint32_t Data, uint32_t Pwd);
void EM4xProtect(uint32_t flag, uint32_t Data, uint32_t Pwd);
void Cotag(uint32_t arg0);
/// iso14443.h
void SimulateIso14443Tag(void);
void AcquireRawAdcSamplesIso14443(uint32_t parameter);
void ReadSTMemoryIso14443(uint32_t);
void RAMFUNC SnoopIso14443(void);
void SimulateIso14443bTag(void);
void AcquireRawAdcSamplesIso14443b(uint32_t parameter);
void ReadSTMemoryIso14443b(uint32_t);
void RAMFUNC SnoopIso14443b(void);
void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]);
/// iso14443a.h
void RAMFUNC SnoopIso14443a(uint8_t param);
void SimulateIso14443aTag(int tagType, int uid_1st, int uid_2nd, byte_t* data);
void ReaderIso14443a(UsbCommand * c);
// Also used in iclass.c
bool RAMFUNC LogTrace(const uint8_t * btBytes, uint8_t iLen, uint32_t iSamples, uint32_t dwParity, bool readerToTag);
uint32_t GetParity(const uint8_t * pbtCmd, int iLen);
void iso14a_set_trigger(bool enable);
void iso14a_clear_trace();
void iso14a_set_tracing(bool enable);
void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *parity);
void RAMFUNC SniffMifare(uint8_t param);
/// epa.h
void EPA_PACE_Collect_Nonce(UsbCommand * c);
void EPA_PACE_Replay(UsbCommand *c);
// mifarecmd.h
void ReaderMifare(bool first_try);
int32_t dist_nt(uint32_t nt1, uint32_t nt2);
void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *data);
void MifareUReadBlock(uint8_t arg0,uint8_t *datain);
void MifareUReadCard(uint8_t arg0,uint8_t *datain);
void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
void MifareUWriteBlock(uint8_t arg0,uint8_t *datain);
void MifareUWriteBlock_Special(uint8_t arg0,uint8_t *datain);
void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
void MifareChkKeys(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
void Mifare1ksim(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
void MifareSetDbgLvl(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); // Work with "magic Chinese" card
void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
/// iso15693.h
void RecordRawAdcSamplesIso15693(void);
void AcquireRawAdcSamplesIso15693(void);
void ReaderIso15693(uint32_t parameter); // Simulate an ISO15693 reader - greg
void SimTagIso15693(uint32_t parameter); // simulate an ISO15693 tag - greg
void BruteforceIso15693Afi(uint32_t speed); // find an AFI of a tag - atrox
void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8_t data[]); // send arbitrary commands from CLI - atrox
void SetDebugIso15693(uint32_t flag);
/// iclass.h
void RAMFUNC SnoopIClass(void);
void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
void ReaderIClass(uint8_t arg0);
//int doIClassSimulation(uint8_t csn[], int breakAfterMacReceived);
// hitag2.h
void SnoopHitag(uint32_t type);
void SimulateHitagTag(bool tag_mem_supplied, byte_t* data);
void ReaderHitag(hitag_function htf, hitag_data* htd);
// cmd.h
bool cmd_receive(UsbCommand* cmd);
bool cmd_send(uint32_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2, void* data, size_t len);
/// util.h
// mifaredesfire.h
bool InitDesfireCard();
void MifareSendCommand(uint8_t arg0,uint8_t arg1, uint8_t *datain);
void MifareDesfireGetInformation();
void MifareDES_Auth1(uint8_t arg0,uint8_t arg1,uint8_t arg2, uint8_t *datain);
void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t * datain);
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout);
size_t CreateAPDU( uint8_t *datain, size_t len, uint8_t *dataout);
#endif

View file

@ -1,95 +0,0 @@
/* crypto1.c
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, US
Copyright (C) 2008-2008 bla <blapost@gmail.com>
*/
#include "crapto1.h"
#include <stdlib.h>
#define SWAPENDIAN(x)\
(x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16)
void crypto1_create(struct Crypto1State *s, uint64_t key)
{
// struct Crypto1State *s = malloc(sizeof(*s));
int i;
for(i = 47;s && i > 0; i -= 2) {
s->odd = s->odd << 1 | BIT(key, (i - 1) ^ 7);
s->even = s->even << 1 | BIT(key, i ^ 7);
}
return;
}
void crypto1_destroy(struct Crypto1State *state)
{
// free(state);
state->odd = 0;
state->even = 0;
}
void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr)
{
int i;
for(*lfsr = 0, i = 23; i >= 0; --i) {
*lfsr = *lfsr << 1 | BIT(state->odd, i ^ 3);
*lfsr = *lfsr << 1 | BIT(state->even, i ^ 3);
}
}
uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted)
{
uint32_t feedin;
uint8_t ret = filter(s->odd);
feedin = ret & !!is_encrypted;
feedin ^= !!in;
feedin ^= LF_POLY_ODD & s->odd;
feedin ^= LF_POLY_EVEN & s->even;
s->even = s->even << 1 | parity(feedin);
s->odd ^= (s->odd ^= s->even, s->even ^= s->odd);
return ret;
}
uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted)
{
uint8_t i, ret = 0;
for (i = 0; i < 8; ++i)
ret |= crypto1_bit(s, BIT(in, i), is_encrypted) << i;
return ret;
}
uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted)
{
uint32_t i, ret = 0;
for (i = 0; i < 32; ++i)
ret |= crypto1_bit(s, BEBIT(in, i), is_encrypted) << (i ^ 24);
return ret;
}
/* prng_successor
* helper used to obscure the keystream during authentication
*/
uint32_t prng_successor(uint32_t x, uint32_t n)
{
SWAPENDIAN(x);
while(n--)
x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31;
return SWAPENDIAN(x);
}

View file

@ -5,17 +5,22 @@
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Routines to support the German eletronic "Personalausweis" (ID card)
// Routines to support the German electronic "Personalausweis" (ID card)
// Note that the functions which do not implement USB commands do NOT initialize
// the card (with iso14443a_select_card etc.). If You want to use these
// functions, You need to do the setup before calling them!
//-----------------------------------------------------------------------------
#include "apps.h"
#include "iso14443a.h"
#include "iso14443b.h"
#include "epa.h"
#include "cmd.h"
#include "usb_cdc.h"
#include "fpgaloader.h"
#include "string.h"
#include "util.h"
// Protocol and Parameter Selection Request
// Protocol and Parameter Selection Request for ISO 14443 type A cards
// use regular (1x) speed in both directions
// CRC is already included
static const uint8_t pps[] = {0xD0, 0x11, 0x00, 0x52, 0xA6};
@ -74,6 +79,54 @@ static const uint8_t oid_pace_start[] = {
0x04 // id-PACE
};
// APDUs for replaying:
// MSE: Set AT (initiate PACE)
static uint8_t apdu_replay_mse_set_at_pace[41];
// General Authenticate (Get Nonce)
static uint8_t apdu_replay_general_authenticate_pace_get_nonce[8];
// General Authenticate (Map Nonce)
static uint8_t apdu_replay_general_authenticate_pace_map_nonce[75];
// General Authenticate (Mutual Authenticate)
static uint8_t apdu_replay_general_authenticate_pace_mutual_authenticate[75];
// General Authenticate (Perform Key Agreement)
static uint8_t apdu_replay_general_authenticate_pace_perform_key_agreement[18];
// pointers to the APDUs (for iterations)
static struct {
uint8_t len;
uint8_t *data;
} const apdus_replay[] = {
{sizeof(apdu_replay_mse_set_at_pace), apdu_replay_mse_set_at_pace},
{sizeof(apdu_replay_general_authenticate_pace_get_nonce), apdu_replay_general_authenticate_pace_get_nonce},
{sizeof(apdu_replay_general_authenticate_pace_map_nonce), apdu_replay_general_authenticate_pace_map_nonce},
{sizeof(apdu_replay_general_authenticate_pace_mutual_authenticate), apdu_replay_general_authenticate_pace_mutual_authenticate},
{sizeof(apdu_replay_general_authenticate_pace_perform_key_agreement), apdu_replay_general_authenticate_pace_perform_key_agreement}
};
// lengths of the replay APDUs
static uint8_t apdu_lengths_replay[5];
// type of card (ISO 14443 A or B)
static char iso_type = 0;
//-----------------------------------------------------------------------------
// Wrapper for sending APDUs to type A and B cards
//-----------------------------------------------------------------------------
int EPA_APDU(uint8_t *apdu, size_t length, uint8_t *response)
{
switch(iso_type)
{
case 'a':
return iso14_apdu(apdu, (uint16_t) length, false, response, NULL);
break;
case 'b':
return iso14443b_apdu(apdu, length, response);
break;
default:
return 0;
break;
}
}
//-----------------------------------------------------------------------------
// Closes the communication channel and turns off the field
//-----------------------------------------------------------------------------
@ -81,6 +134,7 @@ void EPA_Finish()
{
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LEDsoff();
iso_type = 0;
}
//-----------------------------------------------------------------------------
@ -101,16 +155,16 @@ size_t EPA_Parse_CardAccess(uint8_t *data,
pace_version_info_t *pace_info)
{
size_t index = 0;
while (index <= length - 2) {
// determine type of element
// SET or SEQUENCE
if (data[index] == 0x31 || data[index] == 0x30) {
// enter the set (skip tag + length)
index += 2;
// extended length
// check for extended length
if ((data[index - 1] & 0x80) != 0) {
index += (data[index] & 0x7F);
index += (data[index-1] & 0x7F);
}
}
// OID
@ -158,7 +212,7 @@ size_t EPA_Parse_CardAccess(uint8_t *data,
index += 2 + data[index + 1];
}
}
// TODO: We should check whether we reached the end in error, but for that
// we need a better parser (e.g. with states like IN_SET or IN_PACE_INFO)
return 0;
@ -176,29 +230,31 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length)
// we reserve 262 bytes here just to be safe (256-byte APDU + SW + ISO frame)
uint8_t response_apdu[262];
int rapdu_length = 0;
// select the file EF.CardAccess
rapdu_length = iso14_apdu((uint8_t *)apdu_select_binary_cardaccess,
rapdu_length = EPA_APDU((uint8_t *)apdu_select_binary_cardaccess,
sizeof(apdu_select_binary_cardaccess),
response_apdu);
if (rapdu_length != 6
if (rapdu_length < 6
|| response_apdu[rapdu_length - 4] != 0x90
|| response_apdu[rapdu_length - 3] != 0x00)
{
DbpString("Failed to select EF.CardAccess!");
return -1;
}
// read the file
rapdu_length = iso14_apdu((uint8_t *)apdu_read_binary,
rapdu_length = EPA_APDU((uint8_t *)apdu_read_binary,
sizeof(apdu_read_binary),
response_apdu);
if (rapdu_length <= 6
|| response_apdu[rapdu_length - 4] != 0x90
|| response_apdu[rapdu_length - 3] != 0x00)
{
Dbprintf("Failed to read EF.CardAccess!");
return -1;
}
// copy the content into the buffer
// length of data available: apdu_length - 4 (ISO frame) - 2 (SW)
size_t to_copy = rapdu_length - 6;
@ -213,17 +269,11 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length)
//-----------------------------------------------------------------------------
static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return)
{
// // step in which the failure occured
// ack->arg[0] = step;
// // last return code
// ack->arg[1] = func_return;
// power down the field
EPA_Finish();
// send the USB packet
cmd_send(CMD_ACK,step,func_return,0,0,0);
//UsbSendPacket((void *)ack, sizeof(UsbCommand));
cmd_send(CMD_ACK,step,func_return,0,0,0);
}
//-----------------------------------------------------------------------------
@ -243,12 +293,8 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
*/
// return value of a function
int func_return;
int func_return = 0;
// // initialize ack with 0s
// memset(ack->arg, 0, 12);
// memset(ack->d.asBytes, 0, 48);
// set up communication
func_return = EPA_Setup();
if (func_return != 0) {
@ -256,9 +302,6 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
return;
}
// increase the timeout (at least some cards really do need this!)
iso14a_set_timeout(0x0002FFFF);
// read the CardAccess file
// this array will hold the CardAccess file
uint8_t card_access[256] = {0};
@ -279,11 +322,11 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
EPA_PACE_Collect_Nonce_Abort(3, func_return);
return;
}
// initiate the PACE protocol
// use the CAN for the password since that doesn't change
func_return = EPA_PACE_MSE_Set_AT(pace_version_info, 2);
// now get the nonce
uint8_t nonce[256] = {0};
uint8_t requested_size = (uint8_t)c->arg[0];
@ -294,15 +337,12 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
EPA_PACE_Collect_Nonce_Abort(4, func_return);
return;
}
// all done, return
// all done, return
EPA_Finish();
// save received information
// ack->arg[1] = func_return;
// memcpy(ack->d.asBytes, nonce, func_return);
// UsbSendPacket((void *)ack, sizeof(UsbCommand));
cmd_send(CMD_ACK,0,func_return,0,nonce,func_return);
cmd_send(CMD_ACK,0,func_return,0,nonce,func_return);
}
//-----------------------------------------------------------------------------
@ -323,10 +363,10 @@ int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce)
sizeof(apdu_general_authenticate_pace_get_nonce));
// append Le (requested length + 2 due to tag/length taking 2 bytes) in RAPDU
apdu[sizeof(apdu_general_authenticate_pace_get_nonce)] = requested_length + 4;
// send it
uint8_t response_apdu[262];
int send_return = iso14_apdu(apdu,
int send_return = EPA_APDU(apdu,
sizeof(apdu),
response_apdu);
// check if the command succeeded
@ -336,7 +376,7 @@ int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce)
{
return -1;
}
// if there is no nonce in the RAPDU, return here
if (send_return < 10)
{
@ -351,7 +391,7 @@ int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce)
}
// copy the nonce
memcpy(nonce, response_apdu + 6, nonce_length);
return nonce_length;
}
@ -397,7 +437,7 @@ int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password)
apdu[4] = apdu_length - 5;
// send it
uint8_t response_apdu[6];
int send_return = iso14_apdu(apdu,
int send_return = EPA_APDU(apdu,
apdu_length,
response_apdu);
// check if the command succeeded
@ -410,34 +450,106 @@ int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password)
return 0;
}
//-----------------------------------------------------------------------------
// Perform the PACE protocol by replaying given APDUs
//-----------------------------------------------------------------------------
void EPA_PACE_Replay(UsbCommand *c) {
uint32_t timings[sizeof(apdu_lengths_replay) / sizeof(apdu_lengths_replay[0])] = {0};
// if an APDU has been passed, just save it
if (c->arg[0] != 0) {
// make sure it's not too big
if(c->arg[2] > apdus_replay[c->arg[0] - 1].len) {
cmd_send(CMD_ACK, 1, 0, 0, NULL, 0);
return;
}
memcpy(apdus_replay[c->arg[0] - 1].data + c->arg[1], c->d.asBytes, c->arg[2]);
// save/update APDU length
if (c->arg[1] == 0) {
apdu_lengths_replay[c->arg[0] - 1] = c->arg[2];
} else {
apdu_lengths_replay[c->arg[0] - 1] += c->arg[2];
}
cmd_send(CMD_ACK, 0, 0, 0, NULL, 0);
return;
}
// return value of a function
int func_return;
// set up communication
func_return = EPA_Setup();
if (func_return != 0) {
EPA_Finish();
cmd_send(CMD_ACK, 2, func_return, 0, NULL, 0);
return;
}
// response APDU
uint8_t response_apdu[300] = {0};
// now replay the data and measure the timings
for (int i = 0; i < sizeof(apdu_lengths_replay); i++) {
StartCountUS();
func_return = EPA_APDU(apdus_replay[i].data,
apdu_lengths_replay[i],
response_apdu);
timings[i] = GetCountUS();
// every step but the last one should succeed
if (i < sizeof(apdu_lengths_replay) - 1
&& (func_return < 6
|| response_apdu[func_return - 4] != 0x90
|| response_apdu[func_return - 3] != 0x00))
{
EPA_Finish();
cmd_send(CMD_ACK, 3 + i, func_return, 0, timings, 20);
return;
}
}
EPA_Finish();
cmd_send(CMD_ACK,0,0,0,timings,20);
return;
}
//-----------------------------------------------------------------------------
// Set up a communication channel (Card Select, PPS)
// Returns 0 on success or a non-zero error code on failure
//-----------------------------------------------------------------------------
int EPA_Setup()
{
// return code
int return_code = 0;
// card UID
uint8_t uid[8];
// card select information
uint8_t uid[10];
uint8_t pps_response[3];
uint8_t pps_response_par[1];
iso14a_card_select_t card_select_info;
// first, look for type A cards
// power up the field
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
// select the card
return_code = iso14443a_select_card(uid, &card_select_info, NULL);
if (return_code != 1) {
return 1;
return_code = iso14443a_select_card(uid, &card_select_info, NULL, true, 0, false);
if (return_code == 1) {
// send the PPS request
ReaderTransmit((uint8_t *)pps, sizeof(pps), NULL);
return_code = ReaderReceive(pps_response, pps_response_par);
if (return_code != 3 || pps_response[0] != 0xD0) {
return return_code == 0 ? 2 : return_code;
}
Dbprintf("ISO 14443 Type A");
iso_type = 'a';
return 0;
}
// send the PPS request
ReaderTransmit((uint8_t *)pps, sizeof(pps), NULL);
uint8_t pps_response[3];
return_code = ReaderReceive(pps_response);
if (return_code != 3 || pps_response[0] != 0xD0) {
return return_code == 0 ? 2 : return_code;
// if we're here, there is no type A card, so we look for type B
// power up the field
iso14443b_setup();
// select the card
return_code = iso14443b_select_card();
if (return_code == 1) {
Dbprintf("ISO 14443 Type B");
iso_type = 'b';
return 0;
}
return 0;
}
Dbprintf("No card found.");
return 1;
}

View file

@ -19,7 +19,7 @@ typedef struct {
uint8_t parameter_id;
} pace_version_info_t;
// note: EPA_PACE_GetNonce is declared in apps.h
// note: EPA_PACE_Collect_Nonce and EPA_PACE_Replay are declared in apps.h
// general functions
void EPA_Finish();
@ -33,4 +33,4 @@ int EPA_Setup();
int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password);
int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce);
#endif /* __EPA_H */
#endif /* __EPA_H */

View file

@ -9,10 +9,30 @@
// Routines to load the FPGA image, and then to configure the FPGA's major
// mode once it is configured.
//-----------------------------------------------------------------------------
#include "proxmark3.h"
#include "fpgaloader.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "apps.h"
#include "fpga.h"
#include "proxmark3.h"
#include "util.h"
#include "string.h"
#include "BigBuf.h"
#include "zlib.h"
// remember which version of the bitstream we have already downloaded to the FPGA
static int downloaded_bitstream = 0;
// this is where the bitstreams are located in memory:
extern uint8_t _binary_obj_fpga_all_bit_z_start, _binary_obj_fpga_all_bit_z_end;
static uint8_t *fpga_image_ptr = NULL;
static uint32_t uncompressed_bytes_cnt;
#define OUTPUT_BUFFER_LEN 80
//-----------------------------------------------------------------------------
// Set up the Serial Peripheral Interface as master
@ -29,16 +49,16 @@ void SetupSpi(int mode)
// Disable PIO control of the following pins, allows use by the SPI peripheral
AT91C_BASE_PIOA->PIO_PDR =
GPIO_NCS0 |
GPIO_NCS2 |
GPIO_MISO |
GPIO_MOSI |
GPIO_NCS0 |
GPIO_NCS2 |
GPIO_MISO |
GPIO_MOSI |
GPIO_SPCK;
AT91C_BASE_PIOA->PIO_ASR =
GPIO_NCS0 |
GPIO_MISO |
GPIO_MOSI |
GPIO_NCS0 |
GPIO_MISO |
GPIO_MOSI |
GPIO_SPCK;
AT91C_BASE_PIOA->PIO_BSR = GPIO_NCS2;
@ -51,57 +71,56 @@ void SetupSpi(int mode)
switch (mode) {
case SPI_FPGA_MODE:
AT91C_BASE_SPI->SPI_MR =
( 0 << 24) | // Delay between chip selects (take default: 6 MCK periods)
(14 << 16) | // Peripheral Chip Select (selects FPGA SPI_NCS0 or PA11)
( 0 << 7) | // Local Loopback Disabled
( 1 << 4) | // Mode Fault Detection disabled
( 0 << 2) | // Chip selects connected directly to peripheral
( 0 << 1) | // Fixed Peripheral Select
( 1 << 0); // Master Mode
( 0 << 24) | // Delay between chip selects (take default: 6 MCK periods)
(14 << 16) | // Peripheral Chip Select (selects FPGA SPI_NCS0 or PA11)
( 0 << 7) | // Local Loopback Disabled
( 1 << 4) | // Mode Fault Detection disabled
( 0 << 2) | // Chip selects connected directly to peripheral
( 0 << 1) | // Fixed Peripheral Select
( 1 << 0); // Master Mode
AT91C_BASE_SPI->SPI_CSR[0] =
( 1 << 24) | // Delay between Consecutive Transfers (32 MCK periods)
( 1 << 16) | // Delay Before SPCK (1 MCK period)
( 6 << 8) | // Serial Clock Baud Rate (baudrate = MCK/6 = 24Mhz/6 = 4M baud
( 8 << 4) | // Bits per Transfer (16 bits)
( 0 << 3) | // Chip Select inactive after transfer
( 1 << 1) | // Clock Phase data captured on leading edge, changes on following edge
( 0 << 0); // Clock Polarity inactive state is logic 0
( 1 << 24) | // Delay between Consecutive Transfers (32 MCK periods)
( 1 << 16) | // Delay Before SPCK (1 MCK period)
( 6 << 8) | // Serial Clock Baud Rate (baudrate = MCK/6 = 24Mhz/6 = 4M baud
( 8 << 4) | // Bits per Transfer (16 bits)
( 0 << 3) | // Chip Select inactive after transfer
( 1 << 1) | // Clock Phase data captured on leading edge, changes on following edge
( 0 << 0); // Clock Polarity inactive state is logic 0
break;
case SPI_LCD_MODE:
AT91C_BASE_SPI->SPI_MR =
( 0 << 24) | // Delay between chip selects (take default: 6 MCK periods)
(11 << 16) | // Peripheral Chip Select (selects LCD SPI_NCS2 or PA10)
( 0 << 7) | // Local Loopback Disabled
( 1 << 4) | // Mode Fault Detection disabled
( 0 << 2) | // Chip selects connected directly to peripheral
( 0 << 1) | // Fixed Peripheral Select
( 1 << 0); // Master Mode
( 0 << 24) | // Delay between chip selects (take default: 6 MCK periods)
(11 << 16) | // Peripheral Chip Select (selects LCD SPI_NCS2 or PA10)
( 0 << 7) | // Local Loopback Disabled
( 1 << 4) | // Mode Fault Detection disabled
( 0 << 2) | // Chip selects connected directly to peripheral
( 0 << 1) | // Fixed Peripheral Select
( 1 << 0); // Master Mode
AT91C_BASE_SPI->SPI_CSR[2] =
( 1 << 24) | // Delay between Consecutive Transfers (32 MCK periods)
( 1 << 16) | // Delay Before SPCK (1 MCK period)
( 6 << 8) | // Serial Clock Baud Rate (baudrate = MCK/6 = 24Mhz/6 = 4M baud
( 1 << 4) | // Bits per Transfer (9 bits)
( 0 << 3) | // Chip Select inactive after transfer
( 1 << 1) | // Clock Phase data captured on leading edge, changes on following edge
( 0 << 0); // Clock Polarity inactive state is logic 0
( 1 << 24) | // Delay between Consecutive Transfers (32 MCK periods)
( 1 << 16) | // Delay Before SPCK (1 MCK period)
( 6 << 8) | // Serial Clock Baud Rate (baudrate = MCK/6 = 24Mhz/6 = 4M baud
( 1 << 4) | // Bits per Transfer (9 bits)
( 0 << 3) | // Chip Select inactive after transfer
( 1 << 1) | // Clock Phase data captured on leading edge, changes on following edge
( 0 << 0); // Clock Polarity inactive state is logic 0
break;
default: // Disable SPI
default: // Disable SPI
AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIDIS;
break;
}
}
//-----------------------------------------------------------------------------
// Set up the synchronous serial port, with the one set of options that we
// always use when we are talking to the FPGA. Both RX and TX are enabled.
// Set up the synchronous serial port with the set of options that fits
// the FPGA mode. Both RX and TX are always enabled.
//-----------------------------------------------------------------------------
void FpgaSetupSsc(void)
{
void FpgaSetupSsc(uint16_t FPGA_mode) {
// First configure the GPIOs, and get ourselves a clock.
AT91C_BASE_PIOA->PIO_ASR =
GPIO_SSC_FRAME |
GPIO_SSC_DIN |
GPIO_SSC_DOUT |
GPIO_SSC_FRAME |
GPIO_SSC_DIN |
GPIO_SSC_DOUT |
GPIO_SSC_CLK;
AT91C_BASE_PIOA->PIO_PDR = GPIO_SSC_DOUT;
@ -110,17 +129,21 @@ void FpgaSetupSsc(void)
// Now set up the SSC proper, starting from a known state.
AT91C_BASE_SSC->SSC_CR = AT91C_SSC_SWRST;
// RX clock comes from TX clock, RX starts when TX starts, data changes
// on RX clock rising edge, sampled on falling edge
// RX clock comes from TX clock, RX starts on Transmit Start,
// data and frame signal is sampled on falling edge of RK
AT91C_BASE_SSC->SSC_RCMR = SSC_CLOCK_MODE_SELECT(1) | SSC_CLOCK_MODE_START(1);
// 8 bits per transfer, no loopback, MSB first, 1 transfer per sync
// 8, 16 or 32 bits per transfer, no loopback, MSB first, 1 transfer per sync
// pulse, no output sync
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
if ((FPGA_mode & FPGA_MAJOR_MODE_MASK) == FPGA_MAJOR_MODE_HF_READER && FpgaGetCurrent() == FPGA_BITSTREAM_HF) {
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
} else {
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
}
// clock comes from TK pin, no clock output, outputs change on falling
// edge of TK, sample on rising edge of TK, start on positive-going edge of sync
AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5);
// TX clock comes from TK pin, no clock output, outputs change on rising edge of TK,
// TF (frame sync) is sampled on falling edge of TK, start TX on rising edge of TF
AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5);
// tx framing is the same as the rx framing
AT91C_BASE_SSC->SSC_TFMR = AT91C_BASE_SSC->SSC_RFMR;
@ -134,22 +157,105 @@ void FpgaSetupSsc(void)
// ourselves, not to another buffer). The stuff to manipulate those buffers
// is in apps.h, because it should be inlined, for speed.
//-----------------------------------------------------------------------------
bool FpgaSetupSscDma(uint8_t *buf, int len)
{
if (buf == NULL) {
return false;
}
bool FpgaSetupSscDma(uint8_t *buf, uint16_t sample_count) {
if (buf == NULL) return false;
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // transfer to this memory address
AT91C_BASE_PDC_SSC->PDC_RCR = len; // transfer this many bytes
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) buf; // next transfer to same memory address
AT91C_BASE_PDC_SSC->PDC_RNCR = len; // ... with same number of bytes
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // go!
return true;
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf; // transfer to this memory address
AT91C_BASE_PDC_SSC->PDC_RCR = sample_count; // transfer this many samples
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) buf; // next transfer to same memory address
AT91C_BASE_PDC_SSC->PDC_RNCR = sample_count; // ... with same number of samples
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // go!
return true;
}
//----------------------------------------------------------------------------
// Uncompress (inflate) the FPGA data. Returns one decompressed byte with
// each call.
//----------------------------------------------------------------------------
static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
if (fpga_image_ptr == compressed_fpga_stream->next_out) { // need more data
compressed_fpga_stream->next_out = output_buffer;
compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
fpga_image_ptr = output_buffer;
int res = inflate(compressed_fpga_stream, Z_SYNC_FLUSH);
if (res != Z_OK)
Dbprintf("inflate returned: %d, %s", res, compressed_fpga_stream->msg);
if (res < 0)
return res;
}
uncompressed_bytes_cnt++;
return *fpga_image_ptr++;
}
//----------------------------------------------------------------------------
// Undo the interleaving of several FPGA config files. FPGA config files
// are combined into one big file:
// 288 bytes from FPGA file 1, followed by 288 bytes from FGPA file 2, etc.
//----------------------------------------------------------------------------
static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
while((uncompressed_bytes_cnt / FPGA_INTERLEAVE_SIZE) % fpga_bitstream_num != (bitstream_version - 1)) {
// skip undesired data belonging to other bitstream_versions
get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
}
return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
}
static voidpf fpga_inflate_malloc(voidpf opaque, uInt items, uInt size)
{
return BigBuf_malloc(items*size);
}
static void fpga_inflate_free(voidpf opaque, voidpf address)
{
BigBuf_free(); BigBuf_Clear_ext(false);
}
//----------------------------------------------------------------------------
// Initialize decompression of the respective (HF or LF) FPGA stream
//----------------------------------------------------------------------------
static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
uint8_t header[FPGA_BITSTREAM_FIXED_HEADER_SIZE];
uncompressed_bytes_cnt = 0;
// initialize z_stream structure for inflate:
compressed_fpga_stream->next_in = &_binary_obj_fpga_all_bit_z_start;
compressed_fpga_stream->avail_in = &_binary_obj_fpga_all_bit_z_end - &_binary_obj_fpga_all_bit_z_start;
compressed_fpga_stream->next_out = output_buffer;
compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
compressed_fpga_stream->zalloc = &fpga_inflate_malloc;
compressed_fpga_stream->zfree = &fpga_inflate_free;
inflateInit2(compressed_fpga_stream, 0);
fpga_image_ptr = output_buffer;
for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++) {
header[i] = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
}
// Check for a valid .bit file (starts with bitparse_fixed_header)
if(memcmp(bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0) {
return true;
} else {
return false;
}
}
static void DownloadFPGA_byte(unsigned char w)
{
#define SEND_BIT(x) { if(w & (1<<x) ) HIGH(GPIO_FPGA_DIN); else LOW(GPIO_FPGA_DIN); HIGH(GPIO_FPGA_CCLK); LOW(GPIO_FPGA_CCLK); }
@ -163,28 +269,30 @@ static void DownloadFPGA_byte(unsigned char w)
SEND_BIT(0);
}
// Download the fpga image starting at FpgaImage and with length FpgaImageLen bytes
// If bytereversal is set: reverse the byte order in each 4-byte word
static void DownloadFPGA(const char *FpgaImage, int FpgaImageLen, int bytereversal)
// Download the fpga image starting at current stream position with length FpgaImageLen bytes
static void DownloadFPGA(int bitstream_version, int FpgaImageLen, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
//Dbprintf("DownloadFPGA(len: %d)", FpgaImageLen);
int i=0;
AT91C_BASE_PIOA->PIO_OER = GPIO_FPGA_ON;
AT91C_BASE_PIOA->PIO_PER = GPIO_FPGA_ON;
HIGH(GPIO_FPGA_ON); // ensure everything is powered on
HIGH(GPIO_FPGA_ON); // ensure everything is powered on
SpinDelay(50);
LED_D_ON();
// These pins are inputs
AT91C_BASE_PIOA->PIO_ODR =
GPIO_FPGA_NINIT |
GPIO_FPGA_DONE;
AT91C_BASE_PIOA->PIO_ODR =
GPIO_FPGA_NINIT |
GPIO_FPGA_DONE;
// PIO controls the following pins
AT91C_BASE_PIOA->PIO_PER =
GPIO_FPGA_NINIT |
GPIO_FPGA_DONE;
AT91C_BASE_PIOA->PIO_PER =
GPIO_FPGA_NINIT |
GPIO_FPGA_DONE;
// Enable pull-ups
AT91C_BASE_PIOA->PIO_PPUER =
GPIO_FPGA_NINIT |
@ -196,8 +304,8 @@ static void DownloadFPGA(const char *FpgaImage, int FpgaImageLen, int byterevers
LOW(GPIO_FPGA_DIN);
// These pins are outputs
AT91C_BASE_PIOA->PIO_OER =
GPIO_FPGA_NPROGRAM |
GPIO_FPGA_CCLK |
GPIO_FPGA_NPROGRAM |
GPIO_FPGA_CCLK |
GPIO_FPGA_DIN;
// enter FPGA configuration mode
@ -218,21 +326,13 @@ static void DownloadFPGA(const char *FpgaImage, int FpgaImageLen, int byterevers
return;
}
if(bytereversal) {
/* This is only supported for uint32_t aligned images */
if( ((int)FpgaImage % sizeof(uint32_t)) == 0 ) {
i=0;
while(FpgaImageLen-->0)
DownloadFPGA_byte(FpgaImage[(i++)^0x3]);
/* Explanation of the magic in the above line:
* i^0x3 inverts the lower two bits of the integer i, counting backwards
* for each 4 byte increment. The generated sequence of (i++)^3 is
* 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12 etc. pp.
*/
for(i = 0; i < FpgaImageLen; i++) {
int b = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
if (b < 0) {
Dbprintf("Error %d during FpgaDownload", b);
break;
}
} else {
while(FpgaImageLen-->0)
DownloadFPGA_byte(*FpgaImage++);
DownloadFPGA_byte(b);
}
// continue to clock FPGA until ready signal goes high
@ -250,39 +350,21 @@ static void DownloadFPGA(const char *FpgaImage, int FpgaImageLen, int byterevers
LED_D_OFF();
}
static char *bitparse_headers_start;
static char *bitparse_bitstream_end;
static int bitparse_initialized = 0;
/* Simple Xilinx .bit parser. The file starts with the fixed opaque byte sequence
* 00 09 0f f0 0f f0 0f f0 0f f0 00 00 01
* After that the format is 1 byte section type (ASCII character), 2 byte length
* (big endian), <length> bytes content. Except for section 'e' which has 4 bytes
* length.
*/
static const char _bitparse_fixed_header[] = {0x00, 0x09, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x00, 0x00, 0x01};
static int bitparse_init(void * start_address, void *end_address)
static int bitparse_find_section(int bitstream_version, char section_name, unsigned int *section_length, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
bitparse_initialized = 0;
if(memcmp(_bitparse_fixed_header, start_address, sizeof(_bitparse_fixed_header)) != 0) {
return 0; /* Not matched */
} else {
bitparse_headers_start= ((char*)start_address) + sizeof(_bitparse_fixed_header);
bitparse_bitstream_end= (char*)end_address;
bitparse_initialized = 1;
return 1;
}
}
int bitparse_find_section(char section_name, char **section_start, unsigned int *section_length)
{
char *pos = bitparse_headers_start;
int result = 0;
if(!bitparse_initialized) return 0;
while(pos < bitparse_bitstream_end) {
char current_name = *pos++;
#define MAX_FPGA_BIT_STREAM_HEADER_SEARCH 100 // maximum number of bytes to search for the requested section
uint16_t numbytes = 0;
while(numbytes < MAX_FPGA_BIT_STREAM_HEADER_SEARCH) {
char current_name = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
numbytes++;
unsigned int current_length = 0;
if(current_name < 'a' || current_name > 'e') {
/* Strange section name, abort */
@ -292,11 +374,13 @@ int bitparse_find_section(char section_name, char **section_start, unsigned int
switch(current_name) {
case 'e':
/* Four byte length field */
current_length += (*pos++) << 24;
current_length += (*pos++) << 16;
current_length += get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer) << 24;
current_length += get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer) << 16;
numbytes += 2;
default: /* Fall through, two byte length field */
current_length += (*pos++) << 8;
current_length += (*pos++) << 0;
current_length += get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer) << 8;
current_length += get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer) << 0;
numbytes += 2;
}
if(current_name != 'e' && current_length > 255) {
@ -306,132 +390,90 @@ int bitparse_find_section(char section_name, char **section_start, unsigned int
if(current_name == section_name) {
/* Found it */
*section_start = pos;
*section_length = current_length;
result = 1;
break;
}
pos += current_length; /* Skip section */
for (uint16_t i = 0; i < current_length && numbytes < MAX_FPGA_BIT_STREAM_HEADER_SEARCH; i++) {
get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
numbytes++;
}
}
return result;
}
//-----------------------------------------------------------------------------
// Find out which FPGA image format is stored in flash, then call DownloadFPGA
// with the right parameters to download the image
//-----------------------------------------------------------------------------
extern char _binary_fpga_lf_bit_start, _binary_fpga_lf_bit_end;
extern char _binary_fpga_hf_bit_start, _binary_fpga_hf_bit_end;
//----------------------------------------------------------------------------
// Check which FPGA image is currently loaded (if any). If necessary
// decompress and load the correct (HF or LF) image to the FPGA
//----------------------------------------------------------------------------
void FpgaDownloadAndGo(int bitstream_version)
{
void *bit_start;
void *bit_end;
z_stream compressed_fpga_stream;
uint8_t output_buffer[OUTPUT_BUFFER_LEN] = {0x00};
// check whether or not the bitstream is already loaded
if (FpgaGatherBitstreamVersion() == bitstream_version)
if (downloaded_bitstream == bitstream_version) {
FpgaEnableTracing();
return;
if (bitstream_version == FPGA_BITSTREAM_LF) {
bit_start = &_binary_fpga_lf_bit_start;
bit_end = &_binary_fpga_lf_bit_end;
} else if (bitstream_version == FPGA_BITSTREAM_HF) {
bit_start = &_binary_fpga_hf_bit_start;
bit_end = &_binary_fpga_hf_bit_end;
} else
return;
/* Check for the new flash image format: Should have the .bit file at &_binary_fpga_bit_start
*/
if(bitparse_init(bit_start, bit_end)) {
/* Successfully initialized the .bit parser. Find the 'e' section and
* send its contents to the FPGA.
*/
char *bitstream_start;
unsigned int bitstream_length;
if(bitparse_find_section('e', &bitstream_start, &bitstream_length)) {
DownloadFPGA(bitstream_start, bitstream_length, 0);
return; /* All done */
}
}
/* Fallback for the old flash image format: Check for the magic marker 0xFFFFFFFF
* 0xAA995566 at address 0x102000. This is raw bitstream with a size of 336,768 bits
* = 10,524 uint32_t, stored as uint32_t e.g. little-endian in memory, but each DWORD
* is still to be transmitted in MSBit first order. Set the invert flag to indicate
* that the DownloadFPGA function should invert every 4 byte sequence when doing
* the bytewise download.
*/
if( *(uint32_t*)0x102000 == 0xFFFFFFFF && *(uint32_t*)0x102004 == 0xAA995566 )
DownloadFPGA((char*)0x102000, 10524*4, 1);
}
// make sure that we have enough memory to decompress
BigBuf_free(); BigBuf_Clear_ext(false);
int FpgaGatherBitstreamVersion()
{
char temp[256];
FpgaGatherVersion(temp, sizeof (temp));
if (!memcmp("LF", temp, 2))
return FPGA_BITSTREAM_LF;
else if (!memcmp("HF", temp, 2))
return FPGA_BITSTREAM_HF;
return FPGA_BITSTREAM_ERR;
}
void FpgaGatherVersion(char *dst, int len)
{
char *fpga_info;
unsigned int fpga_info_len;
dst[0] = 0;
if(!bitparse_find_section('e', &fpga_info, &fpga_info_len)) {
strncat(dst, "FPGA image: legacy image without version information", len-1);
} else {
/* USB packets only have 48 bytes data payload, so be terse */
if(bitparse_find_section('a', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) {
if (!memcmp("fpga_lf", fpga_info, 7))
strncat(dst, "LF ", len-1);
else if (!memcmp("fpga_hf", fpga_info, 7))
strncat(dst, "HF ", len-1);
}
strncat(dst, "FPGA image built", len-1);
#if 0
if(bitparse_find_section('b', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) {
strncat(dst, " for ", len-1);
strncat(dst, fpga_info, len-1);
}
#endif
if(bitparse_find_section('c', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) {
strncat(dst, " on ", len-1);
strncat(dst, fpga_info, len-1);
}
if(bitparse_find_section('d', &fpga_info, &fpga_info_len) && fpga_info[fpga_info_len-1] == 0 ) {
strncat(dst, " at ", len-1);
strncat(dst, fpga_info, len-1);
}
if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer)) {
return;
}
unsigned int bitstream_length;
if (bitparse_find_section(bitstream_version, 'e', &bitstream_length, &compressed_fpga_stream, output_buffer)) {
DownloadFPGA(bitstream_version, bitstream_length, &compressed_fpga_stream, output_buffer);
downloaded_bitstream = bitstream_version;
}
inflateEnd(&compressed_fpga_stream);
// turn off antenna
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
// free eventually allocated BigBuf memory
BigBuf_free(); BigBuf_Clear_ext(false);
}
//-----------------------------------------------------------------------------
// Send a 16 bit command/data pair to the FPGA.
// The bit format is: C3 C2 C1 C0 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
// where C is the 4 bit command and D is the 12 bit data
//-----------------------------------------------------------------------------
void FpgaSendCommand(uint16_t cmd, uint16_t v)
{
void FpgaSendCommand(uint16_t cmd, uint16_t v) {
SetupSpi(SPI_FPGA_MODE);
while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); // wait for the transfer to complete
AT91C_BASE_SPI->SPI_TDR = AT91C_SPI_LASTXFER | cmd | v; // send the data
AT91C_BASE_SPI->SPI_TDR = AT91C_SPI_LASTXFER | cmd | v; // write the data to be sent
while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); // wait for the transfer to complete
}
//-----------------------------------------------------------------------------
// Write the FPGA setup word (that determines what mode the logic is in, read
// vs. clone vs. etc.). This is now a special case of FpgaSendCommand() to
// avoid changing this function's occurence everywhere in the source code.
//-----------------------------------------------------------------------------
void FpgaWriteConfWord(uint8_t v)
{
void FpgaWriteConfWord(uint16_t v) {
FpgaSendCommand(FPGA_CMD_SET_CONFREG, v);
}
//-----------------------------------------------------------------------------
// enable/disable FPGA internal tracing
//-----------------------------------------------------------------------------
void FpgaEnableTracing(void) {
FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 1);
}
void FpgaDisableTracing(void) {
FpgaSendCommand(FPGA_CMD_TRACE_ENABLE, 0);
}
//-----------------------------------------------------------------------------
// Set up the CMOS switches that mux the ADC: four switches, independently
// closable, but should only close one at a time. Not an FPGA thing, but
@ -458,3 +500,12 @@ void SetAdcMuxFor(uint32_t whichGpio)
HIGH(whichGpio);
}
void Fpga_print_status(void) {
Dbprintf("Currently loaded FPGA image:");
Dbprintf(" %s", fpga_version_information[downloaded_bitstream-1]);
}
int FpgaGetCurrent() {
return downloaded_bitstream;
}

99
armsrc/fpgaloader.h Normal file
View file

@ -0,0 +1,99 @@
//-----------------------------------------------------------------------------
// Jonathan Westhues, April 2006
// iZsh <izsh at fail0verflow.com>, 2014
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Routines to load the FPGA image, and then to configure the FPGA's major
// mode once it is configured.
//-----------------------------------------------------------------------------
#ifndef __FPGALOADER_H
#define __FPGALOADER_H
#include <stdint.h>
#include <stdbool.h>
void FpgaSendCommand(uint16_t cmd, uint16_t v);
void FpgaWriteConfWord(uint16_t v);
void FpgaDownloadAndGo(int bitstream_version);
void FpgaSetupSsc(uint16_t mode);
void SetupSpi(int mode);
bool FpgaSetupSscDma(uint8_t *buf, uint16_t sample_count);
void Fpga_print_status();
int FpgaGetCurrent();
void FpgaEnableTracing(void);
void FpgaDisableTracing(void);
#define FpgaDisableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
#define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
void SetAdcMuxFor(uint32_t whichGpio);
// definitions for multiple FPGA config files support
#define FPGA_BITSTREAM_LF 1
#define FPGA_BITSTREAM_HF 2
// Definitions for the FPGA commands.
#define FPGA_CMD_MASK 0xF000
// BOTH
#define FPGA_CMD_SET_CONFREG (1<<12)
// LF
#define FPGA_CMD_SET_DIVISOR (2<<12)
#define FPGA_CMD_SET_EDGE_DETECT_THRESHOLD (3<<12)
// HF
#define FPGA_CMD_TRACE_ENABLE (2<<12)
// Definitions for the FPGA configuration word.
#define FPGA_MAJOR_MODE_MASK 0x01C0
// LF
#define FPGA_MAJOR_MODE_LF_ADC (0<<6)
#define FPGA_MAJOR_MODE_LF_EDGE_DETECT (1<<6)
#define FPGA_MAJOR_MODE_LF_PASSTHRU (2<<6)
// HF
#define FPGA_MAJOR_MODE_HF_READER (0<<6)
#define FPGA_MAJOR_MODE_HF_SIMULATOR (1<<6)
#define FPGA_MAJOR_MODE_HF_ISO14443A (2<<6)
#define FPGA_MAJOR_MODE_HF_SNOOP (3<<6)
#define FPGA_MAJOR_MODE_HF_GET_TRACE (4<<6)
// BOTH
#define FPGA_MAJOR_MODE_OFF (7<<6)
#define FPGA_MINOR_MODE_MASK 0x003F
// Options for LF_ADC
#define FPGA_LF_ADC_READER_FIELD (1<<0)
// Options for LF_EDGE_DETECT
#define FPGA_LF_EDGE_DETECT_READER_FIELD (1<<0)
#define FPGA_LF_EDGE_DETECT_TOGGLE_MODE (2<<0)
// Options for the HF reader
#define FPGA_HF_READER_MODE_RECEIVE_IQ (0<<0)
#define FPGA_HF_READER_MODE_RECEIVE_AMPLITUDE (1<<0)
#define FPGA_HF_READER_MODE_RECEIVE_PHASE (2<<0)
#define FPGA_HF_READER_MODE_SEND_FULL_MOD (3<<0)
#define FPGA_HF_READER_MODE_SEND_SHALLOW_MOD (4<<0)
#define FPGA_HF_READER_MODE_SNOOP_IQ (5<<0)
#define FPGA_HF_READER_MODE_SNOOP_AMPLITUDE (6<<0)
#define FPGA_HF_READER_MODE_SNOOP_PHASE (7<<0)
#define FPGA_HF_READER_MODE_SEND_JAM (8<<0)
#define FPGA_HF_READER_SUBCARRIER_848_KHZ (0<<4)
#define FPGA_HF_READER_SUBCARRIER_424_KHZ (1<<4)
#define FPGA_HF_READER_SUBCARRIER_212_KHZ (2<<4)
// Options for the HF simulated tag, how to modulate
#define FPGA_HF_SIMULATOR_NO_MODULATION (0<<0)
#define FPGA_HF_SIMULATOR_MODULATE_BPSK (1<<0)
#define FPGA_HF_SIMULATOR_MODULATE_212K (2<<0)
#define FPGA_HF_SIMULATOR_MODULATE_424K (4<<0)
#define FPGA_HF_SIMULATOR_MODULATE_424K_8BIT 0x5//101
// Options for ISO14443A
#define FPGA_HF_ISO14443A_SNIFFER (0<<0)
#define FPGA_HF_ISO14443A_TAGSIM_LISTEN (1<<0)
#define FPGA_HF_ISO14443A_TAGSIM_MOD (2<<0)
#define FPGA_HF_ISO14443A_READER_LISTEN (3<<0)
#define FPGA_HF_ISO14443A_READER_MOD (4<<0)
#endif

118
armsrc/hfsnoop.c Normal file
View file

@ -0,0 +1,118 @@
//-----------------------------------------------------------------------------
// piwi, 2019
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Routines to get sample data from FPGA.
//-----------------------------------------------------------------------------
#include "hfsnoop.h"
#include "proxmark3.h"
#include "BigBuf.h"
#include "util.h"
#include "apps.h"
#include "usb_cdc.h"
#include "fpga.h"
#include "fpgaloader.h"
static void RAMFUNC optimizedSnoop(void)
{
int n = BigBuf_max_traceLen() / sizeof(uint16_t); // take all memory
uint16_t *dest = (uint16_t *)BigBuf_get_addr();
uint16_t *destend = dest + n;
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16); // Setting Frame mode, 16 bits per word
// Reading data loop
while(dest <= destend)
{
if(AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY)
{
*dest = (uint16_t)(AT91C_BASE_SSC->SSC_RHR);
dest++;
}
}
//Resetting Frame mode (First set in fpgaloader.c)
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
}
void HfSnoop(int samplesToSkip, int triggersToSkip)
{
BigBuf_free(); BigBuf_Clear();
Dbprintf("Skipping first %d sample pairs, Skipping %d triggers.\n", samplesToSkip, triggersToSkip);
int trigger_cnt;
LED_D_ON();
// Select correct configs
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
// Set up the synchronous serial port
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SNOOP);
// connect Demodulated Signal to ADC:
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SNOOP);
SpinDelay(100);
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16); // Setting Frame Mode For better performance on high speed data transfer.
trigger_cnt = 0;
uint16_t r = 0;
while(!BUTTON_PRESS() && !usb_poll_validate_length()) {
WDT_HIT();
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
r = (uint16_t)AT91C_BASE_SSC->SSC_RHR;
r = MAX(r & 0xff, r >> 8);
if (r >= 240) {
if (++trigger_cnt > triggersToSkip)
break;
}
}
}
if(!BUTTON_PRESS()) {
int waitcount = samplesToSkip; // lets wait 40000 ticks of pck0
while(waitcount != 0) {
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY))
waitcount--;
}
optimizedSnoop();
Dbprintf("Trigger kicked! Value: %d, Dumping Samples Hispeed now.", r);
}
DbpString("HF Snoop end");
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LED_D_OFF();
}
void HfPlot(void)
{
uint8_t *buf = ToSend;
uint8_t *this_buf = buf;
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_GET_TRACE);
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS; // Disable DMA Transfer
AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) this_buf; // start transfer to this memory address
AT91C_BASE_PDC_SSC->PDC_RCR = USB_CMD_DATA_SIZE; // transfer this many samples
buf[0] = (uint8_t)AT91C_BASE_SSC->SSC_RHR; // clear receive register
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN; // Start DMA transfer
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_GET_TRACE); // let FPGA transfer its internal Block-RAM
LED_B_ON();
for(size_t i = 0; i < FPGA_TRACE_SIZE; i += USB_CMD_DATA_SIZE) {
// prepare next DMA transfer:
uint8_t *next_buf = buf + ((i + USB_CMD_DATA_SIZE) % (2 * USB_CMD_DATA_SIZE));
AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t)next_buf;
AT91C_BASE_PDC_SSC->PDC_RNCR = USB_CMD_DATA_SIZE;
size_t len = MIN(FPGA_TRACE_SIZE - i, USB_CMD_DATA_SIZE);
while (!(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_ENDRX))) ; // wait for DMA transfer to complete
cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, i, len, FPGA_TRACE_SIZE, this_buf, len);
this_buf = next_buf;
}
// Trigger a finish downloading signal with an ACK frame
cmd_send(CMD_ACK, 1, 0, FPGA_TRACE_SIZE, 0, 0);
LED_B_OFF();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
}

17
armsrc/hfsnoop.h Normal file
View file

@ -0,0 +1,17 @@
//-----------------------------------------------------------------------------
// piwi, 2019
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Routines to get sample data from FPGA.
//-----------------------------------------------------------------------------
#ifndef HFSNOOP_H__
#define HFSNOOP_H__
void HfSnoop(int samplesToSkip, int triggersToSkip);
void HfPlot(void);
#endif

File diff suppressed because it is too large Load diff

24
armsrc/hitag2.h Normal file
View file

@ -0,0 +1,24 @@
//-----------------------------------------------------------------------------
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Hitag2 emulation
//
// (c) 2009 Henryk Plötz <henryk@ploetzli.ch>
// (c) 2012 Roel Verdult
//-----------------------------------------------------------------------------
#ifndef HITAG2_H__
#define HITAG2_H__
#include <stdint.h>
#include <stdbool.h>
#include "hitag.h"
extern void SnoopHitag(uint32_t type);
extern void SimulateHitagTag(bool tag_mem_supplied, uint8_t* data);
extern void ReaderHitag(hitag_function htf, hitag_data* htd);
extern void WriterHitag(hitag_function htf, hitag_data* htd, int page);
#endif

2432
armsrc/hitagS.c Normal file

File diff suppressed because it is too large Load diff

26
armsrc/hitagS.h Normal file
View file

@ -0,0 +1,26 @@
//-----------------------------------------------------------------------------
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// HitagS emulation (preliminary test version)
//
// (c) 2016 Oguzhan Cicek, Hendrik Schwartke, Ralf Spenneberg
// <info@os-s.de>
//-----------------------------------------------------------------------------
// Some code was copied from Hitag2.c
//-----------------------------------------------------------------------------
#ifndef HITAGS_H__
#define HITAGS_H__
#include <stdint.h>
#include <stdbool.h>
#include "hitag.h"
void ReadHitagSCmd(hitag_function htf, hitag_data* htd, uint64_t startPage, uint64_t tagMode, bool readBlock);
void SimulateHitagSTag(bool tag_mem_supplied, uint8_t* data);
void WritePageHitagS(hitag_function htf, hitag_data* htd, int page);
void check_challenges_cmd(bool file_given, uint8_t* data, uint64_t tagMode);
#endif

811
armsrc/i2c.c Normal file
View file

@ -0,0 +1,811 @@
//-----------------------------------------------------------------------------
// Willok, June 2018
// Edits by Iceman, July 2018
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// The main i2c code, for communications with smart card module
//-----------------------------------------------------------------------------
#include "i2c.h"
#include <stdint.h>
#include <stdbool.h>
#include "string.h" //for memset memcmp
#include "proxmark3.h"
#include "mifareutil.h" // for MF_DBGLEVEL
#include "BigBuf.h"
#include "apps.h"
#include "usb_cdc.h"
#include "util.h"
#ifdef WITH_SMARTCARD
#include "smartcard.h"
#endif
#define GPIO_RST AT91C_PIO_PA1
#define GPIO_SCL AT91C_PIO_PA5
#define GPIO_SDA AT91C_PIO_PA7
#define SCL_H HIGH(GPIO_SCL)
#define SCL_L LOW(GPIO_SCL)
#define SDA_H HIGH(GPIO_SDA)
#define SDA_L LOW(GPIO_SDA)
#define SCL_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SCL)
#define SDA_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SDA)
#define I2C_ERROR "I2C_WaitAck Error"
static volatile unsigned long c;
// 直接使用循环来延时,一个循环 6 条指令48M Delay=1 大概为 200kbps
// timer.
// I2CSpinDelayClk(4) = 12.31us
// I2CSpinDelayClk(1) = 3.07us
static void __attribute__((optimize("O0"))) I2CSpinDelayClk(uint16_t delay) {
for (c = delay * 2; c; c--) {};
}
// communication delay functions
#define I2C_DELAY_1CLK I2CSpinDelayClk(1)
#define I2C_DELAY_2CLK I2CSpinDelayClk(2)
#define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
#define ISO7618_MAX_FRAME 255
// try i2c bus recovery at 100kHz = 5uS high, 5uS low
static void I2C_recovery(void) {
DbpString("Performing i2c bus recovery");
// reset I2C
SDA_H; SCL_H;
//9nth cycle acts as NACK
for (int i = 0; i < 10; i++) {
SCL_H; WaitUS(5);
SCL_L; WaitUS(5);
}
//a STOP signal (SDA from low to high while CLK is high)
SDA_L; WaitUS(5);
SCL_H; WaitUS(2);
SDA_H; WaitUS(2);
bool isok = (SCL_read && SDA_read);
if (!SDA_read)
DbpString("I2C bus recovery error: SDA still LOW");
if (!SCL_read)
DbpString("I2C bus recovery error: SCL still LOW");
if (isok)
DbpString("I2C bus recovery complete");
}
static void I2C_init(void) {
// Configure reset pin
AT91C_BASE_PIOA->PIO_PPUDR = GPIO_RST; // disable pull up resistor
AT91C_BASE_PIOA->PIO_MDDR = GPIO_RST; // push-pull output (multidriver disabled)
// Configure SCL and SDA pins
AT91C_BASE_PIOA->PIO_PPUER |= (GPIO_SCL | GPIO_SDA); // enable pull up resistor
AT91C_BASE_PIOA->PIO_MDER |= (GPIO_SCL | GPIO_SDA); // open drain output (multidriver enabled) - requires external pull up resistor
// set all three outputs to high
AT91C_BASE_PIOA->PIO_SODR |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
// configure all three pins as output, controlled by PIOA
AT91C_BASE_PIOA->PIO_OER |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
AT91C_BASE_PIOA->PIO_PER |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
bool isok = (SCL_read && SDA_read);
if ( !isok )
I2C_recovery();
}
// set the reset state
static void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA) {
if (LineRST)
HIGH(GPIO_RST);
else
LOW(GPIO_RST);
if (LineSCK)
HIGH(GPIO_SCL);
else
LOW(GPIO_SCL);
if (LineSDA)
HIGH(GPIO_SDA);
else
LOW(GPIO_SDA);
}
// Reset the SIM_Adapter, then enter the main program
// Note: the SIM_Adapter will not enter the main program after power up. Please run this function before use SIM_Adapter.
static void I2C_Reset_EnterMainProgram(void) {
StartTicks();
I2C_init();
I2C_SetResetStatus(0, 0, 0);
WaitMS(30);
I2C_SetResetStatus(1, 0, 0);
WaitMS(30);
I2C_SetResetStatus(1, 1, 1);
WaitMS(10);
}
// Wait for the clock to go High.
static bool WaitSCL_H_delay(uint32_t delay) {
while (delay--) {
if (SCL_read) {
return true;
}
I2C_DELAY_1CLK;
}
return false;
}
// 15000 * 3.07us = 46050us. 46.05ms
static bool WaitSCL_H(void) {
return WaitSCL_H_delay(15000);
}
bool WaitSCL_L_delay(uint32_t delay) {
while (delay--) {
if (!SCL_read) {
return true;
}
I2C_DELAY_1CLK;
}
return false;
}
bool WaitSCL_L(void) {
return WaitSCL_L_delay(15000);
}
static bool I2C_Start(void) {
I2C_DELAY_XCLK(4);
SDA_H; I2C_DELAY_1CLK;
SCL_H;
if (!WaitSCL_H()) return false;
I2C_DELAY_2CLK;
if (!SCL_read) return false;
if (!SDA_read) return false;
SDA_L; I2C_DELAY_2CLK;
return true;
}
// send i2c STOP
static void I2C_Stop(void) {
SCL_L; I2C_DELAY_2CLK;
SDA_L; I2C_DELAY_2CLK;
SCL_H; I2C_DELAY_2CLK;
if (!WaitSCL_H()) return;
SDA_H;
I2C_DELAY_XCLK(8);
}
static bool I2C_WaitAck(void) {
SCL_L; I2C_DELAY_1CLK;
SDA_H; I2C_DELAY_1CLK;
SCL_H;
if (!WaitSCL_H())
return false;
I2C_DELAY_2CLK;
I2C_DELAY_2CLK;
if (SDA_read) {
SCL_L;
return false;
}
SCL_L;
return true;
}
static void I2C_SendByte(uint8_t data) {
uint8_t bits = 8;
while (bits--) {
SCL_L;
I2C_DELAY_1CLK;
if (data & 0x80)
SDA_H;
else
SDA_L;
data <<= 1;
I2C_DELAY_1CLK;
SCL_H;
if (!WaitSCL_H())
return;
I2C_DELAY_2CLK;
}
SCL_L;
}
bool I2C_is_available(void) {
I2C_Reset_EnterMainProgram();
if (!I2C_Start()) // some other device is active on the bus
return true;
I2C_SendByte(I2C_DEVICE_ADDRESS_MAIN & 0xFE);
if (!I2C_WaitAck()) { // no response from smartcard reader
I2C_Stop();
return false;
}
I2C_Stop();
return true;
}
#ifdef WITH_SMARTCARD
// Reset the SIM_Adapter, then enter the bootloader program
// ReserveFor firmware update.
static void I2C_Reset_EnterBootloader(void) {
I2C_SetResetStatus(0, 1, 1);
WaitMS(100);
I2C_SetResetStatus(1, 1, 1);
WaitMS(10);
}
// Wait max 1800ms or until SCL goes LOW.
// It timeout reading response from card
// Which ever comes first
bool WaitSCL_L_timeout(void){
volatile uint16_t delay = 1800;
while ( delay-- ) {
// exit on SCL LOW
if (!SCL_read)
return true;
WaitMS(1);
}
return (delay == 0);
}
static bool I2C_WaitForSim() {
// wait for data from card
if (!WaitSCL_L_timeout())
return false;
// 8051 speaks with smart card.
// 1000*50*3.07 = 153.5ms
// 1byte transfer == 1ms with max frame being 256bytes
if (!WaitSCL_H_delay(10 * 1000 * 50))
return false;
return true;
}
// Send i2c ACK
static void I2C_Ack(void) {
SCL_L; I2C_DELAY_2CLK;
SDA_L; I2C_DELAY_2CLK;
SCL_H; I2C_DELAY_2CLK;
if (!WaitSCL_H()) return;
SCL_L; I2C_DELAY_2CLK;
}
// Send i2c NACK
static void I2C_NoAck(void) {
SCL_L; I2C_DELAY_2CLK;
SDA_H; I2C_DELAY_2CLK;
SCL_H; I2C_DELAY_2CLK;
if (!WaitSCL_H()) return;
SCL_L; I2C_DELAY_2CLK;
}
static int16_t I2C_ReadByte(void) {
uint8_t bits = 8, b = 0;
SDA_H;
while (bits--) {
b <<= 1;
SCL_L;
if (!WaitSCL_L()) return -2;
I2C_DELAY_1CLK;
SCL_H;
if (!WaitSCL_H()) return -1;
I2C_DELAY_1CLK;
if (SDA_read)
b |= 0x01;
}
SCL_L;
return b;
}
// Sends one byte ( command to be written, SlaveDevice address)
static bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) {
bool bBreak = true;
do {
if (!I2C_Start())
return false;
I2C_SendByte(device_address & 0xFE);
if (!I2C_WaitAck())
break;
I2C_SendByte(device_cmd);
if (!I2C_WaitAck())
break;
bBreak = false;
} while (false);
I2C_Stop();
if (bBreak) {
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
return false;
}
return true;
}
// Sends 1 byte data (Data to be written, command to be written , SlaveDevice address ).
static bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address) {
bool bBreak = true;
do {
if (!I2C_Start())
return false;
I2C_SendByte(device_address & 0xFE);
if (!I2C_WaitAck())
break;
I2C_SendByte(device_cmd);
if (!I2C_WaitAck())
break;
I2C_SendByte(data);
if (!I2C_WaitAck())
break;
bBreak = false;
} while (false);
I2C_Stop();
if (bBreak) {
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
return false;
}
return true;
}
//Sends a string of data (Array, length, command to be written , SlaveDevice address ).
// len = uint8 (max buffer to write 256bytes)
static bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address) {
bool bBreak = true;
do {
if (!I2C_Start())
return false;
I2C_SendByte(device_address & 0xFE);
if (!I2C_WaitAck())
break;
I2C_SendByte(device_cmd);
if (!I2C_WaitAck())
break;
while (len) {
I2C_SendByte(*data);
if (!I2C_WaitAck())
break;
len--;
data++;
}
if (len == 0)
bBreak = false;
} while (false);
I2C_Stop();
if (bBreak) {
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
return false;
}
return true;
}
// read 1 strings of data (Data array, Readout length, command to be written , SlaveDevice address ).
// len = uint8 (max buffer to read 256bytes)
static int16_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t device_address) {
if ( !data || len == 0 )
return 0;
// extra wait 500us (514us measured)
// 200us (xx measured)
WaitUS(600);
bool bBreak = true;
uint16_t readcount = 0;
do {
if (!I2C_Start())
return 0;
// 0xB0 / 0xC0 == i2c write
I2C_SendByte(device_address & 0xFE);
if (!I2C_WaitAck())
break;
I2C_SendByte(device_cmd);
if (!I2C_WaitAck())
break;
// 0xB1 / 0xC1 == i2c read
I2C_Start();
I2C_SendByte(device_address | 1);
if (!I2C_WaitAck())
break;
bBreak = false;
} while (false);
if (bBreak) {
I2C_Stop();
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
return 0;
}
while (len) {
int16_t tmp = I2C_ReadByte();
if ( tmp < 0 )
return tmp;
*data = (uint8_t)tmp & 0xFF;
len--;
// 读取的第一个字节为后续长度
// The first byte in response is the message length
if (!readcount && (len > *data)) {
len = *data;
} else {
data++;
}
readcount++;
// acknowledgements. After last byte send NACK.
if (len == 0)
I2C_NoAck();
else
I2C_Ack();
}
I2C_Stop();
// return bytecount - first byte (which is length byte)
return --readcount;
}
static int16_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address) {
//START, 0xB0, 0x00, 0x00, START, 0xB1, xx, yy, zz, ......, STOP
bool bBreak = true;
uint8_t readcount = 0;
// sending
do {
if (!I2C_Start())
return 0;
// 0xB0 / 0xC0 i2c write
I2C_SendByte(device_address & 0xFE);
if (!I2C_WaitAck())
break;
I2C_SendByte(msb);
if (!I2C_WaitAck())
break;
I2C_SendByte(lsb);
if (!I2C_WaitAck())
break;
// 0xB1 / 0xC1 i2c read
I2C_Start();
I2C_SendByte(device_address | 1);
if (!I2C_WaitAck())
break;
bBreak = false;
} while (false);
if (bBreak) {
I2C_Stop();
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
return 0;
}
// reading
while (len) {
int16_t tmp = I2C_ReadByte();
if ( tmp < 0 )
return tmp;
*data = (uint8_t)tmp & 0xFF;
data++;
readcount++;
len--;
// acknowledgements. After last byte send NACK.
if (len == 0)
I2C_NoAck();
else
I2C_Ack();
}
I2C_Stop();
return readcount;
}
static bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address) {
//START, 0xB0, 0x00, 0x00, xx, yy, zz, ......, STOP
bool bBreak = true;
do {
if (!I2C_Start())
return false;
// 0xB0 == i2c write
I2C_SendByte(device_address & 0xFE);
if (!I2C_WaitAck())
break;
I2C_SendByte(msb);
if (!I2C_WaitAck())
break;
I2C_SendByte(lsb);
if (!I2C_WaitAck())
break;
while (len) {
I2C_SendByte(*data);
if (!I2C_WaitAck())
break;
len--;
data++;
}
if (len == 0)
bBreak = false;
} while (false);
I2C_Stop();
if (bBreak) {
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
return false;
}
return true;
}
void I2C_print_status(void) {
DbpString("Smart card module (ISO 7816)");
uint8_t resp[] = {0,0,0,0};
I2C_Reset_EnterMainProgram();
uint8_t len = I2C_BufferRead(resp, sizeof(resp), I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN);
if ( len > 0 )
Dbprintf(" version.................v%x.%02x", resp[0], resp[1]);
else
DbpString(" version.................FAILED");
}
// Will read response from smart card module, retries 3 times to get the data.
static bool sc_rx_bytes(uint8_t* dest, uint8_t *destlen) {
uint8_t i = 3;
int16_t len = 0;
while (i--) {
I2C_WaitForSim();
len = I2C_BufferRead(dest, *destlen, I2C_DEVICE_CMD_READ, I2C_DEVICE_ADDRESS_MAIN);
if ( len > 1 ){
break;
} else if ( len == 1 ) {
continue;
} else if ( len <= 0 ) {
return false;
}
}
// after three
if ( len <= 1 )
return false;
*destlen = (uint8_t)len & 0xFF;
return true;
}
static bool GetATR(smart_card_atr_t *card_ptr) {
if ( !card_ptr ) {
return false;
}
card_ptr->atr_len = 0;
memset(card_ptr->atr, 0, sizeof(card_ptr->atr));
// Send ATR
// start [C0 01] stop start C1 len aa bb cc stop]
I2C_WriteCmd(I2C_DEVICE_CMD_GENERATE_ATR, I2C_DEVICE_ADDRESS_MAIN);
// wait for sim card to answer.
// 1byte = 1ms, max frame 256bytes. Should wait 256ms at least just in case.
if (!I2C_WaitForSim())
return false;
// read bytes from module
uint8_t len = sizeof(card_ptr->atr);
if ( !sc_rx_bytes(card_ptr->atr, &len) )
return false;
card_ptr->atr_len = len;
LogTrace(card_ptr->atr, card_ptr->atr_len, 0, 0, NULL, false);
return true;
}
void SmartCardAtr(void) {
smart_card_atr_t card;
LED_D_ON();
clear_trace();
set_tracing(true);
I2C_Reset_EnterMainProgram();
bool isOK = GetATR( &card );
cmd_send(CMD_ACK, isOK, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
set_tracing(false);
LEDsoff();
}
void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) {
LED_D_ON();
uint8_t len = 0;
uint8_t *resp = BigBuf_malloc(ISO7618_MAX_FRAME);
smartcard_command_t flags = arg0;
if ((flags & SC_CONNECT))
clear_trace();
set_tracing(true);
if ((flags & SC_CONNECT)) {
I2C_Reset_EnterMainProgram();
if ((flags & SC_SELECT)) {
smart_card_atr_t card;
bool gotATR = GetATR( &card );
//cmd_send(CMD_ACK, gotATR, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
if ( !gotATR )
goto OUT;
}
}
if ((flags & SC_RAW) || (flags & SC_RAW_T0)) {
LogTrace(data, arg1, 0, 0, NULL, true);
// Send raw bytes
// asBytes = A0 A4 00 00 02
// arg1 = len 5
bool res = I2C_BufferWrite(data, arg1, ((flags & SC_RAW_T0) ? I2C_DEVICE_CMD_SEND_T0 : I2C_DEVICE_CMD_SEND), I2C_DEVICE_ADDRESS_MAIN);
if ( !res && MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
// read bytes from module
len = ISO7618_MAX_FRAME;
res = sc_rx_bytes(resp, &len);
if ( res ) {
LogTrace(resp, len, 0, 0, NULL, false);
} else {
len = 0;
}
}
OUT:
cmd_send(CMD_ACK, len, 0, 0, resp, len);
BigBuf_free();
set_tracing(false);
LEDsoff();
}
void SmartCardUpgrade(uint64_t arg0) {
LED_C_ON();
#define I2C_BLOCK_SIZE 128
// write. Sector0, with 11,22,33,44
// erase is 128bytes, and takes 50ms to execute
I2C_Reset_EnterBootloader();
bool isOK = true;
int16_t res = 0;
uint16_t length = arg0;
uint16_t pos = 0;
uint8_t *fwdata = BigBuf_get_addr();
uint8_t *verfiydata = BigBuf_malloc(I2C_BLOCK_SIZE);
while (length) {
uint8_t msb = (pos >> 8) & 0xFF;
uint8_t lsb = pos & 0xFF;
Dbprintf("FW %02X%02X", msb, lsb);
size_t size = MIN(I2C_BLOCK_SIZE, length);
// write
res = I2C_WriteFW(fwdata+pos, size, msb, lsb, I2C_DEVICE_ADDRESS_BOOT);
if ( !res ) {
DbpString("Writing failed");
isOK = false;
break;
}
// writing takes time.
WaitMS(50);
// read
res = I2C_ReadFW(verfiydata, size, msb, lsb, I2C_DEVICE_ADDRESS_BOOT);
if ( res <= 0) {
DbpString("Reading back failed");
isOK = false;
break;
}
// cmp
if ( 0 != memcmp(fwdata+pos, verfiydata, size)) {
DbpString("not equal data");
isOK = false;
break;
}
length -= size;
pos += size;
}
cmd_send(CMD_ACK, isOK, pos, 0, 0, 0);
LED_C_OFF();
BigBuf_free();
}
// unfinished (or not needed?)
//void SmartCardSetBaud(uint64_t arg0) {
//}
void SmartCardSetClock(uint64_t arg0) {
LED_D_ON();
set_tracing(true);
I2C_Reset_EnterMainProgram();
// Send SIM CLC
// start [C0 05 xx] stop
I2C_WriteByte(arg0, I2C_DEVICE_CMD_SIM_CLC, I2C_DEVICE_ADDRESS_MAIN);
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
set_tracing(false);
LEDsoff();
}
#endif

39
armsrc/i2c.h Normal file
View file

@ -0,0 +1,39 @@
//-----------------------------------------------------------------------------
// Willok, June 2018
// Edits by Iceman, July 2018
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// The main i2c code, for communications with smart card module
//-----------------------------------------------------------------------------
#ifndef __I2C_H
#define __I2C_H
#include <stdint.h>
#include <stdbool.h>
#define I2C_DEVICE_ADDRESS_BOOT 0xB0
#define I2C_DEVICE_ADDRESS_MAIN 0xC0
#define I2C_DEVICE_CMD_GENERATE_ATR 0x01
#define I2C_DEVICE_CMD_SEND 0x02
#define I2C_DEVICE_CMD_READ 0x03
#define I2C_DEVICE_CMD_SETBAUD 0x04
#define I2C_DEVICE_CMD_SIM_CLC 0x05
#define I2C_DEVICE_CMD_GETVERSION 0x06
#define I2C_DEVICE_CMD_SEND_T0 0x07
bool I2C_is_available(void);
#ifdef WITH_SMARTCARD
void SmartCardAtr(void);
void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data);
void SmartCardUpgrade(uint64_t arg0);
void SmartCardSetClock(uint64_t arg0);
void I2C_print_status(void);
#endif
#endif // __I2C_H

File diff suppressed because it is too large Load diff

32
armsrc/iclass.h Normal file
View file

@ -0,0 +1,32 @@
//-----------------------------------------------------------------------------
// Gerhard de Koning Gans - May 2008
// Hagen Fritsch - June 2010
// Gerhard de Koning Gans - May 2011
// Gerhard de Koning Gans - June 2012 - Added iClass card and reader emulation
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Routines to support iClass.
//-----------------------------------------------------------------------------
#ifndef ICLASS_H__
#define ICLASS_H__
#include <stdint.h>
#include <stdbool.h>
extern void SnoopIClass(uint8_t jam_search_len, uint8_t *jam_search_string);
extern void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
extern void ReaderIClass(uint8_t arg0);
extern void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC);
extern void IClass_iso14443A_GetPublic(uint8_t arg0);
extern void iClass_Readcheck(uint8_t block, bool use_credit_key);
extern void iClass_Check(uint8_t *MAC);
extern void iClass_WriteBlock(uint8_t blockNo, uint8_t *data);
extern void iClass_ReadBlk(uint8_t blockNo);
extern void iClass_Dump(uint8_t blockno, uint8_t numblks);
extern void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data);
#endif

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -12,86 +12,46 @@
#ifndef __ISO14443A_H
#define __ISO14443A_H
#include "common.h"
#include "mifaresniff.h"
// mifare reader over DMA buffer (SnoopIso14443a())!!!
#define MIFARE_BUFF_OFFSET 3560 // \/ \/ \/
// card emulator memory
#define EML_RESPONSES 4000
#define CARD_MEMORY 6000
#define CARD_MEMORY_LEN 4096
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "usb_cmd.h"
#include "mifare.h"
typedef struct {
enum {
DEMOD_UNSYNCD,
// DEMOD_HALF_SYNCD,
// DEMOD_MOD_FIRST_HALF,
// DEMOD_NOMOD_FIRST_HALF,
DEMOD_MANCHESTER_DATA
} state;
uint16_t twoBits;
uint16_t highCnt;
uint16_t bitCount;
uint16_t collisionPos;
uint16_t syncBit;
uint32_t parityBits;
uint16_t shiftReg;
uint16_t samples;
uint16_t len;
uint32_t startTime, endTime;
uint8_t *output;
} tDemod;
uint8_t* response;
uint8_t* modulation;
uint16_t response_n;
uint16_t modulation_n;
uint32_t ProxToAirDuration;
uint8_t par; // enough for precalculated parity of 8 Byte responses
} tag_response_info_t;
typedef enum {
MOD_NOMOD = 0,
MOD_SECOND_HALF,
MOD_FIRST_HALF,
MOD_BOTH_HALVES
} Modulation_t;
typedef struct {
enum {
STATE_UNSYNCD,
STATE_START_OF_COMMUNICATION,
STATE_MILLER_X,
STATE_MILLER_Y,
STATE_MILLER_Z,
// DROP_NONE,
// DROP_FIRST_HALF,
} state;
uint16_t shiftReg;
uint16_t bitCount;
uint16_t len;
uint16_t byteCntMax;
uint16_t posCnt;
uint16_t syncBit;
uint32_t parityBits;
uint16_t highCnt;
uint16_t twoBits;
uint32_t startTime, endTime;
uint8_t *output;
} tUart;
extern byte_t oddparity (const byte_t bt);
extern uint32_t GetParity(const uint8_t *pbtCmd, int iLen);
extern void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par);
extern void AppendCrc14443a(uint8_t *data, int len);
extern void ReaderTransmit(uint8_t *frame, int len, uint32_t *timing);
extern void ReaderTransmitBitsPar(uint8_t *frame, int bits, uint32_t par, uint32_t *timing);
extern void ReaderTransmitPar(uint8_t *frame, int len, uint32_t par, uint32_t *timing);
extern int ReaderReceive(uint8_t *receivedAnswer);
extern int ReaderReceivePar(uint8_t *receivedAnswer, uint32_t *parptr);
extern void RAMFUNC SnoopIso14443a(uint8_t param);
extern void SimulateIso14443aTag(int tagType, int uid_1st, int uid_2nd, uint8_t *data);
extern void ReaderIso14443a(UsbCommand *c);
extern void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing);
extern void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing);
extern void ReaderTransmitPar(uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing);
extern int ReaderReceive(uint8_t *receivedAnswer, uint8_t *par);
extern void ReaderMifare(bool first_try);
extern int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *parity);
extern int EmSendCmd(uint8_t *resp, uint16_t respLen);
extern int EmSend4bit(uint8_t resp);
extern int EmSendCmdPar(uint8_t *resp, uint16_t respLen, uint8_t *par);
extern int EmSendPrecompiledCmd(tag_response_info_t *response_info);
extern bool prepare_allocated_tag_modulation(tag_response_info_t *response_info, uint8_t **buffer, size_t *buffer_size);
extern void iso14443a_setup(uint8_t fpga_minor_mode);
extern int iso14_apdu(uint8_t *cmd, size_t cmd_len, void *data);
extern int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *resp_data, uint32_t *cuid_ptr);
extern int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, uint8_t *res);
extern int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *resp_data, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades, bool no_rats);
extern void iso14a_set_trigger(bool enable);
extern void iso14a_set_timeout(uint32_t timeout);
extern void iso14a_clear_tracelen();
extern void iso14a_set_tracing(bool enable);
extern uint32_t iso14a_get_timeout(void);
#endif /* __ISO14443A_H */

1292
armsrc/iso14443b.c Normal file

File diff suppressed because it is too large Load diff

27
armsrc/iso14443b.h Normal file
View file

@ -0,0 +1,27 @@
//-----------------------------------------------------------------------------
// Merlok - June 2011
// Gerhard de Koning Gans - May 2008
// Hagen Fritsch - June 2010
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Routines to support ISO 14443 type B.
//-----------------------------------------------------------------------------
#ifndef ISO14443B_H__
#define ISO14443B_H__
#include <stdint.h>
#include <stddef.h>
extern int iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *response);
extern void iso14443b_setup();
extern int iso14443b_select_card();
extern void SimulateIso14443bTag(void);
extern void ReadSTMemoryIso14443b(uint32_t);
extern void SnoopIso14443b(void);
extern void SendRawCommand14443B(uint32_t, uint32_t, uint8_t, uint8_t[]);
#endif /* __ISO14443B_H */

File diff suppressed because it is too large Load diff

43
armsrc/iso15693.h Normal file
View file

@ -0,0 +1,43 @@
//-----------------------------------------------------------------------------
// Piwi - October 2018
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Routines to support ISO 15693.
//-----------------------------------------------------------------------------
#ifndef ISO15693_H__
#define ISO15693_H__
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
// Delays in SSP_CLK ticks.
// SSP_CLK runs at 13,56MHz / 32 = 423.75kHz when simulating a tag
#define DELAY_ISO15693_VCD_TO_VICC_SIM 132 // 132/423.75kHz = 311.5us from end of command EOF to start of tag response
//SSP_CLK runs at 13.56MHz / 4 = 3,39MHz when acting as reader. All values should be multiples of 16
#define DELAY_ISO15693_VCD_TO_VICC_READER 1056 // 1056/3,39MHz = 311.5us from end of command EOF to start of tag response
#define DELAY_ISO15693_VICC_TO_VCD_READER 1024 // 1024/3.39MHz = 302.1us between end of tag response and next reader command
extern void Iso15693InitReader(void);
extern void Iso15693InitTag(void);
extern void CodeIso15693AsReader(uint8_t *cmd, int n);
extern void CodeIso15693AsTag(uint8_t *cmd, size_t len);
extern void TransmitTo15693Reader(const uint8_t *cmd, size_t len, uint32_t *start_time, uint32_t slot_time, bool slow);
extern int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eof_time);
extern void TransmitTo15693Tag(const uint8_t *cmd, int len, uint32_t *start_time);
extern int GetIso15693AnswerFromTag(uint8_t* response, uint16_t max_len, uint16_t timeout, uint32_t *eof_time);
extern void SnoopIso15693(uint8_t jam_search_len, uint8_t *jam_search_string);
extern void AcquireRawAdcSamplesIso15693(void);
extern void ReaderIso15693(uint32_t parameter);
extern void SimTagIso15693(uint32_t parameter, uint8_t *uid);
extern void BruteforceIso15693Afi(uint32_t speed);
extern void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t data[]);
extern void SetTag15693Uid(uint8_t *uid);
extern void SetDebugIso15693(uint32_t flag);
extern bool LogTrace_ISO15693(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag);
#endif

View file

@ -11,8 +11,7 @@ INCLUDE ../common/ldscript.common
PHDRS
{
fpgaimage PT_LOAD FLAGS(4);
text PT_LOAD;
text PT_LOAD FLAGS(5);
data PT_LOAD;
bss PT_LOAD;
}
@ -20,16 +19,12 @@ PHDRS
ENTRY(Vector)
SECTIONS
{
.fpgaimage : {
*(fpga_lf_bit.data)
*(fpga_hf_bit.data)
} >fpgaimage :fpgaimage
.start : {
*(.startos)
} >osimage :text
.text : {
KEEP(*(stage1_image))
*(.text)
*(.text.*)
*(.eh_frame)
@ -40,12 +35,13 @@ SECTIONS
.rodata : {
*(.rodata)
*(.rodata.*)
*(fpga_all_bit.data)
KEEP(*(.version_information))
. = ALIGN(8);
} >osimage :text
. = ALIGN(4);
.data : {
KEEP(*(compressed_data))
*(.data)
*(.data.*)
*(.ramfunc)
@ -55,6 +51,7 @@ SECTIONS
__data_src_start__ = LOADADDR(.data);
__data_start__ = ADDR(.data);
__data_end__ = __data_start__ + SIZEOF(.data);
__os_size__ = SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata);
.bss : {
__bss_start__ = .;

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,6 @@
//-----------------------------------------------------------------------------
// (c) 2009 Henryk Plötz <henryk@ploetzli.ch>
// 2018 AntiCat
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
@ -11,8 +12,7 @@
#ifndef __LEGICRF_H
#define __LEGICRF_H
extern void LegicRfSimulate(int phase, int frame, int reqresp);
extern int LegicRfReader(int bytes, int offset);
extern void LegicRfReader(int bytes, int offset);
extern void LegicRfWriter(int bytes, int offset);
#endif /* __LEGICRF_H */

470
armsrc/legicrfsim.c Normal file
View file

@ -0,0 +1,470 @@
//-----------------------------------------------------------------------------
// (c) 2009 Henryk Plötz <henryk@ploetzli.ch>
// 2016 Iceman
// 2018 AntiCat
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// LEGIC RF simulation code
//-----------------------------------------------------------------------------
#include "legicrfsim.h"
#include "proxmark3.h"
#include "apps.h"
#include "util.h"
#include "string.h"
#include "legic_prng.h"
#include "legic.h"
#include "crc.h"
#include "usb_cdc.h" // for usb_poll_validate_length
#include "fpgaloader.h"
static uint8_t* legic_mem; /* card memory, used for sim */
static legic_card_select_t card;/* metadata of currently selected card */
static crc_t legic_crc;
//-----------------------------------------------------------------------------
// Frame timing and pseudorandom number generator
//
// The Prng is forwarded every 99.1us (TAG_BIT_PERIOD), except when the reader is
// transmitting. In that case the prng has to be forwarded every bit transmitted:
// - 31.3us for a 0 (RWD_TIME_0)
// - 99.1us for a 1 (RWD_TIME_1)
//
// The data dependent timing makes writing comprehensible code significantly
// harder. The current aproach forwards the prng data based if there is data on
// air and time based, using GetCountSspClk(), during computational and wait
// periodes. SSP Clock is clocked by the FPGA at 212 kHz (subcarrier frequency).
//
// To not have the necessity to calculate/guess exection time dependend timeouts
// tx_frame and rx_frame use a shared timestamp to coordinate tx and rx timeslots.
//-----------------------------------------------------------------------------
static uint32_t last_frame_end; /* ts of last bit of previews rx or tx frame */
#define TAG_FRAME_WAIT 70 /* 330us from READER frame end to TAG frame start */
#define TAG_ACK_WAIT 758 /* 3.57ms from READER frame end to TAG write ACK */
#define TAG_BIT_PERIOD 21 /* 99.1us */
#define RWD_TIME_PAUSE 4 /* 18.9us */
#define RWD_TIME_1 21 /* RWD_TIME_PAUSE 18.9us off + 80.2us on = 99.1us */
#define RWD_TIME_0 13 /* RWD_TIME_PAUSE 18.9us off + 42.4us on = 61.3us */
#define RWD_CMD_TIMEOUT 120 /* 120 * 99.1us (arbitrary value) */
#define RWD_MIN_FRAME_LEN 6 /* Shortest frame is 6 bits */
#define RWD_MAX_FRAME_LEN 23 /* Longest frame is 23 bits */
#define RWD_PULSE 1 /* Pulse is signaled with GPIO_SSC_DIN high */
#define RWD_PAUSE 0 /* Pause is signaled with GPIO_SSC_DIN low */
//-----------------------------------------------------------------------------
// Demodulation
//-----------------------------------------------------------------------------
// Returns true if a pulse/pause is received within timeout
static inline bool wait_for(bool value, const uint32_t timeout) {
while((bool)(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_DIN) != value) {
if(GetCountSspClk() > timeout) {
return false;
}
}
return true;
}
// Returns a demedulated bit or -1 on code violation
//
// rx_bit decodes bits using a thresholds. rx_bit has to be called by as soon as
// a frame starts (first pause is received). rx_bit checks for a pause up to
// 18.9us followed by a pulse of 80.2us or 42.4us:
// - A bit length <18.9us is a code violation
// - A bit length >80.2us is a 1
// - A bit length <80.2us is a 0
// - A bit length >148.6us is a code violation
static inline int8_t rx_bit() {
// backup ts for threshold calculation
uint32_t bit_start = last_frame_end;
// wait for pause to end
if(!wait_for(RWD_PULSE, bit_start + RWD_TIME_1*3/2)) {
return -1;
}
// wait for next pause
if(!wait_for(RWD_PAUSE, bit_start + RWD_TIME_1*3/2)) {
return -1;
}
// update bit and frame end
last_frame_end = GetCountSspClk();
// check for code violation (bit to short)
if(last_frame_end - bit_start < RWD_TIME_PAUSE) {
return -1;
}
// apply threshold (average of RWD_TIME_0 and )
return (last_frame_end - bit_start > (RWD_TIME_0 + RWD_TIME_1) / 2);
}
//-----------------------------------------------------------------------------
// Modulation
//
// LEGIC RF uses a very basic load modulation from card to reader:
// - Subcarrier on for a 1
// - Subcarrier off for for a 0
//
// The 212kHz subcarrier is generated by the FPGA as well as a mathcing ssp clk.
// Each bit is transfered in a 99.1us slot and the first timeslot starts 330us
// after the final 20us pause generated by the reader.
//-----------------------------------------------------------------------------
// Transmits a bit
//
// Note: The Subcarrier is not disabled during bits to prevent glitches. This is
// not mandatory but results in a cleaner signal. tx_frame will disable
// the subcarrier when the frame is done.
static inline void tx_bit(bool bit) {
LED_C_ON();
if(bit) {
// modulate subcarrier
HIGH(GPIO_SSC_DOUT);
} else {
// do not modulate subcarrier
LOW(GPIO_SSC_DOUT);
}
// wait for tx timeslot to end
last_frame_end += TAG_BIT_PERIOD;
while(GetCountSspClk() < last_frame_end) { };
LED_C_OFF();
}
//-----------------------------------------------------------------------------
// Frame Handling
//
// The LEGIC RF protocol from reader to card does not include explicit frame
// start/stop information or length information. The tag detects end of frame
// trough an extended pulse (>99.1us) without a pause.
// In reverse direction (card to reader) the number of bites is well known
// and depends only the command received (IV, ACK, READ or WRITE).
//-----------------------------------------------------------------------------
static void tx_frame(uint32_t frame, uint8_t len) {
// wait for next tx timeslot
last_frame_end += TAG_FRAME_WAIT;
legic_prng_forward(TAG_FRAME_WAIT/TAG_BIT_PERIOD - 1);
while(GetCountSspClk() < last_frame_end) { };
// transmit frame, MSB first
for(uint8_t i = 0; i < len; ++i) {
bool bit = (frame >> i) & 0x01;
tx_bit(bit ^ legic_prng_get_bit());
legic_prng_forward(1);
};
// disable subcarrier
LOW(GPIO_SSC_DOUT);
}
static void tx_ack() {
// wait for ack timeslot
last_frame_end += TAG_ACK_WAIT;
legic_prng_forward(TAG_ACK_WAIT/TAG_BIT_PERIOD - 1);
while(GetCountSspClk() < last_frame_end) { };
// transmit ack (ack is not encrypted)
tx_bit(true);
legic_prng_forward(1);
// disable subcarrier
LOW(GPIO_SSC_DOUT);
}
// Returns a demedulated frame or -1 on code violation
//
// Since TX to RX delay is arbitrary rx_frame has to:
// - detect start of frame (first pause)
// - forward prng based on ts/TAG_BIT_PERIOD
// - receive the frame
// - detect end of frame (last pause)
static int32_t rx_frame(uint8_t *len) {
int32_t frame = 0;
// add 2 SSP clock cycles (1 for tx and 1 for rx pipeline delay)
// those will be substracted at the end of the rx phase
last_frame_end -= 2;
// wait for first pause (start of frame)
for(uint8_t i = 0; true; ++i) {
// increment prng every TAG_BIT_PERIOD
last_frame_end += TAG_BIT_PERIOD;
legic_prng_forward(1);
// if start of frame was received exit delay loop
if(wait_for(RWD_PAUSE, last_frame_end)) {
last_frame_end = GetCountSspClk();
break;
}
// check for code violation
if(i > RWD_CMD_TIMEOUT) {
return -1;
}
}
// receive frame
for(*len = 0; true; ++(*len)) {
// receive next bit
LED_D_ON();
int8_t bit = rx_bit();
LED_D_OFF();
// check for code violation and to short / long frame
if((bit < 0) && ((*len < RWD_MIN_FRAME_LEN) || (*len > RWD_MAX_FRAME_LEN))) {
return -1;
}
// check for code violation caused by end of frame
if(bit < 0) {
break;
}
// append bit
frame |= (bit ^ legic_prng_get_bit()) << (*len);
legic_prng_forward(1);
}
// rx_bit sets coordination timestamp to start of pause, append pause duration
// and substract 2 SSP clock cycles (1 for rx and 1 for tx pipeline delay) to
// obtain exact end of frame.
last_frame_end += RWD_TIME_PAUSE - 2;
return frame;
}
//-----------------------------------------------------------------------------
// Legic Simulator
//-----------------------------------------------------------------------------
static int32_t init_card(uint8_t cardtype, legic_card_select_t *p_card) {
p_card->tagtype = cardtype;
switch(p_card->tagtype) {
case 0:
p_card->cmdsize = 6;
p_card->addrsize = 5;
p_card->cardsize = 22;
break;
case 1:
p_card->cmdsize = 9;
p_card->addrsize = 8;
p_card->cardsize = 256;
break;
case 2:
p_card->cmdsize = 11;
p_card->addrsize = 10;
p_card->cardsize = 1024;
break;
default:
p_card->cmdsize = 0;
p_card->addrsize = 0;
p_card->cardsize = 0;
return 2;
}
return 0;
}
static void init_tag() {
// configure FPGA
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR
| FPGA_HF_SIMULATOR_MODULATE_212K);
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
// configure SSC with defaults
FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SIMULATOR);
// first pull output to low to prevent glitches then re-claim GPIO_SSC_DOUT
LOW(GPIO_SSC_DOUT);
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
// reserve a cardmem, meaning we can use the tracelog function in bigbuff easier.
legic_mem = BigBuf_get_addr();
// init crc calculator
crc_init(&legic_crc, 4, 0x19 >> 1, 0x05, 0);
// start 212kHz timer (running from SSP Clock)
StartCountSspClk();
}
// Setup reader to card connection
//
// The setup consists of a three way handshake:
// - Receive initialisation vector 7 bits
// - Transmit card type 6 bits
// - Receive Acknowledge 6 bits
static int32_t setup_phase(legic_card_select_t *p_card) {
uint8_t len = 0;
// init coordination timestamp
last_frame_end = GetCountSspClk();
// reset prng
legic_prng_init(0);
// wait for iv
int32_t iv = rx_frame(&len);
if((len != 7) || (iv < 0)) {
return -1;
}
// configure prng
legic_prng_init(iv);
// reply with card type
switch(p_card->tagtype) {
case 0:
tx_frame(0x0D, 6);
break;
case 1:
tx_frame(0x1D, 6);
break;
case 2:
tx_frame(0x3D, 6);
break;
}
// wait for ack
int32_t ack = rx_frame(&len);
if((len != 6) || (ack < 0)) {
return -1;
}
// validate data
switch(p_card->tagtype) {
case 0:
if(ack != 0x19) return -1;
break;
case 1:
if(ack != 0x39) return -1;
break;
case 2:
if(ack != 0x39) return -1;
break;
}
// During rx the prng is clocked using the variable reader period.
// Since rx_frame detects end of frame by detecting a code violation,
// the prng is off by one bit period after each rx phase. Hence, tx
// code advances the prng by (TAG_FRAME_WAIT/TAG_BIT_PERIOD - 1).
// This is not possible for back to back rx, so this quirk reduces
// the gap by one period.
last_frame_end += TAG_BIT_PERIOD;
return 0;
}
static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value) {
crc_clear(&legic_crc);
crc_update(&legic_crc, (value << cmd_sz) | cmd, 8 + cmd_sz);
return crc_finish(&legic_crc);
}
static int32_t connected_phase(legic_card_select_t *p_card) {
uint8_t len = 0;
// wait for command
int32_t cmd = rx_frame(&len);
if(cmd < 0) {
return -1;
}
// check if command is LEGIC_READ
if(len == p_card->cmdsize) {
// prepare data
uint8_t byte = legic_mem[cmd >> 1];
uint8_t crc = calc_crc4(cmd, p_card->cmdsize, byte);
// transmit data
tx_frame((crc << 8) | byte, 12);
return 0;
}
// check if command is LEGIC_WRITE
if(len == p_card->cmdsize + 8 + 4) {
// decode data
uint16_t mask = (1 << p_card->addrsize) - 1;
uint16_t addr = (cmd >> 1) & mask;
uint8_t byte = (cmd >> p_card->cmdsize) & 0xff;
uint8_t crc = (cmd >> (p_card->cmdsize + 8)) & 0xf;
// check received against calculated crc
uint8_t calc_crc = calc_crc4(addr << 1, p_card->cmdsize, byte);
if(calc_crc != crc) {
Dbprintf("!!! crc mismatch: %x != %x !!!", calc_crc, crc);
return -1;
}
// store data
legic_mem[addr] = byte;
// transmit ack
tx_ack();
return 0;
}
return -1;
}
//-----------------------------------------------------------------------------
// Command Line Interface
//
// Only this function is public / called from appmain.c
//-----------------------------------------------------------------------------
void LegicRfSimulate(uint8_t cardtype) {
// configure ARM and FPGA
init_tag();
// verify command line input
if(init_card(cardtype, &card) != 0) {
DbpString("Unknown tagtype.");
goto OUT;
}
LED_A_ON();
DbpString("Starting Legic emulator, press button to end");
while(!BUTTON_PRESS() && !usb_poll_validate_length()) {
WDT_HIT();
// wait for carrier, restart after timeout
if(!wait_for(RWD_PULSE, GetCountSspClk() + TAG_BIT_PERIOD)) {
continue;
}
// wait for connection, restart on error
if(setup_phase(&card)) {
continue;
}
// conection is established, process commands until one fails
while(!connected_phase(&card)) {
WDT_HIT();
}
}
OUT:
DbpString("Stopped");
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LED_A_OFF();
LED_C_OFF();
LED_D_OFF();
StopTicks();
}

19
armsrc/legicrfsim.h Normal file
View file

@ -0,0 +1,19 @@
//-----------------------------------------------------------------------------
// (c) 2009 Henryk Plötz <henryk@ploetzli.ch>
// 2018 AntiCat
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// LEGIC RF emulation public interface
//-----------------------------------------------------------------------------
#ifndef __LEGICRFSIM_H
#define __LEGICRFSIM_H
#include "proxmark3.h"
extern void LegicRfSimulate(uint8_t tagtype);
#endif /* __LEGICRFSIM_H */

File diff suppressed because it is too large Load diff

402
armsrc/lfsampling.c Normal file
View file

@ -0,0 +1,402 @@
//-----------------------------------------------------------------------------
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Miscellaneous routines for low frequency sampling.
//-----------------------------------------------------------------------------
#include "proxmark3.h"
#include "apps.h"
#include "util.h"
#include "string.h"
#include "lfsampling.h"
#include "usb_cdc.h" // for usb_poll_validate_length
#include "fpgaloader.h"
sample_config config = { 1, 8, 1, 95, 0, 0 } ;
void printConfig()
{
Dbprintf("LF Sampling config: ");
Dbprintf(" [q] divisor: %d ", config.divisor);
Dbprintf(" [b] bps: %d ", config.bits_per_sample);
Dbprintf(" [d] decimation: %d ", config.decimation);
Dbprintf(" [a] averaging: %d ", config.averaging);
Dbprintf(" [t] trigger threshold: %d ", config.trigger_threshold);
Dbprintf(" [s] samples to skip: %d ", config.samples_to_skip);
}
/**
* Called from the USB-handler to set the sampling configuration
* The sampling config is used for std reading and snooping.
*
* Other functions may read samples and ignore the sampling config,
* such as functions to read the UID from a prox tag or similar.
*
* Values set to '0' implies no change (except for averaging, threshold, samples_to_skip)
* @brief setSamplingConfig
* @param sc
*/
void setSamplingConfig(uint8_t *config_data) {
sample_config *sc = (sample_config *)config_data;
if (sc->divisor != 0) config.divisor = sc->divisor;
if (sc->bits_per_sample != 0) config.bits_per_sample = sc->bits_per_sample;
if (sc->decimation != 0) config.decimation = sc->decimation;
if (sc->trigger_threshold != -1) config.trigger_threshold = sc->trigger_threshold;
if (sc->samples_to_skip != -1) config.samples_to_skip = sc->samples_to_skip;
config.averaging= sc->averaging;
if (config.bits_per_sample > 8) config.bits_per_sample = 8;
if (config.decimation < 1) config.decimation = 1;
printConfig();
}
sample_config* getSamplingConfig()
{
return &config;
}
typedef struct {
uint8_t * buffer;
uint32_t numbits;
uint32_t position;
} BitstreamOut;
/**
* @brief Pushes bit onto the stream
* @param stream
* @param bit
*/
void pushBit( BitstreamOut* stream, uint8_t bit)
{
int bytepos = stream->position >> 3; // divide by 8
int bitpos = stream->position & 7;
*(stream->buffer+bytepos) |= (bit > 0) << (7 - bitpos);
stream->position++;
stream->numbits++;
}
/**
* Setup the FPGA to listen for samples. This method downloads the FPGA bitstream
* if not already loaded, sets divisor and starts up the antenna.
* @param divisor : 1, 88> 255 or negative ==> 134.8 KHz
* 0 or 95 ==> 125 KHz
*
**/
void LFSetupFPGAForADC(int divisor, bool lf_field)
{
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
if ( (divisor == 1) || (divisor < 0) || (divisor > 255) )
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
else if (divisor == 0)
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
else
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, divisor);
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | (lf_field ? FPGA_LF_ADC_READER_FIELD : 0));
// Connect the A/D to the peak-detected low-frequency path.
SetAdcMuxFor(GPIO_MUXSEL_LOPKD);
// Give it a bit of time for the resonant antenna to settle.
SpinDelay(50);
// Now set up the SSC to get the ADC samples that are now streaming at us.
FpgaSetupSsc(FPGA_MAJOR_MODE_LF_ADC);
}
/**
* Does the sample acquisition. If threshold is specified, the actual sampling
* is not commenced until the threshold has been reached.
* This method implements decimation and quantization in order to
* be able to provide longer sample traces.
* Uses the following global settings:
* @param decimation - how much should the signal be decimated. A decimation of N means we keep 1 in N samples, etc.
* @param bits_per_sample - bits per sample. Max 8, min 1 bit per sample.
* @param averaging If set to true, decimation will use averaging, so that if e.g. decimation is 3, the sample
* value that will be used is the average value of the three samples.
* @param trigger_threshold - a threshold. The sampling won't commence until this threshold has been reached. Set
* to -1 to ignore threshold.
* @param silent - is true, now outputs are made. If false, dbprints the status
* @return the number of bits occupied by the samples.
*/
uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, int cancel_after, int samples_to_skip)
{
//.
uint8_t *dest = BigBuf_get_addr();
bufsize = (bufsize > 0 && bufsize < BigBuf_max_traceLen()) ? bufsize : BigBuf_max_traceLen();
//memset(dest, 0, bufsize); //creates issues with cmdread (marshmellow)
if(bits_per_sample < 1) bits_per_sample = 1;
if(bits_per_sample > 8) bits_per_sample = 8;
if(decimation < 1) decimation = 1;
// Use a bit stream to handle the output
BitstreamOut data = { dest , 0, 0};
int sample_counter = 0;
uint8_t sample = 0;
//If we want to do averaging
uint32_t sample_sum =0 ;
uint32_t sample_total_numbers =0 ;
uint32_t sample_total_saved =0 ;
uint32_t cancel_counter = 0;
uint32_t samples_skipped = 0;
while(!BUTTON_PRESS() && !usb_poll_validate_length() ) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
AT91C_BASE_SSC->SSC_THR = 0x43;
LED_D_ON();
}
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
LED_D_OFF();
// threshold either high or low values 128 = center 0. if trigger = 178
if ((trigger_threshold > 0) && (sample < (trigger_threshold+128)) && (sample > (128-trigger_threshold))) { //
if (cancel_after > 0) {
cancel_counter++;
if (cancel_after == cancel_counter) break;
}
continue;
}
trigger_threshold = 0;
if (samples_to_skip > samples_skipped) {
samples_skipped++;
continue;
}
sample_total_numbers++;
if(averaging)
{
sample_sum += sample;
}
//Check decimation
if(decimation > 1)
{
sample_counter++;
if(sample_counter < decimation) continue;
sample_counter = 0;
}
//Averaging
if(averaging && decimation > 1) {
sample = sample_sum / decimation;
sample_sum =0;
}
//Store the sample
sample_total_saved ++;
if(bits_per_sample == 8){
dest[sample_total_saved-1] = sample;
data.numbits = sample_total_saved << 3;//Get the return value correct
if(sample_total_saved >= bufsize) break;
}
else{
pushBit(&data, sample & 0x80);
if(bits_per_sample > 1) pushBit(&data, sample & 0x40);
if(bits_per_sample > 2) pushBit(&data, sample & 0x20);
if(bits_per_sample > 3) pushBit(&data, sample & 0x10);
if(bits_per_sample > 4) pushBit(&data, sample & 0x08);
if(bits_per_sample > 5) pushBit(&data, sample & 0x04);
if(bits_per_sample > 6) pushBit(&data, sample & 0x02);
//Not needed, 8bps is covered above
//if(bits_per_sample > 7) pushBit(&data, sample & 0x01);
if((data.numbits >> 3) +1 >= bufsize) break;
}
}
}
if(!silent)
{
Dbprintf("Done, saved %d out of %d seen samples at %d bits/sample",sample_total_saved, sample_total_numbers,bits_per_sample);
Dbprintf("buffer samples: %02x %02x %02x %02x %02x %02x %02x %02x ...",
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
}
return data.numbits;
}
/**
* @brief Does sample acquisition, ignoring the config values set in the sample_config.
* This method is typically used by tag-specific readers who just wants to read the samples
* the normal way
* @param trigger_threshold
* @param silent
* @return number of bits sampled
*/
uint32_t DoAcquisition_default(int trigger_threshold, bool silent)
{
return DoAcquisition(1,8,0,trigger_threshold,silent,0,0,0);
}
uint32_t DoAcquisition_config(bool silent, int sample_size)
{
return DoAcquisition(config.decimation
,config.bits_per_sample
,config.averaging
,config.trigger_threshold
,silent
,sample_size
,0
,config.samples_to_skip);
}
uint32_t DoPartialAcquisition(int trigger_threshold, bool silent, int sample_size, int cancel_after) {
return DoAcquisition(1,8,0,trigger_threshold,silent,sample_size,cancel_after,0);
}
uint32_t ReadLF(bool activeField, bool silent, int sample_size)
{
if (!silent) printConfig();
LFSetupFPGAForADC(config.divisor, activeField);
// Now call the acquisition routine
return DoAcquisition_config(silent, sample_size);
}
/**
* Initializes the FPGA for reader-mode (field on), and acquires the samples.
* @return number of bits sampled
**/
uint32_t SampleLF(bool printCfg, int sample_size)
{
uint32_t ret = ReadLF(true, printCfg, sample_size);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
return ret;
}
/**
* Initializes the FPGA for snoop-mode (field off), and acquires the samples.
* @return number of bits sampled
**/
uint32_t SnoopLF()
{
uint32_t ret = ReadLF(false, true, 0);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
return ret;
}
/**
* acquisition of Cotag LF signal. Similar to other LF, since the Cotag has such long datarate RF/384
* and is Manchester?, we directly gather the manchester data into bigbuff
**/
#define COTAG_T1 384
#define COTAG_T2 (COTAG_T1>>1)
#define COTAG_ONE_THRESHOLD 128+30
#define COTAG_ZERO_THRESHOLD 128-30
#ifndef COTAG_BITS
#define COTAG_BITS 264
#endif
void doCotagAcquisition(size_t sample_size) {
uint8_t *dest = BigBuf_get_addr();
uint16_t bufsize = BigBuf_max_traceLen();
if ( bufsize > sample_size )
bufsize = sample_size;
dest[0] = 0;
uint8_t sample = 0, firsthigh = 0, firstlow = 0;
uint16_t i = 0;
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (i < bufsize) ) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
AT91C_BASE_SSC->SSC_THR = 0x43;
LED_D_ON();
}
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
LED_D_OFF();
// find first peak
if ( !firsthigh ) {
if (sample < COTAG_ONE_THRESHOLD)
continue;
firsthigh = 1;
}
if ( !firstlow ){
if (sample > COTAG_ZERO_THRESHOLD )
continue;
firstlow = 1;
}
++i;
if ( sample > COTAG_ONE_THRESHOLD)
dest[i] = 255;
else if ( sample < COTAG_ZERO_THRESHOLD)
dest[i] = 0;
else
dest[i] = dest[i-1];
}
}
}
uint32_t doCotagAcquisitionManchester() {
uint8_t *dest = BigBuf_get_addr();
uint16_t bufsize = BigBuf_max_traceLen();
if ( bufsize > COTAG_BITS )
bufsize = COTAG_BITS;
dest[0] = 0;
uint8_t sample = 0, firsthigh = 0, firstlow = 0;
uint16_t sample_counter = 0, period = 0;
uint8_t curr = 0, prev = 0;
uint16_t noise_counter = 0;
while (!BUTTON_PRESS() && !usb_poll_validate_length() && (sample_counter < bufsize) && (noise_counter < (COTAG_T1<<1)) ) {
WDT_HIT();
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_TXRDY) {
AT91C_BASE_SSC->SSC_THR = 0x43;
LED_D_ON();
}
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
sample = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
LED_D_OFF();
// find first peak
if ( !firsthigh ) {
if (sample < COTAG_ONE_THRESHOLD) {
noise_counter++;
continue;
}
noise_counter = 0;
firsthigh = 1;
}
if ( !firstlow ){
if (sample > COTAG_ZERO_THRESHOLD ) {
noise_counter++;
continue;
}
noise_counter=0;
firstlow = 1;
}
// set sample 255, 0, or previous
if ( sample > COTAG_ONE_THRESHOLD){
prev = curr;
curr = 1;
}
else if ( sample < COTAG_ZERO_THRESHOLD) {
prev = curr;
curr = 0;
}
else {
curr = prev;
}
// full T1 periods,
if ( period > 0 ) {
--period;
continue;
}
dest[sample_counter] = curr;
++sample_counter;
period = COTAG_T1;
}
}
return sample_counter;
}

71
armsrc/lfsampling.h Normal file
View file

@ -0,0 +1,71 @@
#ifndef LFSAMPLING_H__
#define LFSAMPLING_H__
/**
* acquisition of Cotag LF signal. Similar to other LF, since the Cotag has such long datarate RF/384
* and is Manchester?, we directly gather the manchester data into bigbuff
**/
void doCotagAcquisition(size_t sample_size);
uint32_t doCotagAcquisitionManchester(void);
/**
* Initializes the FPGA for reader-mode (field on), and acquires the samples.
* @return number of bits sampled
**/
uint32_t SampleLF(bool silent, int sample_size);
/**
* Initializes the FPGA for snoop-mode (field off), and acquires the samples.
* @return number of bits sampled
**/
uint32_t SnoopLF();
// adds sample size to default options
uint32_t DoPartialAcquisition(int trigger_threshold, bool silent, int sample_size, int cancel_after);
/**
* @brief Does sample acquisition, ignoring the config values set in the sample_config.
* This method is typically used by tag-specific readers who just wants to read the samples
* the normal way
* @param trigger_threshold
* @param silent
* @return number of bits sampled
*/
uint32_t DoAcquisition_default(int trigger_threshold, bool silent);
/**
* @brief Does sample acquisition, using the config values set in the sample_config.
* @param trigger_threshold
* @param silent
* @return number of bits sampled
*/
uint32_t DoAcquisition_config(bool silent, int sample_size);
/**
* Setup the FPGA to listen for samples. This method downloads the FPGA bitstream
* if not already loaded, sets divisor and starts up the antenna.
* @param divisor : 1, 88> 255 or negative ==> 134.8 KHz
* 0 or 95 ==> 125 KHz
*
**/
void LFSetupFPGAForADC(int divisor, bool lf_field);
/**
* Called from the USB-handler to set the sampling configuration
* The sampling config is used for std reading and snooping.
*
* Other functions may read samples and ignore the sampling config,
* such as functions to read the UID from a prox tag or similar.
*
* Values set to '0' implies no change (except for averaging)
* @brief setSamplingConfig
* @param sc
*/
void setSamplingConfig(uint8_t *config_data);
sample_config *getSamplingConfig();
void printConfig();
#endif // LFSAMPLING_H

File diff suppressed because it is too large Load diff

View file

@ -10,19 +10,36 @@
// Routines to support ISO 14443 type A.
//-----------------------------------------------------------------------------
#ifndef __MIFARECMD_H
#define __MIFARECMD_H
#ifndef MIFARECMD_H__
#define MIFARECMD_H__
#include "proxmark3.h"
#include "apps.h"
#include "util.h"
#include "string.h"
#include <stdint.h>
#include "iso14443crc.h"
#include "iso14443a.h"
#include "crapto1.h"
#include "mifareutil.h"
#include "common.h"
extern void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *data);
extern void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
extern void MifareUC_Auth(uint8_t arg0, uint8_t *datain);
extern void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain);
extern void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
extern void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain);
//extern void MifareUWriteBlockCompat(uint8_t arg0,uint8_t *datain);
extern void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain);
extern void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
extern void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain);
extern void MifareChkKeys(uint16_t arg0, uint32_t arg1, uint8_t arg2, uint8_t *datain);
extern void MifareSetDbgLvl(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
extern void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
extern void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
extern void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
extern void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
extern void MifareCWipe(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); // Work with "magic Chinese" card
extern void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
extern void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
extern void MifareCIdent(); // is "magic chinese" card?
extern void MifareUSetPwd(uint8_t arg0, uint8_t *datain);
extern void MifarePersonalizeUID(uint8_t keyType, uint8_t perso_option, uint8_t *datain);
//desfire
extern void Mifare_DES_Auth1(uint8_t arg0,uint8_t *datain);
extern void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain);
#endif
#endif

867
armsrc/mifaresim.c Normal file
View file

@ -0,0 +1,867 @@
//-----------------------------------------------------------------------------
// Merlok - June 2011, 2012
// Gerhard de Koning Gans - May 2008
// Hagen Fritsch - June 2010
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Mifare Classic Card Simulation
//-----------------------------------------------------------------------------
#include "mifaresim.h"
#include "iso14443a.h"
#include "iso14443crc.h"
#include "crapto1/crapto1.h"
#include "BigBuf.h"
#include "string.h"
#include "mifareutil.h"
#include "fpgaloader.h"
#include "proxmark3.h"
#include "usb_cdc.h"
#include "protocols.h"
#include "apps.h"
#include "util.h"
//mifare emulator states
#define MFEMUL_NOFIELD 0
#define MFEMUL_IDLE 1
#define MFEMUL_SELECT1 2
#define MFEMUL_SELECT2 3
#define MFEMUL_SELECT3 4
#define MFEMUL_AUTH1 5
#define MFEMUL_AUTH2 6
#define MFEMUL_WORK 7
#define MFEMUL_WRITEBL2 8
#define MFEMUL_INTREG_INC 9
#define MFEMUL_INTREG_DEC 10
#define MFEMUL_INTREG_REST 11
#define MFEMUL_HALTED 12
#define AC_DATA_READ 0
#define AC_DATA_WRITE 1
#define AC_DATA_INC 2
#define AC_DATA_DEC_TRANS_REST 3
#define AC_KEYA_READ 0
#define AC_KEYA_WRITE 1
#define AC_KEYB_READ 2
#define AC_KEYB_WRITE 3
#define AC_AC_READ 4
#define AC_AC_WRITE 5
#define AUTHKEYA 0
#define AUTHKEYB 1
#define AUTHKEYNONE 0xff
static int ParamCardSizeBlocks(const char c) {
int numBlocks = 16 * 4;
switch (c) {
case '0' : numBlocks = 5 * 4; break;
case '2' : numBlocks = 32 * 4; break;
case '4' : numBlocks = 32 * 4 + 8 * 16; break;
default: numBlocks = 16 * 4;
}
return numBlocks;
}
static uint8_t BlockToSector(int block_num) {
if (block_num < 32 * 4) { // 4 blocks per sector
return (block_num / 4);
} else { // 16 blocks per sector
return 32 + (block_num - 32 * 4) / 16;
}
}
static bool IsTrailerAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t action) {
uint8_t sector_trailer[16];
emlGetMem(sector_trailer, blockNo, 1);
uint8_t AC = ((sector_trailer[7] >> 5) & 0x04)
| ((sector_trailer[8] >> 2) & 0x02)
| ((sector_trailer[8] >> 7) & 0x01);
switch (action) {
case AC_KEYA_READ: {
return false;
break;
}
case AC_KEYA_WRITE: {
return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x01))
|| (keytype == AUTHKEYB && (AC == 0x04 || AC == 0x03)));
break;
}
case AC_KEYB_READ: {
return (keytype == AUTHKEYA && (AC == 0x00 || AC == 0x02 || AC == 0x01));
break;
}
case AC_KEYB_WRITE: {
return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x01))
|| (keytype == AUTHKEYB && (AC == 0x04 || AC == 0x03)));
break;
}
case AC_AC_READ: {
return ((keytype == AUTHKEYA)
|| (keytype == AUTHKEYB && !(AC == 0x00 || AC == 0x02 || AC == 0x01)));
break;
}
case AC_AC_WRITE: {
return ((keytype == AUTHKEYA && (AC == 0x01))
|| (keytype == AUTHKEYB && (AC == 0x03 || AC == 0x05)));
break;
}
default: return false;
}
}
static bool IsDataAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t action)
{
uint8_t sector_trailer[16];
emlGetMem(sector_trailer, SectorTrailer(blockNo), 1);
uint8_t sector_block;
if (blockNo < 32*4) {
sector_block = blockNo & 0x03;
} else {
sector_block = (blockNo & 0x0f) / 5;
}
uint8_t AC;
switch (sector_block) {
case 0x00: {
AC = ((sector_trailer[7] >> 2) & 0x04)
| ((sector_trailer[8] << 1) & 0x02)
| ((sector_trailer[8] >> 4) & 0x01);
break;
}
case 0x01: {
AC = ((sector_trailer[7] >> 3) & 0x04)
| ((sector_trailer[8] >> 0) & 0x02)
| ((sector_trailer[8] >> 5) & 0x01);
break;
}
case 0x02: {
AC = ((sector_trailer[7] >> 4) & 0x04)
| ((sector_trailer[8] >> 1) & 0x02)
| ((sector_trailer[8] >> 6) & 0x01);
break;
}
default:
return false;
}
switch (action) {
case AC_DATA_READ: {
return ((keytype == AUTHKEYA && !(AC == 0x03 || AC == 0x05 || AC == 0x07))
|| (keytype == AUTHKEYB && !(AC == 0x07)));
break;
}
case AC_DATA_WRITE: {
return ((keytype == AUTHKEYA && (AC == 0x00))
|| (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x04 || AC == 0x06 || AC == 0x03)));
break;
}
case AC_DATA_INC: {
return ((keytype == AUTHKEYA && (AC == 0x00))
|| (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x06)));
break;
}
case AC_DATA_DEC_TRANS_REST: {
return ((keytype == AUTHKEYA && (AC == 0x00 || AC == 0x06 || AC == 0x01))
|| (keytype == AUTHKEYB && (AC == 0x00 || AC == 0x06 || AC == 0x01)));
break;
}
}
return false;
}
static bool IsAccessAllowed(uint8_t blockNo, uint8_t keytype, uint8_t action) {
if (IsSectorTrailer(blockNo)) {
return IsTrailerAccessAllowed(blockNo, keytype, action);
} else {
return IsDataAccessAllowed(blockNo, keytype, action);
}
}
static void MifareSimInit(uint8_t flags, uint8_t *datain, tag_response_info_t **responses, uint32_t *cuid, uint8_t *uid_len, uint8_t cardsize) {
#define TAG_RESPONSE_COUNT 5 // number of precompiled responses
static uint8_t rATQA[] = {0x00, 0x00};
static uint8_t rUIDBCC1[] = {0x00, 0x00, 0x00, 0x00, 0x00}; // UID 1st cascade level
static uint8_t rUIDBCC2[] = {0x00, 0x00, 0x00, 0x00, 0x00}; // UID 2nd cascade level
static uint8_t rSAKfinal[]= {0x00, 0x00, 0x00}; // SAK after UID complete
static uint8_t rSAK1[] = {0x00, 0x00, 0x00}; // indicate UID not finished
*uid_len = 4;
// UID can be set from emulator memory or incoming data and can be 4 or 7 bytes long
if (flags & FLAG_4B_UID_IN_DATA) { // get UID from datain
memcpy(rUIDBCC1, datain, 4);
} else if (flags & FLAG_7B_UID_IN_DATA) {
rUIDBCC1[0] = 0x88;
memcpy(rUIDBCC1+1, datain, 3);
memcpy(rUIDBCC2, datain+3, 4);
*uid_len = 7;
} else {
uint8_t probable_atqa;
emlGetMemBt(&probable_atqa, 7, 1); // get UID from emul memory - weak guess at length
if (probable_atqa == 0x00) { // ---------- 4BUID
emlGetMemBt(rUIDBCC1, 0, 4);
} else { // ---------- 7BUID
rUIDBCC1[0] = 0x88;
emlGetMemBt(rUIDBCC1+1, 0, 3);
emlGetMemBt(rUIDBCC2, 3, 4);
*uid_len = 7;
}
}
switch (*uid_len) {
case 4:
*cuid = bytes_to_num(rUIDBCC1, 4);
rUIDBCC1[4] = rUIDBCC1[0] ^ rUIDBCC1[1] ^ rUIDBCC1[2] ^ rUIDBCC1[3];
if (MF_DBGLEVEL >= MF_DBG_INFO) {
Dbprintf("4B UID: %02x%02x%02x%02x",
rUIDBCC1[0], rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3] );
}
break;
case 7:
*cuid = bytes_to_num(rUIDBCC2, 4);
rUIDBCC1[4] = rUIDBCC1[0] ^ rUIDBCC1[1] ^ rUIDBCC1[2] ^ rUIDBCC1[3];
rUIDBCC2[4] = rUIDBCC2[0] ^ rUIDBCC2[1] ^ rUIDBCC2[2] ^ rUIDBCC2[3];
if (MF_DBGLEVEL >= MF_DBG_INFO) {
Dbprintf("7B UID: %02x %02x %02x %02x %02x %02x %02x",
rUIDBCC1[1], rUIDBCC1[2], rUIDBCC1[3], rUIDBCC2[0], rUIDBCC2[1], rUIDBCC2[2], rUIDBCC2[3] );
}
break;
default:
break;
}
// set SAK based on cardsize
switch (cardsize) {
case '0': rSAKfinal[0] = 0x09; break; // Mifare Mini
case '2': rSAKfinal[0] = 0x10; break; // Mifare 2K
case '4': rSAKfinal[0] = 0x18; break; // Mifare 4K
default: rSAKfinal[0] = 0x08; // Mifare 1K
}
ComputeCrc14443(CRC_14443_A, rSAKfinal, 1, rSAKfinal + 1, rSAKfinal + 2);
if (MF_DBGLEVEL >= MF_DBG_INFO) {
Dbprintf("SAK: %02x", rSAKfinal[0]);
}
// set SAK for incomplete UID
rSAK1[0] = 0x04; // Bit 3 indicates incomplete UID
ComputeCrc14443(CRC_14443_A, rSAK1, 1, rSAK1 + 1, rSAK1 + 2);
// set ATQA based on cardsize and UIDlen
if (cardsize == '4') {
rATQA[0] = 0x02;
} else {
rATQA[0] = 0x04;
}
if (*uid_len == 7) {
rATQA[0] |= 0x40;
}
if (MF_DBGLEVEL >= MF_DBG_INFO) {
Dbprintf("ATQA: %02x %02x", rATQA[1], rATQA[0]);
}
static tag_response_info_t responses_init[TAG_RESPONSE_COUNT] = {
{ .response = rATQA, .response_n = sizeof(rATQA) }, // Answer to request - respond with card type
{ .response = rUIDBCC1, .response_n = sizeof(rUIDBCC1) }, // Anticollision cascade1 - respond with first part of uid
{ .response = rUIDBCC2, .response_n = sizeof(rUIDBCC2) }, // Anticollision cascade2 - respond with 2nd part of uid
{ .response = rSAKfinal, .response_n = sizeof(rSAKfinal) }, // Acknowledge select - last cascade
{ .response = rSAK1, .response_n = sizeof(rSAK1) } // Acknowledge select - previous cascades
};
// Prepare ("precompile") the responses of the anticollision phase. There will be not enough time to do this at the moment the reader sends its REQA or SELECT
// There are 5 predefined responses with a total of 18 bytes data to transmit. Coded responses need one byte per bit to transfer (data, parity, start, stop, correction)
// 18 * 8 data bits, 18 * 1 parity bits, 5 start bits, 5 stop bits, 5 correction bits -> need 177 bytes buffer
#define ALLOCATED_TAG_MODULATION_BUFFER_SIZE 177 // number of bytes required for precompiled responses
uint8_t *free_buffer_pointer = BigBuf_malloc(ALLOCATED_TAG_MODULATION_BUFFER_SIZE);
size_t free_buffer_size = ALLOCATED_TAG_MODULATION_BUFFER_SIZE;
for (size_t i = 0; i < TAG_RESPONSE_COUNT; i++) {
prepare_allocated_tag_modulation(&responses_init[i], &free_buffer_pointer, &free_buffer_size);
}
*responses = responses_init;
// indices into responses array:
#define ATQA 0
#define UIDBCC1 1
#define UIDBCC2 2
#define SAKfinal 3
#define SAK1 4
}
static bool HasValidCRC(uint8_t *receivedCmd, uint16_t receivedCmd_len) {
uint8_t CRC_byte_1, CRC_byte_2;
ComputeCrc14443(CRC_14443_A, receivedCmd, receivedCmd_len-2, &CRC_byte_1, &CRC_byte_2);
return (receivedCmd[receivedCmd_len-2] == CRC_byte_1 && receivedCmd[receivedCmd_len-1] == CRC_byte_2);
}
/**
*MIFARE simulate.
*
*@param flags :
* FLAG_INTERACTIVE - In interactive mode, we are expected to finish the operation with an ACK
* FLAG_4B_UID_IN_DATA - means that there is a 4-byte UID in the data-section, we're expected to use that
* FLAG_7B_UID_IN_DATA - means that there is a 7-byte UID in the data-section, we're expected to use that
* FLAG_NR_AR_ATTACK - means we should collect NR_AR responses for bruteforcing later
* FLAG_RANDOM_NONCE - means we should generate some pseudo-random nonce data (only allows moebius attack)
*@param exitAfterNReads, exit simulation after n blocks have been read, 0 is infinite ...
* (unless reader attack mode enabled then it runs util it gets enough nonces to recover all keys attmpted)
*/
void MifareSim(uint8_t flags, uint8_t exitAfterNReads, uint8_t cardsize, uint8_t *datain)
{
LED_A_ON();
tag_response_info_t *responses;
uint8_t uid_len = 4;
uint32_t cuid = 0;
uint8_t cardWRBL = 0;
uint8_t cardAUTHSC = 0;
uint8_t cardAUTHKEY = AUTHKEYNONE; // no authentication
uint32_t cardRr = 0;
//uint32_t rn_enc = 0;
uint32_t ans = 0;
uint32_t cardINTREG = 0;
uint8_t cardINTBLOCK = 0;
struct Crypto1State mpcs = {0, 0};
struct Crypto1State *pcs = &mpcs;
uint32_t numReads = 0; //Counts numer of times reader reads a block
uint8_t receivedCmd[MAX_MIFARE_FRAME_SIZE];
uint8_t receivedCmd_dec[MAX_MIFARE_FRAME_SIZE];
uint8_t receivedCmd_par[MAX_MIFARE_PARITY_SIZE];
uint16_t receivedCmd_len;
uint8_t response[MAX_MIFARE_FRAME_SIZE];
uint8_t response_par[MAX_MIFARE_PARITY_SIZE];
uint8_t fixed_nonce[] = {0x01, 0x02, 0x03, 0x04};
int num_blocks = ParamCardSizeBlocks(cardsize);
// Here we collect UID, sector, keytype, NT, AR, NR, NT2, AR2, NR2
// This will be used in the reader-only attack.
// allow collecting up to 7 sets of nonces to allow recovery of up to 7 keys
#define ATTACK_KEY_COUNT 7 // keep same as define in cmdhfmf.c -> readerAttack() (Cannot be more than 7)
nonces_t ar_nr_resp[ATTACK_KEY_COUNT*2]; // *2 for 2 separate attack types (nml, moebius) 36 * 7 * 2 bytes = 504 bytes
memset(ar_nr_resp, 0x00, sizeof(ar_nr_resp));
uint8_t ar_nr_collected[ATTACK_KEY_COUNT*2]; // *2 for 2nd attack type (moebius)
memset(ar_nr_collected, 0x00, sizeof(ar_nr_collected));
uint8_t nonce1_count = 0;
uint8_t nonce2_count = 0;
uint8_t moebius_n_count = 0;
bool gettingMoebius = false;
uint8_t mM = 0; // moebius_modifier for collection storage
// Authenticate response - nonce
uint32_t nonce;
if (flags & FLAG_RANDOM_NONCE) {
nonce = prand();
} else {
nonce = bytes_to_num(fixed_nonce, 4);
}
// free eventually allocated BigBuf memory but keep Emulator Memory
BigBuf_free_keep_EM();
MifareSimInit(flags, datain, &responses, &cuid, &uid_len, cardsize);
// We need to listen to the high-frequency, peak-detected path.
iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);
// clear trace
clear_trace();
set_tracing(true);
ResetSspClk();
bool finished = false;
bool button_pushed = BUTTON_PRESS();
int cardSTATE = MFEMUL_NOFIELD;
while (!button_pushed && !finished && !usb_poll_validate_length()) {
WDT_HIT();
if (cardSTATE == MFEMUL_NOFIELD) {
// wait for reader HF field
int vHf = (MAX_ADC_HF_VOLTAGE_LOW * AvgAdc(ADC_CHAN_HF_LOW)) >> 10;
if (vHf > MF_MINFIELDV) {
LED_D_ON();
cardSTATE = MFEMUL_IDLE;
}
button_pushed = BUTTON_PRESS();
continue;
}
//Now, get data
FpgaEnableTracing();
int res = EmGetCmd(receivedCmd, &receivedCmd_len, receivedCmd_par);
if (res == 2) { // Reader has dropped the HF field. Power off.
FpgaDisableTracing();
LED_D_OFF();
cardSTATE = MFEMUL_NOFIELD;
continue;
} else if (res == 1) { // button pressed
FpgaDisableTracing();
button_pushed = true;
break;
}
// WUPA in HALTED state or REQA or WUPA in any other state
if (receivedCmd_len == 1 && ((receivedCmd[0] == ISO14443A_CMD_REQA && cardSTATE != MFEMUL_HALTED) || receivedCmd[0] == ISO14443A_CMD_WUPA)) {
EmSendPrecompiledCmd(&responses[ATQA]);
FpgaDisableTracing();
// init crypto block
crypto1_destroy(pcs);
cardAUTHKEY = AUTHKEYNONE;
if (flags & FLAG_RANDOM_NONCE) {
nonce = prand();
}
cardSTATE = MFEMUL_SELECT1;
continue;
}
switch (cardSTATE) {
case MFEMUL_NOFIELD:
case MFEMUL_HALTED:
case MFEMUL_IDLE:{
break;
}
case MFEMUL_SELECT1:{
// select all - 0x93 0x20
if (receivedCmd_len == 2 && (receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT && receivedCmd[1] == 0x20)) {
EmSendPrecompiledCmd(&responses[UIDBCC1]);
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("SELECT ALL CL1 received");
break;
}
// select card - 0x93 0x70 ...
if (receivedCmd_len == 9 &&
(receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT && receivedCmd[1] == 0x70 && memcmp(&receivedCmd[2], responses[UIDBCC1].response, 4) == 0)) {
if (uid_len == 4) {
EmSendPrecompiledCmd(&responses[SAKfinal]);
cardSTATE = MFEMUL_WORK;
} else if (uid_len == 7) {
EmSendPrecompiledCmd(&responses[SAK1]);
cardSTATE = MFEMUL_SELECT2;
}
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("SELECT CL1 %02x%02x%02x%02x received",receivedCmd[2],receivedCmd[3],receivedCmd[4],receivedCmd[5]);
break;
}
cardSTATE = MFEMUL_IDLE;
break;
}
case MFEMUL_SELECT2:{
// select all cl2 - 0x95 0x20
if (receivedCmd_len == 2 && (receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2 && receivedCmd[1] == 0x20)) {
EmSendPrecompiledCmd(&responses[UIDBCC2]);
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("SELECT ALL CL2 received");
break;
}
// select cl2 card - 0x95 0x70 xxxxxxxxxxxx
if (receivedCmd_len == 9 &&
(receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2 && receivedCmd[1] == 0x70 && memcmp(&receivedCmd[2], responses[UIDBCC2].response, 4) == 0)) {
if (uid_len == 7) {
EmSendPrecompiledCmd(&responses[SAKfinal]);
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("SELECT CL2 %02x%02x%02x%02x received",receivedCmd[2],receivedCmd[3],receivedCmd[4],receivedCmd[5]);
cardSTATE = MFEMUL_WORK;
break;
}
}
cardSTATE = MFEMUL_IDLE;
break;
}
case MFEMUL_WORK:{
if (receivedCmd_len != 4) { // all commands must have exactly 4 bytes
break;
}
bool encrypted_data = (cardAUTHKEY != AUTHKEYNONE) ;
if (encrypted_data) {
// decrypt seqence
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, receivedCmd_dec);
} else {
memcpy(receivedCmd_dec, receivedCmd, receivedCmd_len);
}
if (!HasValidCRC(receivedCmd_dec, receivedCmd_len)) { // all commands must have a valid CRC
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_TR));
break;
}
if (receivedCmd_dec[0] == MIFARE_AUTH_KEYA || receivedCmd_dec[0] == MIFARE_AUTH_KEYB) {
// if authenticating to a block that shouldn't exist - as long as we are not doing the reader attack
if (receivedCmd_dec[1] >= num_blocks && !(flags & FLAG_NR_AR_ATTACK)) {
//is this the correct response to an auth on a out of range block? marshmellow
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], receivedCmd_dec[1]);
break;
}
cardAUTHSC = BlockToSector(receivedCmd_dec[1]); // received block num
cardAUTHKEY = receivedCmd_dec[0] & 0x01;
crypto1_destroy(pcs);//Added by martin
crypto1_create(pcs, emlGetKey(cardAUTHSC, cardAUTHKEY));
if (!encrypted_data) { // first authentication
crypto1_word(pcs, cuid ^ nonce, 0); // Update crypto state
num_to_bytes(nonce, 4, response); // Send unencrypted nonce
EmSendCmd(response, sizeof(nonce));
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Reader authenticating for block %d (0x%02x) with key %d", receivedCmd_dec[1], receivedCmd_dec[1], cardAUTHKEY);
} else { // nested authentication
num_to_bytes(nonce, sizeof(nonce), response);
uint8_t pcs_in[4] = {0};
num_to_bytes(cuid ^ nonce, sizeof(nonce), pcs_in);
mf_crypto1_encryptEx(pcs, response, pcs_in, sizeof(nonce), response_par);
EmSendCmdPar(response, sizeof(nonce), response_par); // send encrypted nonce
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Reader doing nested authentication for block %d (0x%02x) with key %d", receivedCmd_dec[1], receivedCmd_dec[1], cardAUTHKEY);
}
cardSTATE = MFEMUL_AUTH1;
break;
}
// halt can be sent encrypted or in clear
if (receivedCmd_dec[0] == ISO14443A_CMD_HALT && receivedCmd_dec[1] == 0x00) {
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("--> HALTED.");
cardSTATE = MFEMUL_HALTED;
break;
}
if(receivedCmd_dec[0] == MIFARE_CMD_READBLOCK
|| receivedCmd_dec[0] == MIFARE_CMD_WRITEBLOCK
|| receivedCmd_dec[0] == MIFARE_CMD_INC
|| receivedCmd_dec[0] == MIFARE_CMD_DEC
|| receivedCmd_dec[0] == MIFARE_CMD_RESTORE
|| receivedCmd_dec[0] == MIFARE_CMD_TRANSFER) {
if (receivedCmd_dec[1] >= num_blocks) {
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Reader tried to operate (0x%02x) on out of range block: %d (0x%02x), nacking",receivedCmd_dec[0],receivedCmd_dec[1],receivedCmd_dec[1]);
break;
}
if (BlockToSector(receivedCmd_dec[1]) != cardAUTHSC) {
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Reader tried to operate (0x%02x) on block (0x%02x) not authenticated for (0x%02x), nacking",receivedCmd_dec[0],receivedCmd_dec[1],cardAUTHSC);
break;
}
}
if (receivedCmd_dec[0] == MIFARE_CMD_READBLOCK) {
uint8_t blockNo = receivedCmd_dec[1];
emlGetMem(response, blockNo, 1);
if (IsSectorTrailer(blockNo)) {
memset(response, 0x00, 6); // keyA can never be read
if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYB_READ)) {
memset(response+10, 0x00, 6); // keyB cannot be read
}
if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_AC_READ)) {
memset(response+6, 0x00, 4); // AC bits cannot be read
}
} else {
if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_DATA_READ)) {
memset(response, 0x00, 16); // datablock cannot be read
}
}
AppendCrc14443a(response, 16);
mf_crypto1_encrypt(pcs, response, 18, response_par);
EmSendCmdPar(response, 18, response_par);
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) {
Dbprintf("Reader reading block %d (0x%02x)", blockNo, blockNo);
}
numReads++;
if(exitAfterNReads > 0 && numReads == exitAfterNReads) {
Dbprintf("%d reads done, exiting", numReads);
finished = true;
}
break;
}
if (receivedCmd_dec[0] == MIFARE_CMD_WRITEBLOCK) {
uint8_t blockNo = receivedCmd_dec[1];
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("RECV 0xA0 write block %d (%02x)", blockNo, blockNo);
cardWRBL = blockNo;
cardSTATE = MFEMUL_WRITEBL2;
break;
}
if (receivedCmd_dec[0] == MIFARE_CMD_INC || receivedCmd_dec[0] == MIFARE_CMD_DEC || receivedCmd_dec[0] == MIFARE_CMD_RESTORE) {
uint8_t blockNo = receivedCmd_dec[1];
if (emlCheckValBl(blockNo)) {
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) {
Dbprintf("RECV 0x%02x inc(0xC1)/dec(0xC0)/restore(0xC2) block %d (%02x)",receivedCmd_dec[0], blockNo, blockNo);
}
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Reader tried to operate on block, but emlCheckValBl failed, nacking");
break;
}
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) {
Dbprintf("RECV 0x%02x inc(0xC1)/dec(0xC0)/restore(0xC2) block %d (%02x)",receivedCmd_dec[0], blockNo, blockNo);
}
cardWRBL = blockNo;
if (receivedCmd_dec[0] == MIFARE_CMD_INC)
cardSTATE = MFEMUL_INTREG_INC;
if (receivedCmd_dec[0] == MIFARE_CMD_DEC)
cardSTATE = MFEMUL_INTREG_DEC;
if (receivedCmd_dec[0] == MIFARE_CMD_RESTORE)
cardSTATE = MFEMUL_INTREG_REST;
break;
}
if (receivedCmd_dec[0] == MIFARE_CMD_TRANSFER) {
uint8_t blockNo = receivedCmd_dec[1];
if (emlSetValBl(cardINTREG, cardINTBLOCK, receivedCmd_dec[1]))
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
else
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK));
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("RECV 0x%02x transfer block %d (%02x)",receivedCmd_dec[0], blockNo, blockNo);
break;
}
// command not allowed
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Received command not allowed, nacking");
cardSTATE = MFEMUL_IDLE;
break;
}
case MFEMUL_AUTH1:{
if (receivedCmd_len != 8) {
cardSTATE = MFEMUL_IDLE;
break;
}
uint32_t nr = bytes_to_num(receivedCmd, 4);
uint32_t ar = bytes_to_num(&receivedCmd[4], 4);
// Collect AR/NR per keytype & sector
if(flags & FLAG_NR_AR_ATTACK) {
for (uint8_t i = 0; i < ATTACK_KEY_COUNT; i++) {
if ( ar_nr_collected[i+mM]==0 || ((cardAUTHSC == ar_nr_resp[i+mM].sector) && (cardAUTHKEY == ar_nr_resp[i+mM].keytype) && (ar_nr_collected[i+mM] > 0)) ) {
// if first auth for sector, or matches sector and keytype of previous auth
if (ar_nr_collected[i+mM] < 2) {
// if we haven't already collected 2 nonces for this sector
if (ar_nr_resp[ar_nr_collected[i+mM]].ar != ar) {
// Avoid duplicates... probably not necessary, ar should vary.
if (ar_nr_collected[i+mM]==0) {
// first nonce collect
ar_nr_resp[i+mM].cuid = cuid;
ar_nr_resp[i+mM].sector = cardAUTHSC;
ar_nr_resp[i+mM].keytype = cardAUTHKEY;
ar_nr_resp[i+mM].nonce = nonce;
ar_nr_resp[i+mM].nr = nr;
ar_nr_resp[i+mM].ar = ar;
nonce1_count++;
// add this nonce to first moebius nonce
ar_nr_resp[i+ATTACK_KEY_COUNT].cuid = cuid;
ar_nr_resp[i+ATTACK_KEY_COUNT].sector = cardAUTHSC;
ar_nr_resp[i+ATTACK_KEY_COUNT].keytype = cardAUTHKEY;
ar_nr_resp[i+ATTACK_KEY_COUNT].nonce = nonce;
ar_nr_resp[i+ATTACK_KEY_COUNT].nr = nr;
ar_nr_resp[i+ATTACK_KEY_COUNT].ar = ar;
ar_nr_collected[i+ATTACK_KEY_COUNT]++;
} else { // second nonce collect (std and moebius)
ar_nr_resp[i+mM].nonce2 = nonce;
ar_nr_resp[i+mM].nr2 = nr;
ar_nr_resp[i+mM].ar2 = ar;
if (!gettingMoebius) {
nonce2_count++;
// check if this was the last second nonce we need for std attack
if ( nonce2_count == nonce1_count ) {
// done collecting std test switch to moebius
// first finish incrementing last sample
ar_nr_collected[i+mM]++;
// switch to moebius collection
gettingMoebius = true;
mM = ATTACK_KEY_COUNT;
if (flags & FLAG_RANDOM_NONCE) {
nonce = prand();
} else {
nonce = nonce*7;
}
break;
}
} else {
moebius_n_count++;
// if we've collected all the nonces we need - finish.
if (nonce1_count == moebius_n_count) finished = true;
}
}
ar_nr_collected[i+mM]++;
}
}
// we found right spot for this nonce stop looking
break;
}
}
}
// --- crypto
crypto1_word(pcs, nr , 1);
cardRr = ar ^ crypto1_word(pcs, 0, 0);
// test if auth OK
if (cardRr != prng_successor(nonce, 64)){
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("AUTH FAILED for sector %d with key %c. cardRr=%08x, succ=%08x",
cardAUTHSC, cardAUTHKEY == AUTHKEYA ? 'A' : 'B',
cardRr, prng_successor(nonce, 64));
// Shouldn't we respond anything here?
// Right now, we don't nack or anything, which causes the
// reader to do a WUPA after a while. /Martin
// -- which is the correct response. /piwi
cardAUTHKEY = AUTHKEYNONE; // not authenticated
cardSTATE = MFEMUL_IDLE;
break;
}
ans = prng_successor(nonce, 96);
num_to_bytes(ans, 4, response);
mf_crypto1_encrypt(pcs, response, 4, response_par);
EmSendCmdPar(response, 4, response_par);
FpgaDisableTracing();
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("AUTH COMPLETED for sector %d with key %c.", cardAUTHSC, cardAUTHKEY == AUTHKEYA ? 'A' : 'B');
cardSTATE = MFEMUL_WORK;
break;
}
case MFEMUL_WRITEBL2:{
if (receivedCmd_len == 18) {
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, receivedCmd_dec);
if (HasValidCRC(receivedCmd_dec, receivedCmd_len)) {
if (IsSectorTrailer(cardWRBL)) {
emlGetMem(response, cardWRBL, 1);
if (!IsAccessAllowed(cardWRBL, cardAUTHKEY, AC_KEYA_WRITE)) {
memcpy(receivedCmd_dec, response, 6); // don't change KeyA
}
if (!IsAccessAllowed(cardWRBL, cardAUTHKEY, AC_KEYB_WRITE)) {
memcpy(receivedCmd_dec+10, response+10, 6); // don't change KeyA
}
if (!IsAccessAllowed(cardWRBL, cardAUTHKEY, AC_AC_WRITE)) {
memcpy(receivedCmd_dec+6, response+6, 4); // don't change AC bits
}
} else {
if (!IsAccessAllowed(cardWRBL, cardAUTHKEY, AC_DATA_WRITE)) {
memcpy(receivedCmd_dec, response, 16); // don't change anything
}
}
emlSetMem(receivedCmd_dec, cardWRBL, 1);
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_ACK)); // always ACK?
cardSTATE = MFEMUL_WORK;
break;
}
}
cardSTATE = MFEMUL_IDLE;
break;
}
case MFEMUL_INTREG_INC:{
if (receivedCmd_len == 6) {
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, (uint8_t*)&ans);
if (emlGetValBl(&cardINTREG, &cardINTBLOCK, cardWRBL)) {
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
cardSTATE = MFEMUL_IDLE;
break;
}
cardINTREG = cardINTREG + ans;
cardSTATE = MFEMUL_WORK;
}
break;
}
case MFEMUL_INTREG_DEC:{
if (receivedCmd_len == 6) {
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, (uint8_t*)&ans);
if (emlGetValBl(&cardINTREG, &cardINTBLOCK, cardWRBL)) {
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
cardSTATE = MFEMUL_IDLE;
break;
}
cardINTREG = cardINTREG - ans;
cardSTATE = MFEMUL_WORK;
}
break;
}
case MFEMUL_INTREG_REST:{
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, (uint8_t*)&ans);
if (emlGetValBl(&cardINTREG, &cardINTBLOCK, cardWRBL)) {
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
cardSTATE = MFEMUL_IDLE;
break;
}
cardSTATE = MFEMUL_WORK;
break;
}
} // end of switch
FpgaDisableTracing();
button_pushed = BUTTON_PRESS();
} // end of while
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LEDsoff();
if(flags & FLAG_NR_AR_ATTACK && MF_DBGLEVEL >= MF_DBG_INFO) {
for ( uint8_t i = 0; i < ATTACK_KEY_COUNT; i++) {
if (ar_nr_collected[i] == 2) {
Dbprintf("Collected two pairs of AR/NR which can be used to extract %s from reader for sector %d:", (i<ATTACK_KEY_COUNT/2) ? "keyA" : "keyB", ar_nr_resp[i].sector);
Dbprintf("../tools/mfkey/mfkey32 %08x %08x %08x %08x %08x %08x",
ar_nr_resp[i].cuid, //UID
ar_nr_resp[i].nonce, //NT
ar_nr_resp[i].nr, //NR1
ar_nr_resp[i].ar, //AR1
ar_nr_resp[i].nr2, //NR2
ar_nr_resp[i].ar2 //AR2
);
}
}
for ( uint8_t i = ATTACK_KEY_COUNT; i < ATTACK_KEY_COUNT*2; i++) {
if (ar_nr_collected[i] == 2) {
Dbprintf("Collected two pairs of AR/NR which can be used to extract %s from reader for sector %d:", (i<ATTACK_KEY_COUNT/2) ? "keyA" : "keyB", ar_nr_resp[i].sector);
Dbprintf("../tools/mfkey/mfkey32 %08x %08x %08x %08x %08x %08x %08x",
ar_nr_resp[i].cuid, //UID
ar_nr_resp[i].nonce, //NT
ar_nr_resp[i].nr, //NR1
ar_nr_resp[i].ar, //AR1
ar_nr_resp[i].nonce2,//NT2
ar_nr_resp[i].nr2, //NR2
ar_nr_resp[i].ar2 //AR2
);
}
}
}
if (MF_DBGLEVEL >= MF_DBG_INFO) Dbprintf("Emulator stopped. Tracing: %d trace length: %d ", get_tracing(), BigBuf_get_traceLen());
if(flags & FLAG_INTERACTIVE) { // Interactive mode flag, means we need to send ACK
//Send the collected ar_nr in the response
cmd_send(CMD_ACK, CMD_SIMULATE_MIFARE_CARD, button_pushed, 0, &ar_nr_resp, sizeof(ar_nr_resp));
}
LED_A_OFF();
}

20
armsrc/mifaresim.h Normal file
View file

@ -0,0 +1,20 @@
//-----------------------------------------------------------------------------
// Merlok - June 2011, 2012
// Gerhard de Koning Gans - May 2008
// Hagen Fritsch - June 2010
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Mifare Classic Card Simulation
//-----------------------------------------------------------------------------
#ifndef __MIFARESIM_H
#define __MIFARESIM_H
#include <stdint.h>
extern void MifareSim(uint8_t flags, uint8_t exitAfterNReads, uint8_t cardsize, uint8_t *datain);
#endif

View file

@ -1,173 +1,169 @@
//-----------------------------------------------------------------------------
// Merlok - 2012
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Routines to support mifare classic sniffer.
//-----------------------------------------------------------------------------
#include "mifaresniff.h"
#include "apps.h"
static int sniffState = SNF_INIT;
static uint8_t sniffUIDType;
static uint8_t sniffUID[8];
static uint8_t sniffATQA[2];
static uint8_t sniffSAK;
static uint8_t sniffBuf[16];
static uint32_t timerData = 0;
bool MfSniffInit(void){
memset(sniffUID, 0x00, 8);
memset(sniffATQA, 0x00, 2);
sniffSAK = 0;
sniffUIDType = SNF_UID_4;
return FALSE;
}
bool MfSniffEnd(void){
LED_B_ON();
cmd_send(CMD_ACK,0,0,0,0,0);
LED_B_OFF();
return FALSE;
}
bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint32_t parity, uint16_t bitCnt, bool reader) {
if (reader && (len == 1) && (bitCnt == 7)) { // reset on 7-Bit commands from reader
sniffState = SNF_INIT;
}
switch (sniffState) {
case SNF_INIT:{
if ((len == 1) && (reader) && (bitCnt == 7) ) { // REQA or WUPA from reader
sniffUIDType = SNF_UID_4;
memset(sniffUID, 0x00, 8);
memset(sniffATQA, 0x00, 2);
sniffSAK = 0;
sniffState = SNF_WUPREQ;
}
break;
}
case SNF_WUPREQ:{
if ((!reader) && (len == 2)) { // ATQA from tag
memcpy(sniffATQA, data, 2);
sniffState = SNF_ATQA;
}
break;
}
case SNF_ATQA:{
if ((reader) && (len == 2) && (data[0] == 0x93) && (data[1] == 0x20)) { // Select ALL from reader
sniffState = SNF_ANTICOL1;
}
break;
}
case SNF_ANTICOL1:{
if ((!reader) && (len == 5) && ((data[0] ^ data[1] ^ data[2] ^ data[3]) == data[4])) { // UID from tag (CL1)
memcpy(sniffUID + 3, data, 4);
sniffState = SNF_UID1;
}
break;
}
//-----------------------------------------------------------------------------
// Merlok - 2012
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Routines to support mifare classic sniffer.
//-----------------------------------------------------------------------------
#include "mifaresniff.h"
#include "proxmark3.h"
#include "util.h"
#include "string.h"
#include "iso14443crc.h"
#include "iso14443a.h"
#include "crapto1/crapto1.h"
#include "mifareutil.h"
#include "common.h"
#include "usb_cdc.h"
#include "BigBuf.h"
#include "fpgaloader.h"
static int sniffState = SNF_INIT;
static uint8_t sniffUIDType;
static uint8_t sniffUID[8] = {0x00};
static uint8_t sniffATQA[2] = {0x00};
static uint8_t sniffSAK;
static uint8_t sniffBuf[16] = {0x00};
static uint32_t timerData = 0;
bool MfSniffInit(void){
memset(sniffUID, 0x00, 8);
memset(sniffATQA, 0x00, 2);
sniffSAK = 0;
sniffUIDType = SNF_UID_4;
return false;
}
bool MfSniffEnd(void){
LED_B_ON();
cmd_send(CMD_ACK,0,0,0,0,0);
LED_B_OFF();
return false;
}
bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, uint16_t bitCnt, bool reader) {
if (reader && (len == 1) && (bitCnt == 7)) { // reset on 7-Bit commands from reader
sniffState = SNF_INIT;
}
switch (sniffState) {
case SNF_INIT:{
if ((len == 1) && (reader) && (bitCnt == 7) ) { // REQA or WUPA from reader
sniffUIDType = SNF_UID_4;
memset(sniffUID, 0x00, 8);
memset(sniffATQA, 0x00, 2);
sniffSAK = 0;
sniffState = SNF_ATQA;
if (data[0] == 0x40)
sniffState = SNF_MAGIC_WUPC2;
}
break;
}
case SNF_MAGIC_WUPC2:
if ((len == 1) && (reader) && (data[0] == 0x43) ) {
sniffState = SNF_CARD_IDLE;
}
break;
case SNF_ATQA:{
if ((!reader) && (len == 2)) { // ATQA from tag
memcpy(sniffATQA, data, 2);
sniffState = SNF_UID1;
}
break;
}
case SNF_UID1:{
if ((reader) && (len == 9) && (data[0] == 0x93) && (data[1] == 0x70) && (CheckCrc14443(CRC_14443_A, data, 9))) { // Select 4 Byte UID from reader
memcpy(sniffUID + 3, &data[2], 4);
sniffState = SNF_SAK;
}
break;
}
case SNF_SAK:{
if ((!reader) && (len == 3) && (CheckCrc14443(CRC_14443_A, data, 3))) { // SAK from card?
sniffSAK = data[0];
if (sniffUID[3] == 0x88) { // CL2 UID part to be expected
sniffState = SNF_ANTICOL2;
} else { // select completed
sniffState = SNF_CARD_IDLE;
}
}
break;
}
case SNF_ANTICOL2:{
if ((!reader) && (len == 5) && ((data[0] ^ data[1] ^ data[2] ^ data[3]) == data[4])) { // CL2 UID
memcpy(sniffUID, sniffUID+4, 3);
memcpy(sniffUID+3, data, 4);
sniffUIDType = SNF_UID_7;
sniffState = SNF_UID2;
}
break;
break;
}
case SNF_SAK:{
if ((!reader) && (len == 3) && (CheckCrc14443(CRC_14443_A, data, 3))) { // SAK from card?
sniffSAK = data[0];
if ((sniffUID[3] == 0x88) && (sniffUIDType == SNF_UID_4)) { // CL2 UID part to be expected
sniffUIDType = SNF_UID_7;
memcpy(sniffUID, sniffUID + 4, 3);
sniffState = SNF_UID2;
} else { // select completed
sniffState = SNF_CARD_IDLE;
}
}
break;
}
case SNF_UID2:{
if ((reader) && (len == 9) && (data[0] == 0x95) && (data[1] == 0x70) && (CheckCrc14443(CRC_14443_A, data, 9))) { // Select 2nd part of 7 Byte UID
if ((reader) && (len == 9) && (data[0] == 0x95) && (data[1] == 0x70) && (CheckCrc14443(CRC_14443_A, data, 9))) {
memcpy(sniffUID + 3, &data[2], 4);
sniffState = SNF_SAK;
}
break;
}
case SNF_CARD_IDLE:{ // trace the card select sequence
sniffBuf[0] = 0xFF;
sniffBuf[1] = 0xFF;
memcpy(sniffBuf + 2, sniffUID, 7);
memcpy(sniffBuf + 9, sniffATQA, 2);
sniffBuf[11] = sniffSAK;
sniffBuf[12] = 0xFF;
sniffBuf[13] = 0xFF;
LogTrace(sniffBuf, 14, 0, parity, true);
} // intentionally no break;
case SNF_CARD_CMD:{
LogTrace(data, len, 0, parity, true);
sniffState = SNF_CARD_RESP;
timerData = GetTickCount();
break;
}
case SNF_CARD_RESP:{
LogTrace(data, len, 0, parity, false);
sniffState = SNF_CARD_CMD;
timerData = GetTickCount();
break;
}
default:
sniffState = SNF_INIT;
break;
}
return FALSE;
}
bool RAMFUNC MfSniffSend(uint16_t maxTimeoutMs) {
if (traceLen && (GetTickCount() > timerData + maxTimeoutMs)) {
return intMfSniffSend();
}
return FALSE;
}
// internal sending function. not a RAMFUNC.
bool intMfSniffSend() {
int pckSize = 0;
int pckLen = traceLen;
int pckNum = 0;
FpgaDisableSscDma();
while (pckLen > 0) {
pckSize = MIN(USB_CMD_DATA_SIZE, pckLen);
LED_B_ON();
cmd_send(CMD_ACK, 1, pckSize, pckNum, trace + traceLen - pckLen, pckSize);
LED_B_OFF();
pckLen -= pckSize;
pckNum++;
}
LED_B_ON();
cmd_send(CMD_ACK,2,0,0,0,0);
LED_B_OFF();
iso14a_clear_trace();
return TRUE;
}
case SNF_CARD_IDLE:{ // trace the card select sequence
sniffBuf[0] = 0xFF;
sniffBuf[1] = 0xFF;
memcpy(sniffBuf + 2, sniffUID, 7);
memcpy(sniffBuf + 9, sniffATQA, 2);
sniffBuf[11] = sniffSAK;
sniffBuf[12] = 0xFF;
sniffBuf[13] = 0xFF;
LogTrace(sniffBuf, 14, 0, 0, NULL, true);
sniffState = SNF_CARD_CMD;
} // intentionally no break;
case SNF_CARD_CMD:{
LogTrace(data, len, 0, 0, parity, reader);
timerData = GetTickCount();
break;
}
default:
sniffState = SNF_INIT;
break;
}
return false;
}
bool RAMFUNC MfSniffSend(uint16_t maxTimeoutMs) {
if (BigBuf_get_traceLen() && (GetTickCount() > timerData + maxTimeoutMs)) {
return intMfSniffSend();
}
return false;
}
// internal sending function. not a RAMFUNC.
bool intMfSniffSend() {
int pckSize = 0;
int pckLen = BigBuf_get_traceLen();
int pckNum = 0;
uint8_t *trace = BigBuf_get_addr();
FpgaDisableSscDma();
while (pckLen > 0) {
pckSize = MIN(USB_CMD_DATA_SIZE, pckLen);
LED_B_ON();
cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, 1, BigBuf_get_traceLen(), pckSize, trace + BigBuf_get_traceLen() - pckLen, pckSize);
LED_B_OFF();
pckLen -= pckSize;
pckNum++;
}
LED_B_ON();
cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K,2,0,0,0,0);
LED_B_OFF();
clear_trace();
return true;
}

View file

@ -11,37 +11,31 @@
#ifndef __MIFARESNIFF_H
#define __MIFARESNIFF_H
#include "proxmark3.h"
#include "apps.h"
#include <stdint.h>
#include <stdbool.h>
#include "util.h"
#include "string.h"
#include "iso14443crc.h"
#include "iso14443a.h"
#include "crapto1.h"
#include "mifareutil.h"
#include "common.h"
#define SNF_INIT 0
#define SNF_NO_FIELD 1
#define SNF_WUPREQ 2
#define SNF_NO_FIELD 1
#define SNF_WUPREQ 2
#define SNF_ATQA 3
#define SNF_ANTICOL1 4
#define SNF_ANTICOL1 4
#define SNF_UID1 5
#define SNF_ANTICOL2 6
#define SNF_ANTICOL2 6
#define SNF_UID2 7
#define SNF_SAK 8
#define SNF_CARD_IDLE 9
#define SNF_CARD_CMD 10
#define SNF_CARD_RESP 11
#define SNF_CARD_IDLE 9
#define SNF_CARD_CMD 10
#define SNF_CARD_RESP 11
#define SNF_MAGIC_WUPC2 12
#define SNF_UID_4 0
#define SNF_UID_7 0
bool MfSniffInit(void);
bool RAMFUNC MfSniffLogic(const uint8_t * data, uint16_t len, uint32_t parity, uint16_t bitCnt, bool reader);
bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, uint16_t bitCnt, bool reader);
bool RAMFUNC MfSniffSend(uint16_t maxTimeoutMs);
bool intMfSniffSend();
bool MfSniffEnd(void);
#endif
#endif

File diff suppressed because it is too large Load diff

View file

@ -9,76 +9,71 @@
// code for work with mifare cards.
//-----------------------------------------------------------------------------
#ifndef __MIFAREUTIL_H
#define __MIFAREUTIL_H
#ifndef MIFAREUTIL_H__
#define MIFAREUTIL_H__
#include <stdint.h>
#include <stdbool.h>
#include "crapto1/crapto1.h"
#include "usb_cdc.h"
// mifare authentication
#define CRYPT_NONE 0
#define CRYPT_ALL 1
#define CRYPT_REQUEST 2
#define AUTH_FIRST 0
#define AUTH_NESTED 2
// mifare 4bit card answers
#define CARD_ACK 0x0A // 1010 - ACK
#define CARD_NACK_NA 0x04 // 0100 - NACK, not allowed (command not allowed)
#define CARD_NACK_TR 0x05 // 0101 - NACK, transmission error
#define CRYPT_NONE 0
#define CRYPT_ALL 1
#define CRYPT_REQUEST 2
#define AUTH_FIRST 0
#define AUTH_NESTED 2
// reader voltage field detector
#define MF_MINFIELDV 4000
// debug
// 0 - no debug messages 1 - error messages 2 - all messages 4 - extended debug mode
#define MF_DBG_NONE 0
#define MF_DBG_ERROR 1
#define MF_DBG_ALL 2
#define MF_DBG_EXTENDED 4
#define MF_DBG_NONE 0 // no messages
#define MF_DBG_ERROR 1 // errors only
#define MF_DBG_INFO 2 // errors + info messages
#define MF_DBG_DEBUG 3 // errors + info + debug messages
#define MF_DBG_EXTENDED 4 // errors + info + debug + breaking debug messages
extern int MF_DBGLEVEL;
//mifare emulator states
#define MFEMUL_NOFIELD 0
#define MFEMUL_IDLE 1
#define MFEMUL_SELECT1 2
#define MFEMUL_SELECT2 3
#define MFEMUL_AUTH1 4
#define MFEMUL_AUTH2 5
#define MFEMUL_WORK 6
#define MFEMUL_WRITEBL2 7
#define MFEMUL_INTREG_INC 8
#define MFEMUL_INTREG_DEC 9
#define MFEMUL_INTREG_REST 10
#define MFEMUL_HALTED 11
//functions
int mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing);
int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing);
#define cardSTATE_TO_IDLE() cardSTATE = MFEMUL_IDLE; LED_B_OFF(); LED_C_OFF();
// mifare classic
int mifare_classic_auth(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested, uint32_t *auth_timeout);
int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested, uint32_t * ntptr, uint32_t *timing, uint32_t *auth_timeout);
int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData);
int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid);
int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData);
//functions
uint8_t* mifare_get_bigbufptr(void);
int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t* answer, uint32_t *timing);
int mifare_sendcmd_short_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t *data, uint8_t* amswer, uint8_t *timing);
int mifare_sendcmd_shortex(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t* answer, uint32_t * parptr, uint32_t *timing);
int mifare_classic_auth(struct Crypto1State *pcs, uint32_t uid, \
uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint64_t isNested);
int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, \
uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint64_t isNested, uint32_t * ntptr, uint32_t *timing);
int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData);
int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData);
int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData);
int mifare_ultra_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData);
int mifare_ultra_special_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData);
int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid);
int mifare_ultra_halt(uint32_t uid);
// crypto functions
void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *receivedCmd, int len);
void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, int len, uint32_t *par);
// Ultralight/NTAG...
int mifare_ul_ev1_auth(uint8_t *key, uint8_t *pack);
int mifare_ultra_auth(uint8_t *key);
int mifare_ultra_readblock(uint8_t blockNo, uint8_t *blockData);
//int mifare_ultra_writeblock_compat(uint8_t blockNo, uint8_t *blockData);
int mifare_ultra_writeblock(uint8_t blockNo, uint8_t *blockData);
int mifare_ultra_halt();
// desfire
int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t* data, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing);
int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t* data, uint8_t* answer,uint8_t *answer_parity, uint32_t *timing);
int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData);
int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData);
// crypto functions
void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *receivedCmd, int len);
void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, uint8_t *data_out);
void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, uint8_t *par);
void mf_crypto1_encryptEx(struct Crypto1State *pcs, uint8_t *data, uint8_t *in, uint16_t len, uint8_t *par);
uint8_t mf_crypto1_encrypt4bit(struct Crypto1State *pcs, uint8_t data);
// memory management
uint8_t* mifare_get_bigbufptr(void);
uint8_t* eml_get_bigbufptr_sendbuf(void);
uint8_t* eml_get_bigbufptr_recbuf(void);
// Mifare memory structure
uint8_t NumBlocksPerSector(uint8_t sectorNo);
uint8_t FirstBlockOfSector(uint8_t sectorNo);
bool IsSectorTrailer(uint8_t blockNo);
uint8_t SectorTrailer(uint8_t blockNo);
// emulator functions
void emlClearMem(void);
@ -87,7 +82,13 @@ void emlGetMem(uint8_t *data, int blockNum, int blocksCount);
void emlGetMemBt(uint8_t *data, int bytePtr, int byteCount);
uint64_t emlGetKey(int sectorNum, int keyType);
int emlGetValBl(uint32_t *blReg, uint8_t *blBlock, int blockNum);
int emlSetValBl(uint32_t blReg, uint8_t blBlock, int blockNum);
int emlCheckValBl(int blockNum);
#endif
int emlSetValBl(uint32_t blReg, uint8_t blBlock, int blockNum);
int emlCheckValBl(int blockNum);
// mifare check keys
typedef uint8_t TKeyIndex[2][40];
int MifareChkBlockKeysFixedNonce(uint8_t *ar_par, uint8_t ar_par_cnt, uint8_t blockNo, uint8_t keyType, uint32_t *auth_timeout, uint8_t debugLevel);
int MifareChkBlockKeys(uint8_t *keys, uint8_t keyCount, uint8_t blockNo, uint8_t keyType, uint32_t *auth_timeout, uint8_t debugLevel);
int MifareMultisectorChk(uint8_t *keys, uint8_t keyCount, uint8_t SectorCount, uint8_t keyType, uint32_t *auth_timeout, uint8_t debugLevel, TKeyIndex *keyIndex);
#endif

300
armsrc/optimized_cipher.c Normal file
View file

@ -0,0 +1,300 @@
/*****************************************************************************
* WARNING
*
* THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY.
*
* USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL
* PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL,
* AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES.
*
* THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS.
*
*****************************************************************************
*
* This file is part of loclass. It is a reconstructon of the cipher engine
* used in iClass, and RFID techology.
*
* The implementation is based on the work performed by
* Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
* Milosch Meriac in the paper "Dismantling IClass".
*
* Copyright (C) 2014 Martin Holst Swende
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, or, at your option, any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with loclass. If not, see <http://www.gnu.org/licenses/>.
*
*
*
****************************************************************************/
/**
This file contains an optimized version of the MAC-calculation algorithm. Some measurements on
a std laptop showed it runs in about 1/3 of the time:
Std: 0.428962
Opt: 0.151609
Additionally, it is self-reliant, not requiring e.g. bitstreams from the cipherutils, thus can
be easily dropped into a code base.
The optimizations have been performed in the following steps:
* Parameters passed by reference instead of by value.
* Iteration instead of recursion, un-nesting recursive loops into for-loops.
* Handling of bytes instead of individual bits, for less shuffling and masking
* Less creation of "objects", structs, and instead reuse of alloc:ed memory
* Inlining some functions via #define:s
As a consequence, this implementation is less generic. Also, I haven't bothered documenting this.
For a thorough documentation, check out the MAC-calculation within cipher.c instead.
-- MHS 2015
**/
/**
The runtime of opt_doTagMAC_2() with the MHS optimized version was 403 microseconds on Proxmark3.
This was still to slow for some newer readers which didn't want to wait that long.
Further optimizations to speedup the MAC calculations:
* Optimized opt_Tt logic
* Look up table for opt_select
* Removing many unnecessary bit maskings (& 0x1)
* updating state in place instead of alternating use of a second state structure
* remove the necessity to reverse bits of input and output bytes
opt_doTagMAC_2() now completes in 270 microseconds.
-- piwi 2019
**/
#include "optimized_cipher.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "string.h"
static const uint8_t opt_select_LUT[256] = {
00, 03, 02, 01, 02, 03, 00, 01, 04, 07, 07, 04, 06, 07, 05, 04,
01, 02, 03, 00, 02, 03, 00, 01, 05, 06, 06, 05, 06, 07, 05, 04,
06, 05, 04, 07, 04, 05, 06, 07, 06, 05, 05, 06, 04, 05, 07, 06,
07, 04, 05, 06, 04, 05, 06, 07, 07, 04, 04, 07, 04, 05, 07, 06,
06, 05, 04, 07, 04, 05, 06, 07, 02, 01, 01, 02, 00, 01, 03, 02,
03, 00, 01, 02, 00, 01, 02, 03, 07, 04, 04, 07, 04, 05, 07, 06,
00, 03, 02, 01, 02, 03, 00, 01, 00, 03, 03, 00, 02, 03, 01, 00,
05, 06, 07, 04, 06, 07, 04, 05, 05, 06, 06, 05, 06, 07, 05, 04,
02, 01, 00, 03, 00, 01, 02, 03, 06, 05, 05, 06, 04, 05, 07, 06,
03, 00, 01, 02, 00, 01, 02, 03, 07, 04, 04, 07, 04, 05, 07, 06,
02, 01, 00, 03, 00, 01, 02, 03, 02, 01, 01, 02, 00, 01, 03, 02,
03, 00, 01, 02, 00, 01, 02, 03, 03, 00, 00, 03, 00, 01, 03, 02,
04, 07, 06, 05, 06, 07, 04, 05, 00, 03, 03, 00, 02, 03, 01, 00,
01, 02, 03, 00, 02, 03, 00, 01, 05, 06, 06, 05, 06, 07, 05, 04,
04, 07, 06, 05, 06, 07, 04, 05, 04, 07, 07, 04, 06, 07, 05, 04,
01, 02, 03, 00, 02, 03, 00, 01, 01, 02, 02, 01, 02, 03, 01, 00
};
/********************** the table above has been generated with this code: ********
#include "util.h"
static void init_opt_select_LUT(void) {
for (int r = 0; r < 256; r++) {
uint8_t r_ls2 = r << 2;
uint8_t r_and_ls2 = r & r_ls2;
uint8_t r_or_ls2 = r | r_ls2;
uint8_t z0 = (r_and_ls2 >> 5) ^ ((r & ~r_ls2) >> 4) ^ ( r_or_ls2 >> 3);
uint8_t z1 = (r_or_ls2 >> 6) ^ ( r_or_ls2 >> 1) ^ (r >> 5) ^ r;
uint8_t z2 = ((r & ~r_ls2) >> 4) ^ (r_and_ls2 >> 3) ^ r;
opt_select_LUT[r] = (z0 & 4) | (z1 & 2) | (z2 & 1);
}
print_result("", opt_select_LUT, 256);
}
***********************************************************************************/
#define opt__select(x,y,r) (4 & (((r & (r << 2)) >> 5) ^ ((r & ~(r << 2)) >> 4) ^ ( (r | r << 2) >> 3)))\
|(2 & (((r | r << 2) >> 6) ^ ( (r | r << 2) >> 1) ^ (r >> 5) ^ r ^ ((x^y) << 1)))\
|(1 & (((r & ~(r << 2)) >> 4) ^ ((r & (r << 2)) >> 3) ^ r ^ x))
/*
* Some background on the expression above can be found here...
uint8_t xopt__select(bool x, bool y, uint8_t r)
{
//r: r0 r1 r2 r3 r4 r5 r6 r7
//r_ls2: r2 r3 r4 r5 r6 r7 0 0
// z0
// z1
// uint8_t z0 = (r0 & r2) ^ (r1 & ~r3) ^ (r2 | r4); // <-- original
uint8_t z0 = (r_and_ls2 >> 5) ^ ((r & ~r_ls2) >> 4) ^ ( r_or_ls2 >> 3);
// uint8_t z1 = (r0 | r2) ^ ( r5 | r7) ^ r1 ^ r6 ^ x ^ y; // <-- original
uint8_t z1 = (r_or_ls2 >> 6) ^ ( r_or_ls2 >> 1) ^ (r >> 5) ^ r ^ ((x^y) << 1);
// uint8_t z2 = (r3 & ~r5) ^ (r4 & r6 ) ^ r7 ^ x; // <-- original
uint8_t z2 = ((r & ~r_ls2) >> 4) ^ (r_and_ls2 >> 3) ^ r ^ x;
return (z0 & 4) | (z1 & 2) | (z2 & 1);
}
*/
static void opt_successor(const uint8_t *k, State *s, uint8_t y) {
// #define opt_T(s) (0x1 & ((s->t >> 15) ^ (s->t >> 14) ^ (s->t >> 10) ^ (s->t >> 8) ^ (s->t >> 5) ^ (s->t >> 4)^ (s->t >> 1) ^ s->t))
// uint8_t Tt = opt_T(s);
uint16_t Tt = s->t & 0xc533;
Tt = Tt ^ (Tt >> 1);
Tt = Tt ^ (Tt >> 4);
Tt = Tt ^ (Tt >> 10);
Tt = Tt ^ (Tt >> 8);
s->t = (s->t >> 1);
s->t |= (Tt ^ (s->r >> 7) ^ (s->r >> 3)) << 15;
uint8_t opt_B = s->b;
opt_B ^= s->b >> 6;
opt_B ^= s->b >> 5;
opt_B ^= s->b >> 4;
s->b = s->b >> 1;
s->b |= (opt_B ^ s->r) << 7;
uint8_t opt_select = opt_select_LUT[s->r] & 0x04;
opt_select |= (opt_select_LUT[s->r] ^ ((Tt ^ y) << 1)) & 0x02;
opt_select |= (opt_select_LUT[s->r] ^ Tt) & 0x01;
uint8_t r = s->r;
s->r = (k[opt_select] ^ s->b) + s->l ;
s->l = s->r + r;
}
static void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes) {
for (int i = 0; i < length; i++) {
uint8_t head;
head = in[i];
opt_successor(k, s, head);
head >>= 1;
opt_successor(k, s, head);
head >>= 1;
opt_successor(k, s, head);
head >>= 1;
opt_successor(k, s, head);
head >>= 1;
opt_successor(k, s, head);
head >>= 1;
opt_successor(k, s, head);
head >>= 1;
opt_successor(k, s, head);
head >>= 1;
opt_successor(k, s, head);
}
//For tag MAC, an additional 32 zeroes
if (add32Zeroes) {
for(int i = 0; i < 16; i++) {
opt_successor(k, s, 0);
opt_successor(k, s, 0);
}
}
}
static void opt_output(const uint8_t *k, State *s, uint8_t *buffer) {
for (uint8_t times = 0; times < 4; times++) {
uint8_t bout = 0;
bout |= (s->r & 0x4) >> 2;
opt_successor(k, s, 0);
bout |= (s->r & 0x4) >> 1;
opt_successor(k, s, 0);
bout |= (s->r & 0x4);
opt_successor(k, s, 0);
bout |= (s->r & 0x4) << 1;
opt_successor(k, s, 0);
bout |= (s->r & 0x4) << 2;
opt_successor(k, s, 0);
bout |= (s->r & 0x4) << 3;
opt_successor(k, s, 0);
bout |= (s->r & 0x4) << 4;
opt_successor(k, s, 0);
bout |= (s->r & 0x4) << 5;
opt_successor(k, s, 0);
buffer[times] = bout;
}
}
static void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out) {
State _init = {
((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l
((k[0] ^ 0x4c) + 0x21) & 0xFF,// r
0x4c, // b
0xE012 // t
};
opt_suc(k, &_init, input, 12, false);
//printf("\noutp ");
opt_output(k, &_init, out);
}
void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) {
uint8_t dest[] = {0, 0, 0, 0, 0, 0, 0, 0};
opt_MAC(div_key_p, cc_nr_p, dest);
memcpy(mac, dest, 4);
return;
}
void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4]) {
State _init = {
((div_key_p[0] ^ 0x4c) + 0xEC) & 0xFF,// l
((div_key_p[0] ^ 0x4c) + 0x21) & 0xFF,// r
0x4c, // b
0xE012 // t
};
opt_suc(div_key_p, &_init, cc_p, 12, true);
opt_output(div_key_p, &_init, mac);
return;
}
/**
* The tag MAC can be divided (both can, but no point in dividing the reader mac) into
* two functions, since the first 8 bytes are known, we can pre-calculate the state
* reached after feeding CC to the cipher.
* @param cc_p
* @param div_key_p
* @return the cipher state
*/
State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p) {
State _init = {
((div_key_p[0] ^ 0x4c) + 0xEC) & 0xFF,// l
((div_key_p[0] ^ 0x4c) + 0x21) & 0xFF,// r
0x4c, // b
0xE012 // t
};
opt_suc(div_key_p, &_init, cc_p, 8, false);
return _init;
}
/**
* The second part of the tag MAC calculation, since the CC is already calculated into the state,
* this function is fed only the NR, and internally feeds the remaining 32 0-bits to generate the tag
* MAC response.
* @param _init - precalculated cipher state
* @param nr - the reader challenge
* @param mac - where to store the MAC
* @param div_key_p - the key to use
*/
void opt_doTagMAC_2(State _init, uint8_t *nr, uint8_t mac[4], const uint8_t *div_key_p) {
opt_suc(div_key_p, &_init, nr, 4, true);
opt_output(div_key_p, &_init, mac);
return;
}

88
armsrc/optimized_cipher.h Normal file
View file

@ -0,0 +1,88 @@
/*****************************************************************************
* WARNING
*
* THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY.
*
* USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL
* PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL,
* AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES.
*
* THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS.
*
*****************************************************************************
*
* This file is part of loclass. It is a reconstructon of the cipher engine
* used in iClass, and RFID techology.
*
* The implementation is based on the work performed by
* Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
* Milosch Meriac in the paper "Dismantling IClass".
*
* Copyright (C) 2014 Martin Holst Swende
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, or, at your option, any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with loclass. If not, see <http://www.gnu.org/licenses/>.
*
*
****************************************************************************/
#ifndef OPTIMIZED_CIPHER_H__
#define OPTIMIZED_CIPHER_H__
#include <stdint.h>
/**
* Definition 1 (Cipher state). A cipher state of iClass s is an element of F 40/2
* consisting of the following four components:
* 1. the left register l = (l 0 . . . l 7 ) F 8/2 ;
* 2. the right register r = (r 0 . . . r 7 ) F 8/2 ;
* 3. the top register t = (t 0 . . . t 15 ) F 16/2 .
* 4. the bottom register b = (b 0 . . . b 7 ) F 8/2 .
**/
typedef struct {
uint8_t l;
uint8_t r;
uint8_t b;
uint16_t t;
} State;
/** The reader MAC is MAC(key, CC * NR )
**/
void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]);
/**
* The tag MAC is MAC(key, CC * NR * 32x0))
*/
void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4]);
/**
* The tag MAC can be divided (both can, but no point in dividing the reader mac) into
* two functions, since the first 8 bytes are known, we can pre-calculate the state
* reached after feeding CC to the cipher.
* @param cc_p
* @param div_key_p
* @return the cipher state
*/
State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p);
/**
* The second part of the tag MAC calculation, since the CC is already calculated into the state,
* this function is fed only the NR, and internally feeds the remaining 32 0-bits to generate the tag
* MAC response.
* @param _init - precalculated cipher state
* @param nr - the reader challenge
* @param mac - where to store the MAC
* @param div_key_p - the key to use
*/
void opt_doTagMAC_2(State _init, uint8_t *nr, uint8_t mac[4], const uint8_t *div_key_p);
#endif // OPTIMIZED_CIPHER_H__

589
armsrc/pcf7931.c Normal file
View file

@ -0,0 +1,589 @@
#include "proxmark3.h"
#include "apps.h"
#include "usb_cdc.h"
#include "lfsampling.h"
#include "pcf7931.h"
#include "util.h"
#include "string.h"
#include "fpgaloader.h"
#define T0_PCF 8 //period for the pcf7931 in us
#define ALLOC 16
size_t DemodPCF7931(uint8_t **outBlocks) {
uint8_t bits[256] = {0x00};
uint8_t blocks[8][16];
uint8_t *dest = BigBuf_get_addr();
int GraphTraceLen = BigBuf_max_traceLen();
if (GraphTraceLen > 18000)
GraphTraceLen = 18000;
int i, j, lastval, bitidx, half_switch;
int clock = 64;
int tolerance = clock / 8;
int pmc, block_done;
int lc, warnings = 0;
size_t num_blocks = 0;
int lmin=128, lmax=128;
uint8_t dir;
//clear read buffer
BigBuf_Clear_keep_EM();
LFSetupFPGAForADC(95, true);
DoAcquisition_default(0, true);
lmin = 64;
lmax = 192;
i = 2;
/* Find first local max/min */
if(dest[1] > dest[0]) {
while(i < GraphTraceLen) {
if( !(dest[i] > dest[i-1]) && dest[i] > lmax)
break;
i++;
}
dir = 0;
} else {
while(i < GraphTraceLen) {
if( !(dest[i] < dest[i-1]) && dest[i] < lmin)
break;
i++;
}
dir = 1;
}
lastval = i++;
half_switch = 0;
pmc = 0;
block_done = 0;
for (bitidx = 0; i < GraphTraceLen; i++) {
if ((dest[i-1] > dest[i] && dir == 1 && dest[i] > lmax) || (dest[i-1] < dest[i] && dir == 0 && dest[i] < lmin)) {
lc = i - lastval;
lastval = i;
// Switch depending on lc length:
// Tolerance is 1/8 of clock rate (arbitrary)
if (ABS(lc-clock/4) < tolerance) {
// 16T0
if((i - pmc) == lc) { /* 16T0 was previous one */
/* It's a PMC ! */
i += (128+127+16+32+33+16)-1;
lastval = i;
pmc = 0;
block_done = 1;
} else {
pmc = i;
}
} else if (ABS(lc-clock/2) < tolerance) {
// 32TO
if((i - pmc) == lc) { /* 16T0 was previous one */
/* It's a PMC ! */
i += (128+127+16+32+33)-1;
lastval = i;
pmc = 0;
block_done = 1;
} else if(half_switch == 1) {
bits[bitidx++] = 0;
half_switch = 0;
}
else
half_switch++;
} else if (ABS(lc-clock) < tolerance) {
// 64TO
bits[bitidx++] = 1;
} else {
// Error
if (++warnings > 10) {
Dbprintf("Error: too many detection errors, aborting.");
return 0;
}
}
if(block_done == 1) {
if(bitidx == 128) {
for(j = 0; j < 16; ++j) {
blocks[num_blocks][j] =
128 * bits[j*8 + 7]+
64 * bits[j*8 + 6] +
32 * bits[j*8 + 5] +
16 * bits[j*8 + 4] +
8 * bits[j*8 + 3] +
4 * bits[j*8 + 2] +
2 * bits[j*8 + 1] +
bits[j*8]
;
}
num_blocks++;
}
bitidx = 0;
block_done = 0;
half_switch = 0;
}
if(i < GraphTraceLen)
dir = (dest[i-1] > dest[i]) ? 0 : 1;
}
if(bitidx==255)
bitidx=0;
warnings = 0;
if(num_blocks == 4) break;
}
memcpy(outBlocks, blocks, 16 * num_blocks);
return num_blocks;
}
bool IsBlock0PCF7931(uint8_t *block) {
// assuming all RFU bits are set to 0
// if PAC is enabled password is set to 0
if (block[7] == 0x01)
{
if (!memcmp(block, "\x00\x00\x00\x00\x00\x00\x00", 7) && !memcmp(block+9, "\x00\x00\x00\x00\x00\x00\x00", 7))
return true;
}
else if (block[7] == 0x00)
{
if (!memcmp(block+9, "\x00\x00\x00\x00\x00\x00\x00", 7))
return true;
}
return false;
}
bool IsBlock1PCF7931(uint8_t *block) {
// assuming all RFU bits are set to 0
uint8_t rb1 = block[14] & 0x80;
uint8_t rfb = block[14] & 0x7f;
uint8_t rlb = block[15];
if (block[10] == 0 && block[11] == 0 && block[12] == 0 && block[13] == 0)
// block 1 is sent only if (RLB >= 1 && RFB <= 1) or RB1 enabled
if(rfb <= rlb && rfb <= 9 && rlb <= 9 && ((rfb <= 1 && rlb >= 1) || rb1))
return true;
return false;
}
void ReadPCF7931() {
int found_blocks = 0; // successfully read blocks
int max_blocks = 8; // readable blocks
uint8_t memory_blocks[8][17]; // PCF content
uint8_t single_blocks[8][17]; // PFC blocks with unknown position
int single_blocks_cnt = 0;
size_t n = 0; // transmitted blocks
uint8_t tmp_blocks[4][16]; // temporary read buffer
uint8_t found_0_1 = 0; // flag: blocks 0 and 1 were found
int errors = 0; // error counter
int tries = 0; // tries counter
memset(memory_blocks, 0, 8*17*sizeof(uint8_t));
memset(single_blocks, 0, 8*17*sizeof(uint8_t));
int i = 0, j = 0;
do {
i = 0;
memset(tmp_blocks, 0, 4*16*sizeof(uint8_t));
n = DemodPCF7931((uint8_t**)tmp_blocks);
if(!n)
++errors;
// exit if no block is received
if (errors >= 10 && found_blocks == 0 && single_blocks_cnt == 0) {
Dbprintf("Error, no tag or bad tag");
return;
}
// exit if too many errors during reading
if (tries > 50 && (2*errors > tries)) {
Dbprintf("Error reading the tag");
Dbprintf("Here is the partial content");
goto end;
}
// our logic breaks if we don't get at least two blocks
if (n < 2) {
// skip if all 0s block or no blocks
if (n == 0 || !memcmp(tmp_blocks[0], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16))
continue;
// add block to single blocks list
if (single_blocks_cnt < max_blocks) {
for (i = 0; i < single_blocks_cnt; ++i) {
if (!memcmp(single_blocks[i], tmp_blocks[0], 16)) {
j = 1;
break;
}
}
if (j != 1) {
memcpy(single_blocks[single_blocks_cnt], tmp_blocks[0], 16);
print_result("got single block", single_blocks[single_blocks_cnt], 16);
single_blocks_cnt++;
}
j = 0;
}
++tries;
continue;
}
Dbprintf("(dbg) got %d blocks (%d/%d found) (%d tries, %d errors)", n, found_blocks, (max_blocks == 0 ? found_blocks : max_blocks), tries, errors);
for (i = 0; i < n; ++i)
{
print_result("got consecutive blocks", tmp_blocks[i], 16);
}
i = 0;
if(!found_0_1) {
while (i < n - 1) {
if (IsBlock0PCF7931(tmp_blocks[i]) && IsBlock1PCF7931(tmp_blocks[i+1])) {
found_0_1 = 1;
memcpy(memory_blocks[0], tmp_blocks[i], 16);
memcpy(memory_blocks[1], tmp_blocks[i+1], 16);
memory_blocks[0][ALLOC] = memory_blocks[1][ALLOC] = 1;
// block 1 tells how many blocks are going to be sent
max_blocks = MAX((memory_blocks[1][14] & 0x7f), memory_blocks[1][15]) + 1;
found_blocks = 2;
Dbprintf("Found blocks 0 and 1. PCF is transmitting %d blocks.", max_blocks);
// handle the following blocks
for (j = i + 2; j < n; ++j) {
memcpy(memory_blocks[found_blocks], tmp_blocks[j], 16);
memory_blocks[found_blocks][ALLOC] = 1;
++found_blocks;
}
break;
}
++i;
}
} else {
// Trying to re-order blocks
// Look for identical block in memory blocks
while (i < n-1) {
// skip all zeroes blocks
if (memcmp(tmp_blocks[i], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16)) {
for (j = 1; j < max_blocks - 1; ++j) {
if (!memcmp(tmp_blocks[i], memory_blocks[j], 16) && !memory_blocks[j+1][ALLOC]) {
memcpy(memory_blocks[j+1], tmp_blocks[i+1], 16);
memory_blocks[j+1][ALLOC] = 1;
if (++found_blocks >= max_blocks) goto end;
}
}
}
if (memcmp(tmp_blocks[i+1], "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16)) {
for (j = 0; j < max_blocks; ++j) {
if (!memcmp(tmp_blocks[i+1], memory_blocks[j], 16) && !memory_blocks[(j == 0 ? max_blocks : j) -1][ALLOC]) {
if (j == 0) {
memcpy(memory_blocks[max_blocks - 1], tmp_blocks[i], 16);
memory_blocks[max_blocks - 1][ALLOC] = 1;
} else {
memcpy(memory_blocks[j-1], tmp_blocks[i], 16);
memory_blocks[j-1][ALLOC] = 1;
}
if (++found_blocks >= max_blocks) goto end;
}
}
}
++i;
}
}
++tries;
if (BUTTON_PRESS()) {
Dbprintf("Button pressed, stopping.");
goto end;
}
}
while (found_blocks < max_blocks);
end:
Dbprintf("-----------------------------------------");
Dbprintf("Memory content:");
Dbprintf("-----------------------------------------");
for (i = 0; i < max_blocks; ++i) {
if (memory_blocks[i][ALLOC])
print_result("Block", memory_blocks[i], 16);
else
Dbprintf("<missing block %d>", i);
}
Dbprintf("-----------------------------------------");
if (found_blocks < max_blocks) {
Dbprintf("-----------------------------------------");
Dbprintf("Blocks with unknown position:");
Dbprintf("-----------------------------------------");
for (i = 0; i < single_blocks_cnt; ++i)
print_result("Block", single_blocks[i], 16);
Dbprintf("-----------------------------------------");
}
cmd_send(CMD_ACK,0,0,0,0,0);
}
static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) {
uint32_t tab[1024]={0}; // data times frame
uint32_t u = 0;
uint8_t parity = 0;
bool comp = 0;
//BUILD OF THE DATA FRAME
//alimentation of the tag (time for initializing)
AddPatternPCF7931(init_delay, 0, 8192/2*T0_PCF, tab);
AddPatternPCF7931(8192/2*T0_PCF + 319*T0_PCF+70, 3*T0_PCF, 29*T0_PCF, tab);
//password indication bit
AddBitPCF7931(1, tab, l, p);
// password (on 56 bits)
AddBytePCF7931(pass[0], tab, l, p);
AddBytePCF7931(pass[1], tab, l, p);
AddBytePCF7931(pass[2], tab, l, p);
AddBytePCF7931(pass[3], tab, l, p);
AddBytePCF7931(pass[4], tab, l, p);
AddBytePCF7931(pass[5], tab, l, p);
AddBytePCF7931(pass[6], tab, l, p);
//programming mode (0 or 1)
AddBitPCF7931(0, tab, l, p);
//block adress on 6 bits
for (u = 0; u < 6; ++u) {
if (address & (1 << u)) { // bit 1
++parity;
AddBitPCF7931(1, tab, l, p);
} else { // bit 0
AddBitPCF7931(0, tab, l, p);
}
}
//byte address on 4 bits
for (u = 0; u < 4; ++u)
{
if (byte & (1 << u)) { // bit 1
parity++;
AddBitPCF7931(1, tab, l, p);
}
else // bit 0
AddBitPCF7931(0, tab, l, p);
}
//data on 8 bits
for (u=0; u<8; u++)
{
if (data&(1<<u)) { // bit 1
parity++;
AddBitPCF7931(1, tab, l, p);
}
else //bit 0
AddBitPCF7931(0, tab, l, p);
}
//parity bit
if ((parity % 2) == 0)
AddBitPCF7931(0, tab, l, p); //even parity
else
AddBitPCF7931(1, tab, l, p);//odd parity
//time access memory
AddPatternPCF7931(5120+2680, 0, 0, tab);
//conversion of the scale time
for (u = 0; u < 500; ++u)
tab[u] = (tab[u] * 3) / 2;
//compennsation of the counter reload
while (!comp) {
comp = 1;
for (u = 0; tab[u] != 0; ++u)
if(tab[u] > 0xFFFF) {
tab[u] -= 0xFFFF;
comp = 0;
}
}
SendCmdPCF7931(tab);
}
void BruteForcePCF7931(uint64_t password, uint8_t tries, uint16_t init_delay, int32_t l, int32_t p) {
uint8_t i = 0;
uint8_t pass_array[7];
while (password < 0x00FFFFFFFFFFFFFF) {
if (BUTTON_PRESS()) {
Dbprintf("Button pressed, stopping bruteforce ...");
return;
}
num_to_bytes(password, 7, pass_array);
Dbprintf("Trying: %02x %02x %02x %02x %02x %02x %02x ...",
pass_array[0],
pass_array[1],
pass_array[2],
pass_array[3],
pass_array[4],
pass_array[5],
pass_array[6]);
for (i = 0; i < tries; ++i)
RealWritePCF7931
(
pass_array,
init_delay,
l,
p,
0,
7,
0x01
);
++password;
}
}
/* Write on a byte of a PCF7931 tag
* @param address : address of the block to write
@param byte : address of the byte to write
@param data : data to write
*/
void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) {
Dbprintf("Initialization delay : %d us", init_delay);
Dbprintf("Offsets : %d us on the low pulses width, %d us on the low pulses positions", l, p);
Dbprintf("Password (LSB first on each byte): %02x %02x %02x %02x %02x %02x %02x", pass1, pass2, pass3, pass4, pass5, pass6, pass7);
Dbprintf("Block address : %02x", address);
Dbprintf("Byte address : %02x", byte);
Dbprintf("Data : %02x", data);
uint8_t password[7] = {pass1, pass2, pass3, pass4, pass5, pass6, pass7};
RealWritePCF7931 (password, init_delay, l, p, address, byte, data);
}
/* Send a trame to a PCF7931 tags
* @param tab : array of the data frame
*/
void SendCmdPCF7931(uint32_t * tab) {
uint16_t u=0;
uint16_t tempo=0;
Dbprintf("Sending data frame ...");
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_PASSTHRU );
LED_A_ON();
// steal this pin from the SSP and use it to control the modulation
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
//initialization of the timer
AT91C_BASE_PMC->PMC_PCER |= (0x1 << 12) | (0x1 << 13) | (0x1 << 14);
AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_TIOA0 | AT91C_TCB_TC2XC2S_NONE;
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; // timer disable
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV3_CLOCK; //clock at 48/32 MHz
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN;
AT91C_BASE_TCB->TCB_BCR = 1;
tempo = AT91C_BASE_TC0->TC_CV;
for (u = 0; tab[u] != 0; u += 3) {
// modulate antenna
HIGH(GPIO_SSC_DOUT);
while(tempo != tab[u])
tempo = AT91C_BASE_TC0->TC_CV;
// stop modulating antenna
LOW(GPIO_SSC_DOUT);
while(tempo != tab[u+1])
tempo = AT91C_BASE_TC0->TC_CV;
// modulate antenna
HIGH(GPIO_SSC_DOUT);
while(tempo != tab[u+2])
tempo = AT91C_BASE_TC0->TC_CV;
}
LED_A_OFF();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
SpinDelay(200);
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; // timer disable
DbpString("Data frame sent (multiple sends may be needed)");
LED(0xFFFF, 1000);
}
/* Add a byte for building the data frame of PCF7931 tags
* @param b : byte to add
* @param tab : array of the data frame
* @param l : offset on low pulse width
* @param p : offset on low pulse positioning
*/
bool AddBytePCF7931(uint8_t byte, uint32_t * tab, int32_t l, int32_t p) {
uint32_t u;
for (u = 0; u < 8; ++u) {
if (byte & (1 << u)) { //bit is 1
if(AddBitPCF7931(1, tab, l, p)==1)return 1;
} else { //bit is 0
if(AddBitPCF7931(0, tab, l, p)==1)return 1;
}
}
return 0;
}
/* Add a bits for building the data frame of PCF7931 tags
* @param b : bit to add
* @param tab : array of the data frame
* @param l : offset on low pulse width
* @param p : offset on low pulse positioning
*/
bool AddBitPCF7931(bool b, uint32_t * tab, int32_t l, int32_t p) {
uint8_t u = 0;
for (u = 0; tab[u] != 0; u += 3){} //we put the cursor at the last value of the array
if (b == 1) { //add a bit 1
if (u == 0) tab[u] = 34 * T0_PCF + p;
else tab[u] = 34 * T0_PCF + tab[u-1] + p;
tab[u+1] = 6 * T0_PCF+tab[u] + l;
tab[u+2] = 88 * T0_PCF+tab[u + 1] - l - p;
return 0;
} else { //add a bit 0
if (u == 0) tab[u] = 98 * T0_PCF + p;
else tab[u] = 98 * T0_PCF + tab[u-1] + p;
tab[u + 1] = 6 * T0_PCF + tab[u] + l;
tab[u + 2] = 24 * T0_PCF + tab[u + 1] - l - p;
return 0;
}
return 1;
}
/* Add a custom pattern in the data frame
* @param a : delay of the first high pulse
* @param b : delay of the low pulse
* @param c : delay of the last high pulse
* @param tab : array of the data frame
*/
bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t * tab) {
uint32_t u = 0;
for(u = 0; tab[u] != 0; u += 3){} //we put the cursor at the last value of the array
if (u == 0) tab[u] = a;
else tab[u] = a + tab[u - 1];
tab[u + 1] = b + tab[u];
tab[u + 2] = c + tab[u + 1];
return 0;
}

15
armsrc/pcf7931.h Normal file
View file

@ -0,0 +1,15 @@
#ifndef __PCF7931_H
#define __PCF7931_H
size_t DemodPCF7931(uint8_t **outBlocks);
bool IsBlock0PCF7931(uint8_t *Block);
bool IsBlock1PCF7931(uint8_t *Block);
void ReadPCF7931();
void SendCmdPCF7931(uint32_t * tab);
bool AddBytePCF7931(uint8_t byte, uint32_t * tab, int32_t l, int32_t p);
bool AddBitPCF7931(bool b, uint32_t * tab, int32_t l, int32_t p);
bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t * tab);
void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data);
void BruteForcePCF7931(uint64_t start_password, uint8_t tries, uint16_t init_delay, int32_t l, int32_t p);
#endif

View file

@ -40,9 +40,6 @@
#include "util.h"
#include "string.h"
typedef uint32_t uintmax_t;
typedef int32_t intmax_t;
typedef unsigned char u_char;
typedef unsigned int u_int;
typedef unsigned long u_long;
@ -178,6 +175,7 @@ reswitch: switch (ch = (u_char)*fmt++) {
padc = '0';
goto reswitch;
}
// intentionally fall through to next case
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
for (n = 0;; ++fmt) {

View file

@ -11,23 +11,75 @@
#include "proxmark3.h"
#include "apps.h"
#include "zlib.h"
#include "BigBuf.h"
static uint8_t *next_free_memory;
extern struct common_area common_area;
extern char __data_src_start__, __data_start__, __data_end__, __bss_start__, __bss_end__;
static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size)
{
uint8_t *allocated_memory;
allocated_memory = next_free_memory;
next_free_memory += items*size;
return allocated_memory;
}
static void inflate_free(voidpf opaque, voidpf address)
{
// nothing to do
}
static void uncompress_data_section(void)
{
z_stream data_section;
next_free_memory = BigBuf_get_addr();
// initialize zstream structure
data_section.next_in = (uint8_t *) &__data_src_start__;
data_section.avail_in = &__data_end__ - &__data_start__; // uncompressed size. Wrong but doesn't matter.
data_section.next_out = (uint8_t *) &__data_start__;
data_section.avail_out = &__data_end__ - &__data_start__; // uncompressed size. Correct.
data_section.zalloc = &inflate_malloc;
data_section.zfree = &inflate_free;
data_section.opaque = NULL;
// initialize zlib for inflate
inflateInit2(&data_section, 15);
// uncompress data segment to RAM
inflate(&data_section, Z_FINISH);
// save the size of the compressed data section
common_area.arg1 = data_section.total_in;
}
extern char __data_start__, __data_src_start__, __data_end__, __bss_start__, __bss_end__;
void __attribute__((section(".startos"))) Vector(void)
{
/* Stack should have been set up by the bootloader */
char *src, *dst, *end;
// char *src;
char *dst, *end;
uncompress_data_section();
/* Set up (that is: clear) BSS. */
dst = &__bss_start__;
end = &__bss_end__;
while(dst < end) *dst++ = 0;
/* Set up data segment: Copy from flash to ram */
src = &__data_src_start__;
dst = &__data_start__;
end = &__data_end__;
while(dst < end) *dst++ = *src++;
// Set up data segment: Copy from flash to ram
// src = &__data_src_start__;
// dst = &__data_start__;
// end = &__data_end__;
// while(dst < end) *dst++ = *src++;
AppMain();
}

View file

@ -11,8 +11,7 @@
#include "string.h"
#include <stdint.h>
void *memcpy(void *dest, const void *src, int len)
{
void *memcpy(void *dest, const void *src, size_t len) {
uint8_t *d = dest;
const uint8_t *s = src;
while((len--) > 0) {
@ -23,8 +22,8 @@ void *memcpy(void *dest, const void *src, int len)
return dest;
}
void *memset(void *dest, int c, int len)
{
void *memset(void *dest, int c, size_t len) {
uint8_t *d = dest;
while((len--) > 0) {
*d = c;
@ -33,8 +32,30 @@ void *memset(void *dest, int c, int len)
return dest;
}
int memcmp(const void *av, const void *bv, int len)
{
void *memmove(void *dest, const void *src, size_t len) {
uint8_t *d = dest;
const uint8_t *s = src;
if (dest <= src) {
while((len--) > 0) {
*d = *s;
d++;
s++;
}
} else {
d = d + len - 1;
s = s + len - 1;
while((len--) > 0) {
*d = *s;
d--;
s--;
}
}
return dest;
}
int memcmp(const void *av, const void *bv, size_t len) {
const uint8_t *a = av;
const uint8_t *b = bv;
@ -48,8 +69,8 @@ int memcmp(const void *av, const void *bv, int len)
return 0;
}
int strlen(const char *str)
{
size_t strlen(const char *str) {
int l = 0;
while(*str) {
l++;
@ -58,8 +79,8 @@ int strlen(const char *str)
return l;
}
char* strncat(char *dest, const char *src, unsigned int n)
{
char* strncat(char *dest, const char *src, size_t n) {
unsigned int dest_len = strlen(dest);
unsigned int i;
@ -70,8 +91,8 @@ char* strncat(char *dest, const char *src, unsigned int n)
return dest;
}
char* strcat(char *dest, const char *src)
{
char* strcat(char *dest, const char *src) {
unsigned int dest_len = strlen(dest);
unsigned int i;
@ -81,35 +102,3 @@ char* strcat(char *dest, const char *src)
return dest;
}
////////////////////////////////////////// code to do 'itoa'
/* reverse: reverse string s in place */
void strreverse(char s[])
{
int c, i, j;
for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
/* itoa: convert n to characters in s */
void itoa(int n, char s[])
{
int i, sign;
if ((sign = n) < 0) /* record sign */
n = -n; /* make n positive */
i = 0;
do { /* generate digits in reverse order */
s[i++] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
strreverse(s);
}
//////////////////////////////////////// END 'itoa' CODE

View file

@ -12,14 +12,14 @@
#ifndef __STRING_H
#define __STRING_H
int strlen(const char *str);
void *memcpy(void *dest, const void *src, int len);
void *memset(void *dest, int c, int len);
int memcmp(const void *av, const void *bv, int len);
char *strncat(char *dest, const char *src, unsigned int n);
char *strcat(char *dest, const char *src);
void strreverse(char s[]);
void itoa(int n, char s[]);
#include <stddef.h>
void *memcpy(void *dest, const void *src, size_t len);
void *memset(void *dest, int c, size_t len);
void *memmove(void *dest, const void *src, size_t len);
int memcmp(const void *av, const void *bv, size_t len);
size_t strlen(const char *str);
char *strncat(char *dest, const char *src, size_t n);
char *strcat(char *dest, const char *src);
#endif /* __STRING_H */

View file

@ -12,9 +12,30 @@
#include "util.h"
#include "string.h"
#include "apps.h"
#include "BigBuf.h"
void print_result(char *name, uint8_t *buf, size_t len) {
uint8_t *p = buf;
if ( len % 16 == 0 ) {
for(; p-buf < len; p += 16)
Dbprintf("[%s:%d/%d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
name,
p-buf,
len,
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]
);
}
else {
for(; p-buf < len; p += 8)
Dbprintf("[%s:%d/%d] %02x %02x %02x %02x %02x %02x %02x %02x", name, p-buf, len, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
}
}
size_t nbytes(size_t nbits) {
return (nbits/8)+((nbits%8)>0);
return (nbits >> 3)+((nbits % 8) > 0);
}
uint32_t SwapBits(uint32_t value, int nrbits) {
@ -45,6 +66,21 @@ uint64_t bytes_to_num(uint8_t* src, size_t len)
return num;
}
// RotateLeft - Ultralight, Desfire
void rol(uint8_t *data, const size_t len){
uint8_t first = data[0];
for (size_t i = 0; i < len-1; i++) {
data[i] = data[i+1];
}
data[len-1] = first;
}
void lsl (uint8_t *data, size_t len) {
for (size_t n = 0; n < len - 1; n++) {
data[n] = (data[n] << 1) | (data[n+1] >> 7);
}
data[len - 1] <<= 1;
}
void LEDsoff()
{
LED_A_OFF();
@ -53,6 +89,22 @@ void LEDsoff()
LED_D_OFF();
}
void LEDson()
{
LED_A_ON();
LED_B_ON();
LED_C_ON();
LED_D_ON();
}
void LEDsinvert()
{
LED_A_INV();
LED_B_INV();
LED_C_INV();
LED_D_INV();
}
// LEDs: R(C) O(A) G(B) -- R(D) [1, 2, 4 and 8]
void LED(int led, int ms)
{
@ -85,8 +137,7 @@ void LED(int led, int ms)
// not clicked, or held down (for ms || 1sec)
// In general, don't use this function unless you expect a
// double click, otherwise it will waste 500ms -- use BUTTON_HELD instead
int BUTTON_CLICKED(int ms)
{
int BUTTON_CLICKED(int ms) {
// Up to 500ms in between clicks to mean a double click
int ticks = (48000 * (ms ? ms : 1000)) >> 10;
@ -148,8 +199,7 @@ int BUTTON_CLICKED(int ms)
}
// Determine if a button is held down
int BUTTON_HELD(int ms)
{
int BUTTON_HELD(int ms) {
// If button is held for one second
int ticks = (48000 * (ms ? ms : 1000)) >> 10;
@ -166,8 +216,7 @@ int BUTTON_HELD(int ms)
uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
for(;;)
{
for(;;) {
uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
// As soon as our button let go, we didn't hold long enough
@ -175,8 +224,7 @@ int BUTTON_HELD(int ms)
return BUTTON_SINGLE_CLICK;
// Have we waited the full second?
else
if (now == (uint16_t)(start + ticks))
else if (now == (uint16_t)(start + ticks))
return BUTTON_HOLD;
WDT_HIT();
@ -188,8 +236,7 @@ int BUTTON_HELD(int ms)
// attempt at high resolution microsecond timer
// beware: timer counts in 21.3uS increments (1024/48Mhz)
void SpinDelayUs(int us)
{
void SpinDelayUs(int us) {
int ticks = (48*us) >> 10;
// Borrow a PWM unit for my real-time clock
@ -210,8 +257,7 @@ void SpinDelayUs(int us)
}
}
void SpinDelay(int ms)
{
void SpinDelay(int ms) {
// convert to uS and call microsecond delay function
SpinDelayUs(ms*1000);
}
@ -225,17 +271,17 @@ void FormatVersionInformation(char *dst, int len, const char *prefix, void *vers
{
struct version_information *v = (struct version_information*)version_information;
dst[0] = 0;
strncat(dst, prefix, len);
strncat(dst, prefix, len-1);
if(v->magic != VERSION_INFORMATION_MAGIC) {
strncat(dst, "Missing/Invalid version information", len - strlen(dst) - 1);
strncat(dst, "Missing/Invalid version information\n", len - strlen(dst) - 1);
return;
}
if(v->versionversion != 1) {
strncat(dst, "Version information not understood", len - strlen(dst) - 1);
strncat(dst, "Version information not understood\n", len - strlen(dst) - 1);
return;
}
if(!v->present) {
strncat(dst, "Version information not available", len - strlen(dst) - 1);
strncat(dst, "Version information not available\n", len - strlen(dst) - 1);
return;
}
@ -248,41 +294,44 @@ void FormatVersionInformation(char *dst, int len, const char *prefix, void *vers
strncat(dst, " ", len - strlen(dst) - 1);
strncat(dst, v->buildtime, len - strlen(dst) - 1);
strncat(dst, "\n", len - strlen(dst) - 1);
}
// -------------------------------------------------------------------------
// timer lib
// -------------------------------------------------------------------------
// test procedure:
//
// ti = GetTickCount();
// SpinDelay(1000);
// ti = GetTickCount() - ti;
// Dbprintf("timer(1s): %d t=%d", ti, GetTickCount());
// ti = GetTickCount();
// SpinDelay(1000);
// ti = GetTickCount() - ti;
// Dbprintf("timer(1s): %d t=%d", ti, GetTickCount());
void StartTickCount()
{
// must be 0x40, but on my cpu - included divider is optimal
// 0x20 - 1 ms / bit
// 0x40 - 2 ms / bit
AT91C_BASE_RTTC->RTTC_RTMR = AT91C_RTTC_RTTRST + 0x001D; // was 0x003B
void StartTickCount() {
// This timer is based on the slow clock. The slow clock frequency is between 22kHz and 40kHz.
// We can determine the actual slow clock frequency by looking at the Main Clock Frequency Register.
uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & 0xffff; // = 16 * main clock frequency (16MHz) / slow clock frequency
// set RealTimeCounter divider to count at 1kHz:
AT91C_BASE_RTTC->RTTC_RTMR = AT91C_RTTC_RTTRST | ((256000 + (mainf/2)) / mainf);
// note: worst case precision is approx 2.5%
}
/*
* Get the current count.
*/
uint32_t RAMFUNC GetTickCount(){
uint32_t RAMFUNC GetTickCount(void) {
return AT91C_BASE_RTTC->RTTC_RTVR;// was * 2;
}
// -------------------------------------------------------------------------
// microseconds timer
// microseconds timer
// -------------------------------------------------------------------------
void StartCountUS()
{
void StartCountUS(void) {
AT91C_BASE_PMC->PMC_PCER |= (0x1 << 12) | (0x1 << 13) | (0x1 << 14);
// AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC1XC1S_TIOA0;
// AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC1XC1S_TIOA0;
AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_TIOA0 | AT91C_TCB_TC2XC2S_NONE;
// fast clock
@ -292,22 +341,24 @@ void StartCountUS()
AT91C_TC_ACPC_SET | AT91C_TC_ASWTRG_SET;
AT91C_BASE_TC0->TC_RA = 1;
AT91C_BASE_TC0->TC_RC = 0xBFFF + 1; // 0xC000
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; // timer disable
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; // timer disable
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_XC1; // from timer 0
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN;
AT91C_BASE_TCB->TCB_BCR = 1;
}
uint32_t RAMFUNC GetCountUS(){
return (AT91C_BASE_TC1->TC_CV * 0x8000) + ((AT91C_BASE_TC0->TC_CV / 15) * 10);
uint32_t RAMFUNC GetCountUS(void) {
return (AT91C_BASE_TC1->TC_CV * 0x8000) + ((AT91C_BASE_TC0->TC_CV * 2) / 3); //was /15) * 10);
}
static uint32_t GlobalUsCounter = 0;
uint32_t RAMFUNC GetDeltaCountUS(){
uint32_t RAMFUNC GetDeltaCountUS(void) {
uint32_t g_cnt = GetCountUS();
uint32_t g_res = g_cnt - GlobalUsCounter;
GlobalUsCounter = g_cnt;
@ -316,76 +367,201 @@ uint32_t RAMFUNC GetDeltaCountUS(){
// -------------------------------------------------------------------------
// Timer for iso14443 commands. Uses ssp_clk from FPGA
// Timer for iso14443 commands. Uses ssp_clk from FPGA
// -------------------------------------------------------------------------
void StartCountSspClk()
{
void StartCountSspClk(void) {
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1) | (1 << AT91C_ID_TC2); // Enable Clock to all timers
AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_TIOA1 // XC0 Clock = TIOA1
| AT91C_TCB_TC1XC1S_NONE // XC1 Clock = none
| AT91C_TCB_TC2XC2S_TIOA0; // XC2 Clock = TIOA0
AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_TIOA1 // XC0 Clock = TIOA1
| AT91C_TCB_TC1XC1S_NONE // XC1 Clock = none
| AT91C_TCB_TC2XC2S_TIOA0; // XC2 Clock = TIOA0
// configure TC1 to create a short pulse on TIOA1 when a rising edge on TIOB1 (= ssp_clk from FPGA) occurs:
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; // disable TC1
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS; // disable TC1
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV1_CLOCK // TC1 Clock = MCK(48MHz)/2 = 24MHz
| AT91C_TC_CPCSTOP // Stop clock on RC compare
| AT91C_TC_EEVTEDG_RISING // Trigger on rising edge of Event
| AT91C_TC_EEVT_TIOB // Event-Source: TIOB1 (= ssp_clk from FPGA = 13,56MHz/16)
| AT91C_TC_ENETRG // Enable external trigger event
| AT91C_TC_WAVESEL_UP // Upmode without automatic trigger on RC compare
| AT91C_TC_WAVE // Waveform Mode
| AT91C_TC_AEEVT_SET // Set TIOA1 on external event
| AT91C_TC_ACPC_CLEAR; // Clear TIOA1 on RC Compare
AT91C_BASE_TC1->TC_RC = 0x04; // RC Compare value = 0x04
| AT91C_TC_CPCSTOP // Stop clock on RC compare
| AT91C_TC_EEVTEDG_RISING // Trigger on rising edge of Event
| AT91C_TC_EEVT_TIOB // Event-Source: TIOB1 (= ssp_clk from FPGA = 13,56MHz/16 ... 13,56MHz/4)
| AT91C_TC_ENETRG // Enable external trigger event
| AT91C_TC_WAVESEL_UP // Upmode without automatic trigger on RC compare
| AT91C_TC_WAVE // Waveform Mode
| AT91C_TC_AEEVT_SET // Set TIOA1 on external event
| AT91C_TC_ACPC_CLEAR; // Clear TIOA1 on RC Compare
AT91C_BASE_TC1->TC_RC = 1; // RC Compare value = 1; pulse width to TC0
// use TC0 to count TIOA1 pulses
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; // disable TC0
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_XC0 // TC0 clock = XC0 clock = TIOA1
| AT91C_TC_WAVE // Waveform Mode
| AT91C_TC_WAVESEL_UP // just count
| AT91C_TC_ACPA_CLEAR // Clear TIOA0 on RA Compare
| AT91C_TC_ACPC_SET; // Set TIOA0 on RC Compare
AT91C_BASE_TC0->TC_RA = 1; // RA Compare value = 1; pulse width to TC2
AT91C_BASE_TC0->TC_RC = 0; // RC Compare value = 0; increment TC2 on overflow
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; // disable TC0
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_XC0 // TC0 clock = XC0 clock = TIOA1
| AT91C_TC_WAVE // Waveform Mode
| AT91C_TC_WAVESEL_UP // just count
| AT91C_TC_ACPA_CLEAR // Clear TIOA0 on RA Compare
| AT91C_TC_ACPC_SET; // Set TIOA0 on RC Compare
AT91C_BASE_TC0->TC_RA = 1; // RA Compare value = 1; pulse width to TC2
AT91C_BASE_TC0->TC_RC = 0; // RC Compare value = 0; increment TC2 on overflow
// use TC2 to count TIOA0 pulses (giving us a 32bit counter (TC0/TC2) clocked by ssp_clk)
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKDIS; // disable TC2
AT91C_BASE_TC2->TC_CMR = AT91C_TC_CLKS_XC2 // TC2 clock = XC2 clock = TIOA0
| AT91C_TC_WAVE // Waveform Mode
| AT91C_TC_WAVESEL_UP; // just count
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN; // enable TC0
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN; // enable TC1
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKEN; // enable TC2
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKDIS; // disable TC2
AT91C_BASE_TC2->TC_CMR = AT91C_TC_CLKS_XC2 // TC2 clock = XC2 clock = TIOA0
| AT91C_TC_WAVE // Waveform Mode
| AT91C_TC_WAVESEL_UP; // just count
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN; // enable TC0
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN; // enable TC1
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKEN; // enable TC2
//
// synchronize the counter with the ssp_frame signal. Note: FPGA must be in any iso14446 mode, otherwise the frame signal would not be present
// synchronize the counter with the ssp_frame signal. Note: FPGA must be in a FPGA mode with SSC transfer, otherwise SSC_FRAME and SSC_CLK signals would not be present
//
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_FRAME)); // wait for ssp_frame to go high (start of frame)
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_FRAME); // wait for ssp_frame to be low
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high
// note: up to now two ssp_clk rising edges have passed since the rising edge of ssp_frame
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_FRAME); // wait for ssp_frame to be low
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_FRAME)); // wait for ssp_frame to go high (start of frame)
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 1st ssp_clk after start of frame
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 2nd ssp_clk after start of frame
if ((AT91C_BASE_SSC->SSC_RFMR & SSC_FRAME_MODE_BITS_IN_WORD(32)) == SSC_FRAME_MODE_BITS_IN_WORD(16)) { // 16bit frame
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 3rd ssp_clk after start of frame
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 4th ssp_clk after start of frame
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 5th ssp_clk after start of frame
while(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK); // wait for ssp_clk to go low;
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)); // wait for ssp_clk to go high; 6th ssp_clk after start of frame
}
// it is now safe to assert a sync signal. This sets all timers to 0 on next active clock edge
AT91C_BASE_TCB->TCB_BCR = 1; // assert Sync (set all timers to 0 on next active clock edge)
// at the next (3rd) ssp_clk rising edge, TC1 will be reset (and not generate a clock signal to TC0)
// at the next (4th) ssp_clk rising edge, TC0 (the low word of our counter) will be reset. From now on,
// whenever the last three bits of our counter go 0, we can be sure to be in the middle of a frame transfer.
// (just started with the transfer of the 4th Bit).
AT91C_BASE_TCB->TCB_BCR = 1; // assert Sync (set all timers to 0 on next active clock edge)
// at the next (3rd/7th) ssp_clk rising edge, TC1 will be reset (and not generate a clock signal to TC0)
// at the next (4th/8th) ssp_clk rising edge, TC0 (the low word of our counter) will be reset. From now on,
// whenever the last three/four bits of our counter go 0, we can be sure to be in the middle of a frame transfer.
// The high word of the counter (TC2) will not reset until the low word (TC0) overflows. Therefore need to wait quite some time before
// we can use the counter.
while (AT91C_BASE_TC0->TC_CV < 0xFFF0);
while (AT91C_BASE_TC0->TC_CV < 0xFFFF);
// Note: needs one more SSP_CLK cycle (1.18 us) until TC2 resets. Don't call GetCountSspClk() that soon.
}
uint32_t RAMFUNC GetCountSspClk(){
uint32_t tmp_count;
tmp_count = (AT91C_BASE_TC2->TC_CV << 16) | AT91C_BASE_TC0->TC_CV;
if ((tmp_count & 0x0000ffff) == 0) { //small chance that we may have missed an increment in TC2
return (AT91C_BASE_TC2->TC_CV << 16);
}
else {
return tmp_count;
void ResetSspClk(void) {
//enable clock of timer and software trigger
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
while (AT91C_BASE_TC2->TC_CV > 0);
}
uint32_t GetCountSspClk(){
uint32_t hi, lo;
do {
hi = AT91C_BASE_TC2->TC_CV;
lo = AT91C_BASE_TC0->TC_CV;
} while (hi != AT91C_BASE_TC2->TC_CV);
return (hi << 16) | lo;
}
// -------------------------------------------------------------------------
// Timer for bitbanging, or LF stuff when you need a very precis timer
// 1us = 1.5ticks
// -------------------------------------------------------------------------
void StartTicks(void){
// initialization of the timer
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_TIOA0 | AT91C_TCB_TC2XC2S_NONE;
// disable TC0 and TC1 for re-configuration
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
// first configure TC1 (higher, 0xFFFF0000) 16 bit counter
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_XC1; // just connect to TIOA0 from TC0
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // re-enable timer and wait for TC0
// second configure TC0 (lower, 0x0000FFFF) 16 bit counter
AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV3_CLOCK | // MCK(48MHz) / 32
AT91C_TC_WAVE | AT91C_TC_WAVESEL_UP_AUTO |
AT91C_TC_ACPA_CLEAR | // RA comperator clears TIOA (carry bit)
AT91C_TC_ACPC_SET | // RC comperator sets TIOA (carry bit)
AT91C_TC_ASWTRG_SET; // SWTriger sets TIOA (carry bit)
AT91C_BASE_TC0->TC_RC = 0; // set TIOA (carry bit) on overflow, return to zero
AT91C_BASE_TC0->TC_RA = 1; // clear carry bit on next clock cycle
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG; // reset and re-enable timer
// synchronized startup procedure
while (AT91C_BASE_TC0->TC_CV > 0); // wait until TC0 returned to zero
while (AT91C_BASE_TC0->TC_CV < 2); // and has started (TC_CV > TC_RA, now TC1 is cleared)
// return to zero
AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG;
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
while (AT91C_BASE_TC0->TC_CV > 0);
}
uint32_t GetTicks(void) {
uint32_t hi, lo;
do {
hi = AT91C_BASE_TC1->TC_CV;
lo = AT91C_BASE_TC0->TC_CV;
} while(hi != AT91C_BASE_TC1->TC_CV);
return (hi << 16) | lo;
}
// Wait - Spindelay in ticks.
// if called with a high number, this will trigger the WDT...
void WaitTicks(uint32_t ticks){
if ( ticks == 0 ) return;
ticks += GetTicks();
while (GetTicks() < ticks);
}
// Wait / Spindelay in us (microseconds)
// 1us = 1.5ticks.
void WaitUS(uint16_t us){
WaitTicks( (uint32_t)us * 3 / 2 ) ;
}
void WaitMS(uint16_t ms){
WaitTicks( (uint32_t)ms * 1500 );
}
// Starts Clock and waits until its reset
void ResetTicks(void){
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
while (AT91C_BASE_TC0->TC_CV > 0);
}
void ResetTimer(AT91PS_TC timer){
timer->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
while(timer->TC_CV > 0) ;
}
// stop clock
void StopTicks(void){
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
}
static uint64_t next_random = 1;
/* Generates a (non-cryptographically secure) 32-bit random number.
*
* We don't have an implementation of the "rand" function or a clock to seed it
* with, so we just call GetTickCount the first time to seed ourselves.
*/
uint32_t prand() {
if (next_random == 1) {
next_random = GetTickCount();
}
next_random = next_random * 6364136223846793005 + 1;
return (uint32_t)(next_random >> 32) % 0xffffffff;
}

View file

@ -8,46 +8,77 @@
// Utility functions used in many places, not specific to any piece of code.
//-----------------------------------------------------------------------------
#ifndef __UTIL_H
#define __UTIL_H
#ifndef UTIL_H__
#define UTIL_H__
#include <stddef.h>
#include <stdint.h>
#include <common.h>
#include "common.h"
#include "at91sam7s512.h"
#define BYTEx(x, n) (((x) >> (n * 8)) & 0xff )
#define LED_RED 1
#define LED_RED 1
#define LED_ORANGE 2
#define LED_GREEN 4
#define LED_RED2 8
#define BUTTON_HOLD 1
#define BUTTON_NO_CLICK 0
#define BUTTON_SINGLE_CLICK -1
#define BUTTON_DOUBLE_CLICK -2
#define BUTTON_ERROR -99
#define LED_GREEN 4
#define LED_RED2 8
size_t nbytes(size_t nbits);
uint32_t SwapBits(uint32_t value, int nrbits);
void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
uint64_t bytes_to_num(uint8_t* src, size_t len);
#define BUTTON_HOLD 1
#define BUTTON_NO_CLICK 0
#define BUTTON_SINGLE_CLICK -1
#define BUTTON_DOUBLE_CLICK -2
#define BUTTON_ERROR -99
void SpinDelay(int ms);
void SpinDelayUs(int us);
void LED(int led, int ms);
void LEDsoff();
int BUTTON_CLICKED(int ms);
int BUTTON_HELD(int ms);
void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information);
#define REV8(x) ((((x)>>7)&1)|((((x)>>6)&1)<<1)|((((x)>>5)&1)<<2)|((((x)>>4)&1)<<3)|((((x)>>3)&1)<<4)|((((x)>>2)&1)<<5)|((((x)>>1)&1)<<6)|(((x)&1)<<7))
#define REV16(x) (REV8(x) | (REV8 (x >> 8) << 8))
#define REV32(x) (REV16(x) | (REV16(x >> 16) << 16))
#define REV64(x) (REV32(x) | (REV32(x >> 32) << 32))
void StartTickCount();
uint32_t RAMFUNC GetTickCount();
extern void print_result(char *name, uint8_t *buf, size_t len);
extern size_t nbytes(size_t nbits);
extern uint32_t SwapBits(uint32_t value, int nrbits);
extern void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
extern uint64_t bytes_to_num(uint8_t* src, size_t len);
extern void rol(uint8_t *data, const size_t len);
extern void lsl (uint8_t *data, size_t len);
void StartCountUS();
uint32_t RAMFUNC GetCountUS();
uint32_t RAMFUNC GetDeltaCountUS();
extern void LED(int led, int ms);
extern void LEDsoff();
extern void LEDson();
extern void LEDsinvert();
extern int BUTTON_CLICKED(int ms);
extern int BUTTON_HELD(int ms);
extern void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information);
void StartCountSspClk();
uint32_t RAMFUNC GetCountSspClk();
//iceman's ticks.h
#ifndef GET_TICKS
# define GET_TICKS GetTicks()
#endif
extern void SpinDelay(int ms);
extern void SpinDelayUs(int us);
extern void StartTickCount();
extern uint32_t RAMFUNC GetTickCount();
extern void StartCountUS();
extern uint32_t RAMFUNC GetCountUS();
extern uint32_t RAMFUNC GetDeltaCountUS();
extern void StartCountSspClk();
extern void ResetSspClk(void);
extern uint32_t GetCountSspClk();
extern void StartTicks(void);
extern uint32_t GetTicks(void);
extern void WaitTicks(uint32_t ticks);
extern void WaitUS(uint16_t us);
extern void WaitMS(uint16_t ms);
extern void ResetTicks();
extern void ResetTimer(AT91PS_TC timer);
extern void StopTicks(void);
// end iceman's ticks.h
extern uint32_t prand();
#endif

View file

@ -7,9 +7,10 @@
#-----------------------------------------------------------------------------
# DO NOT use thumb mode in the phase 1 bootloader since that generates a section with glue code
ARMSRC =
THUMBSRC = cmd.c usb_cdc.c bootrom.c
ARMSRC = string.c
THUMBSRC = usb_cdc.c bootrom.c
ASMSRC = ram-reset.s flash-reset.s
VERSIONSRC = version.c
## There is a strange bug with the linker: Sometimes it will not emit the glue to call
## BootROM from ARM mode. The symbol is emitted, but the section will be filled with
@ -18,9 +19,13 @@ ASMSRC = ram-reset.s flash-reset.s
# ARMSRC := $(ARMSRC) $(THUMBSRC)
# THUMBSRC :=
# stdint.h provided locally until GCC 4.5 becomes C99 compliant
APP_CFLAGS = -I.
# version.c should be remade on every compilation
.PHONY: version.c
version.c: default_version.c
perl ../tools/mkversion.pl .. > $@ || $(COPY) $^ $@
# Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC
include ../common/Makefile.common

View file

@ -6,17 +6,15 @@
// Main code for the bootloader
//-----------------------------------------------------------------------------
#include <proxmark3.h>
#include "proxmark3.h"
#include "usb_cdc.h"
#include "cmd.h"
//#include "usb_hid.h"
void DbpString(char *str) {
byte_t len = 0;
uint8_t len = 0;
while (str[len] != 0x00) {
len++;
}
cmd_send(CMD_DEBUG_PRINT_STRING,len,0,0,(byte_t*)str,len);
cmd_send_old(CMD_DEBUG_PRINT_STRING,len,0,0,(uint8_t*)str,len);
}
struct common_area common_area __attribute__((section(".commonarea")));
@ -89,28 +87,22 @@ static void Fatal(void)
for(;;);
}
void UsbPacketReceived(uint8_t *packet, int len) {
void UsbPacketReceived(UsbCommand *c) {
int i, dont_ack=0;
UsbCommand* c = (UsbCommand *)packet;
volatile uint32_t *p;
if(len != sizeof(UsbCommand)) {
Fatal();
}
uint32_t arg0 = (uint32_t)c->arg[0];
switch(c->cmd) {
case CMD_DEVICE_INFO: {
dont_ack = 1;
// c->cmd = CMD_DEVICE_INFO;
arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM |
DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH;
arg0 = DEVICE_INFO_FLAG_BOOTROM_PRESENT
| DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM
| DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH;
if(common_area.flags.osimage_present) {
arg0 |= DEVICE_INFO_FLAG_OSIMAGE_PRESENT;
}
// UsbSendPacket(packet, len);
cmd_send(CMD_DEVICE_INFO,arg0,1,2,0,0);
cmd_send_old(CMD_DEVICE_INFO,arg0,1,2,0,0);
} break;
case CMD_SETUP_WRITE: {
@ -125,10 +117,8 @@ void UsbPacketReceived(uint8_t *packet, int len) {
case CMD_FINISH_WRITE: {
uint32_t* flash_mem = (uint32_t*)(&_flash_start);
// p = (volatile uint32_t *)&_flash_start;
for (size_t j=0; j<2; j++) {
for(i = 0+(64*j); i < 64+(64*j); i++) {
//p[i+60] = c->d.asDwords[i];
flash_mem[i] = c->d.asDwords[i];
}
@ -138,16 +128,13 @@ void UsbPacketReceived(uint8_t *packet, int len) {
if( ((flash_address+AT91C_IFLASH_PAGE_SIZE-1) >= end_addr) || (flash_address < start_addr) ) {
/* Disallow write */
dont_ack = 1;
// c->cmd = CMD_NACK;
// UsbSendPacket(packet, len);
cmd_send(CMD_NACK,0,0,0,0,0);
cmd_send_old(CMD_NACK,0,0,0,0,0);
} else {
uint32_t page_n = (flash_address - ((uint32_t)flash_mem)) / AT91C_IFLASH_PAGE_SIZE;
/* Translate address to flash page and do flash, update here for the 512k part */
AT91C_BASE_EFC0->EFC_FCR = MC_FLASH_COMMAND_KEY |
MC_FLASH_COMMAND_PAGEN(page_n) |
AT91C_MC_FCMD_START_PROG;
// arg0 = (address - ((uint32_t)flash_s));
}
// Wait until flashing of page finishes
@ -155,15 +142,12 @@ void UsbPacketReceived(uint8_t *packet, int len) {
while(!((sr = AT91C_BASE_EFC0->EFC_FSR) & AT91C_MC_FRDY));
if(sr & (AT91C_MC_LOCKE | AT91C_MC_PROGE)) {
dont_ack = 1;
// c->cmd = CMD_NACK;
cmd_send(CMD_NACK,0,0,0,0,0);
// UsbSendPacket(packet, len);
cmd_send_old(CMD_NACK,0,0,0,0,0);
}
}
} break;
case CMD_HARDWARE_RESET: {
// USB_D_PLUS_PULLUP_OFF();
usb_disable();
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;
} break;
@ -189,9 +173,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
} else {
start_addr = end_addr = 0;
dont_ack = 1;
// c->cmd = CMD_NACK;
// UsbSendPacket(packet, len);
cmd_send(CMD_NACK,0,0,0,0,0);
cmd_send_old(CMD_NACK,0,0,0,0,0);
}
}
} break;
@ -202,9 +184,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
}
if(!dont_ack) {
// c->cmd = CMD_ACK;
// UsbSendPacket(packet, len);
cmd_send(CMD_ACK,arg0,0,0,0,0);
cmd_send_old(CMD_ACK,arg0,0,0,0,0);
}
}
@ -213,29 +193,20 @@ static void flash_mode(int externally_entered)
start_addr = 0;
end_addr = 0;
bootrom_unlocked = 0;
byte_t rx[sizeof(UsbCommand)];
size_t rx_len;
UsbCommand rx;
usb_enable();
for (volatile size_t i=0; i<0x100000; i++);
usb_enable();
for (volatile size_t i=0; i<0x100000; i++) {};
// UsbStart();
for(;;) {
WDT_HIT();
if (usb_poll()) {
rx_len = usb_read(rx,sizeof(UsbCommand));
if (rx_len) {
// DbpString("starting to flash");
UsbPacketReceived(rx,rx_len);
}
}
// UsbPoll(TRUE);
if (cmd_receive(&rx)) {
UsbPacketReceived(&rx);
}
if(!externally_entered && !BUTTON_PRESS()) {
/* Perform a reset to leave flash mode */
// USB_D_PLUS_PULLUP_OFF();
usb_disable();
LED_B_ON();
AT91C_BASE_RSTC->RSTC_RCR = RST_CONTROL_KEY | AT91C_RSTC_PROCRST;

104
bootrom/string.c Normal file
View file

@ -0,0 +1,104 @@
//-----------------------------------------------------------------------------
// Jonathan Westhues, Sept 2005
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Common string.h functions
//-----------------------------------------------------------------------------
#include "string.h"
#include <stdint.h>
void *memcpy(void *dest, const void *src, size_t len) {
uint8_t *d = dest;
const uint8_t *s = src;
while((len--) > 0) {
*d = *s;
d++;
s++;
}
return dest;
}
void *memset(void *dest, int c, size_t len) {
uint8_t *d = dest;
while((len--) > 0) {
*d = c;
d++;
}
return dest;
}
void *memmove(void *dest, const void *src, size_t len) {
uint8_t *d = dest;
const uint8_t *s = src;
if (dest <= src) {
while((len--) > 0) {
*d = *s;
d++;
s++;
}
} else {
d = d + len - 1;
s = s + len - 1;
while((len--) > 0) {
*d = *s;
d--;
s--;
}
}
return dest;
}
int memcmp(const void *av, const void *bv, size_t len) {
const uint8_t *a = av;
const uint8_t *b = bv;
while((len--) > 0) {
if(*a != *b) {
return *a - *b;
}
a++;
b++;
}
return 0;
}
size_t strlen(const char *str) {
int l = 0;
while(*str) {
l++;
str++;
}
return l;
}
char* strncat(char *dest, const char *src, size_t n) {
unsigned int dest_len = strlen(dest);
unsigned int i;
for (i = 0 ; i < n && src[i] != '\0' ; i++)
dest[dest_len + i] = src[i];
dest[dest_len + i] = '\0';
return dest;
}
char* strcat(char *dest, const char *src) {
unsigned int dest_len = strlen(dest);
unsigned int i;
for (i = 0 ; src[i] != '\0' ; i++)
dest[dest_len + i] = src[i];
dest[dest_len + i] = '\0';
return dest;
}

View file

@ -1,27 +1,25 @@
//-----------------------------------------------------------------------------
// Jonathan Westhues, Aug 2005
// Copyright (C) 2010 Hector Martin "marcan" <marcan@marcansoft.com>
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Replacement stdint.h because GCC doesn't come with it yet (C99)
// Common string.h functions
//-----------------------------------------------------------------------------
#ifndef __STDINT_H
#define __STDINT_H
#ifndef __STRING_H
#define __STRING_H
typedef signed char int8_t;
typedef short int int16_t;
typedef int int32_t;
typedef long long int int64_t;
#include <stddef.h>
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;
void *memcpy(void *dest, const void *src, size_t len);
void *memset(void *dest, int c, size_t len);
void *memmove(void *dest, const void *src, size_t len);
int memcmp(const void *av, const void *bv, size_t len);
size_t strlen(const char *str);
char *strncat(char *dest, const char *src, size_t n);
char *strcat(char *dest, const char *src);
typedef int intptr_t;
typedef unsigned int uintptr_t;
#endif /* __STDINT_H */
#endif /* __STRING_H */

View file

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd ">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key> <string>English</string>
<key>CFBundleIdentifier</key> <string>org.proxmark</string>
<key>CFBundleIconFile</key> <string></string>
<key>CFBundleInfoDictionaryVersion</key> <string>6.0</string>
<key>CFBundlePackageType</key> <string>KEXT</string>
<key>CFBundleSignature</key> <string>????</string>
<key>CFBundleVersion</key> <string>1.0.0</string>
<key>IOKitPersonalities</key>
<dict>
<key>Proxmark3</key>
<dict>
<key>CFBundleIdentifier</key><string>com.apple.kernel.iokit</string>
<key>IOClass</key><string>IOService</string>
<key>IOProviderClass</key><string>IOUSBInterface</string>
<key>bConfigurationValue</key> <integer>1</integer>
<key>bInterfaceNumber</key> <integer>0</integer>
<key>idProduct</key><integer>19343</integer>
<key>idVendor</key><integer>39620</integer>
</dict>
</dict>
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.iokit.IOUSBFamily</key><string>1.8</string>
</dict>
</dict>
</plist>

View file

@ -3,70 +3,178 @@
# at your option, any later version. See the LICENSE.txt file for the text of
# the license.
#-----------------------------------------------------------------------------
include ../common/Makefile.common
CC = gcc
CXX = g++
LD = g++
TAR = tar
TARFLAGS = -C .. --ignore-failed-read -rvf
RM = rm -f
MV = mv
CC=gcc
CXX=g++
#COMMON_FLAGS = -m32
VPATH = ../common
ENV_LDFLAGS := $(LDFLAGS)
ENV_CFLAGS := $(CFLAGS)
VPATH = ../common ../zlib ../uart
OBJDIR = obj
LDLIBS = -L/opt/local/lib -L/usr/local/lib -lreadline -lpthread ../liblua/liblua.a
LDFLAGS = $(COMMON_FLAGS)
CFLAGS = -std=c99 -I. -I../include -I../common -I/opt/local/include -I../liblua -Wall $(COMMON_FLAGS) -g -O4
LUAPLATFORM = generic
LDLIBS = -L/opt/local/lib -L/usr/local/lib -lreadline -lpthread -lm
LUALIB = ../liblua/liblua.a
JANSSONLIBPATH = ./jansson
JANSSONLIB = $(JANSSONLIBPATH)/libjansson.a
MBEDTLSLIBPATH = ../common/mbedtls
MBEDTLSLIB = $(MBEDTLSLIBPATH)/libmbedtls.a
CBORLIBPATH = ./tinycbor
CBORLIB = $(CBORLIBPATH)/tinycbor.a
LIBINCLUDES = -I../zlib -I../uart -I../liblua -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH)
INCLUDES_CLIENT = -I. -I../include -I../common -I/opt/local/include $(LIBINCLUDES)
LDFLAGS = $(ENV_LDFLAGS)
CFLAGS = $(ENV_CFLAGS) -std=c99 -D_ISOC99_SOURCE $(INCLUDES_CLIENT) -Wall -g -O3
CXXFLAGS = -I../include -Wall -O3
APP_CFLAGS =
include ../common/Makefile_Enabled_Options.common
CFLAGS += $(APP_CFLAGS)
ifneq (,$(findstring WITH_SMARTCARD,$(APP_CFLAGS)))
SRC_SMARTCARD = cmdsmartcard.c pcsc.c
else
SRC_SMARTCARD =
endif
platform = $(shell uname)
ifneq (,$(findstring MINGW,$(platform)))
CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
QTLDLIBS = -L$(QTDIR)/lib -lQtCore4 -lQtGui4
MOC = $(QTDIR)/bin/moc
LUAPLATFORM = mingw
else ifeq ($(platform),Darwin)
#CXXFLAGS = -I/Library/Frameworks/QtGui.framework/Versions/Current/Headers -I/Library/Frameworks/QtCore.framework/Versions/Current/Headers
#QTLDLIBS = -framework QtGui -framework QtCore
CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
QTLDLIBS = -F/opt/local/Library/Frameworks -framework QtGui -framework QtCore
MOC = moc
LUAPLATFORM = macosx
PCSC_INCLUDES :=
PCSC_LIBS = -lwinscard
else
CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O4
QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
MOC = $(shell pkg-config --variable=moc_location QtCore)
LDLIBS += -ldl
ifeq ($(platform),Darwin)
PCSC_INCLUDES =
PCSC_LIBS = -framework PCSC
else
PCSC_INCLUDES := $(shell pkg-config --cflags libpcsclite)
PCSC_LIBS := $(shell pkg-config --libs libpcsclite)
endif
endif
# Below is a variant you can use if you have problems compiling with QT5 on ubuntu. see http://www.proxmark.org/forum/viewtopic.php?id=1661 for more info.
#MOC = /usr/lib/x86_64-linux-gnu/qt4/bin/moc
LUAPLATFORM = linux
LUAPLATFORM = generic
ifneq (,$(findstring MINGW,$(platform)))
LUAPLATFORM = mingw
else
ifeq ($(platform),Darwin)
LUAPLATFORM = macosx
OBJCSRCS = util_darwin.m
LDFLAGS += -framework Foundation -framework AppKit
else
LUALIB += -ldl
LDLIBS += -ltermcap -lncurses
LUAPLATFORM = linux
endif
endif
ifneq (,$(findstring WITH_GUI,$(APP_CFLAGS)))
# Check for correctly configured Qt5
QTINCLUDES = $(shell pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null)
QTLDLIBS = $(shell pkg-config --libs Qt5Core Qt5Widgets 2>/dev/null)
MOC = $(shell pkg-config --variable=host_bins Qt5Core)/moc
UIC = $(shell pkg-config --variable=host_bins Qt5Core)/uic
ifeq ($(QTINCLUDES), )
# if Qt5 not found check for correctly configured Qt4
QTINCLUDES = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null)
QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
MOC = $(shell pkg-config --variable=moc_location QtCore)
UIC = $(shell pkg-config --variable=uic_location QtCore)
else
CXXFLAGS += -std=c++11 -fPIC
endif
ifeq ($(QTINCLUDES), )
# if both pkg-config commands failed, search in common places
ifneq ($(QTDIR), )
QTINCLUDES = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
QTLDLIBS = -L$(QTDIR)/lib -lQtCore4 -lQtGui4
ifneq ($(wildcard $(QTDIR)/include/QtWidgets),)
QTINCLUDES += -I$(QTDIR)/include/QtWidgets
QTLDLIBS = -L$(QTDIR)/lib -lQt5Widgets -lQt5Gui -lQt5Core
CXXFLAGS += -std=c++11 -fPIC
endif
MOC = $(QTDIR)/bin/moc
UIC = $(QTDIR)/bin/uic
endif
endif
endif
ifneq ($(QTLDLIBS),)
QTGUI = $(OBJDIR)/proxgui.o $(OBJDIR)/proxguiqt.o $(OBJDIR)/proxguiqt.moc.o
CFLAGS += -DHAVE_GUI
LINK.o = $(LINK.cpp)
ifneq ($(QTLDLIBS), )
QTGUIOBJS = $(OBJDIR)/proxgui.o $(OBJDIR)/proxguiqt.o $(OBJDIR)/proxguiqt.moc.o
CFLAGS += -DHAVE_GUI
else
QTGUI = guidummy.o
QTGUIOBJS = $(OBJDIR)/guidummy.o
endif
CORESRCS = uart.c \
util.c \
sleep.c
# Flags to generate temporary dependency files
DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td
# make temporary to final dependeny files after successful compilation
POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d
CMDSRCS = nonce2key/crapto1.c\
nonce2key/crypto1.c\
nonce2key/nonce2key.c\
mifarehost.c\
CORESRCS = uart_posix.c \
uart_win32.c \
util.c \
util_posix.c \
ui.c \
comms.c
CMDSRCS = $(SRC_SMARTCARD) \
crapto1/crapto1.c\
crapto1/crypto1.c\
crypto/libpcrypto.c\
crypto/asn1utils.c\
crypto/asn1dump.c\
cliparser/argtable3.c\
cliparser/cliparser.c\
fido/additional_ca.c \
fido/cose.c \
fido/cbortools.c \
fido/fidocore.c \
mifare/mfkey.c \
loclass/cipher.c \
loclass/cipherutils.c \
loclass/ikeys.c \
loclass/elite_crack.c\
loclass/fileutils.c\
whereami.c\
mifare/mifarehost.c\
mifare/mifare4.c\
mifare/mad.c \
mifare/ndef.c \
parity.c\
crc.c \
crc16.c \
crc64.c \
iso14443crc.c \
iso15693tools.c \
data.c \
graph.c \
ui.c \
cmddata.c \
lfdemod.c \
emv/crypto_polarssl.c\
emv/crypto.c\
emv/emv_pk.c\
emv/emv_pki.c\
emv/emv_pki_priv.c\
emv/test/cryptotest.c\
emv/apduinfo.c\
emv/dump.c\
emv/tlv.c\
emv/emv_tags.c\
emv/dol.c\
emv/emvjson.c\
emv/emvcore.c\
emv/test/crypto_test.c\
emv/test/sda_test.c\
emv/test/dda_test.c\
emv/test/cda_test.c\
emv/cmdemv.c\
emv/emv_roca.c \
cmdhf.c \
cmdhflist.c \
cmdhf14a.c \
cmdhf14b.c \
cmdhf15.c \
@ -74,77 +182,200 @@ CMDSRCS = nonce2key/crapto1.c\
cmdhflegic.c \
cmdhficlass.c \
cmdhfmf.c \
cmdhfmfp.c \
cmdhfmfu.c \
cmdhfmfhard.c \
hardnested/hardnested_bruteforce.c \
cmdhftopaz.c \
cmdhffido.c \
cmdhw.c \
cmdlf.c \
cmdlfhid.c \
cmdlfio.c \
cmdlfawid.c \
cmdlfcotag.c\
cmdlfem4x.c \
cmdlffdx.c \
cmdlfgproxii.c \
hidcardformatutils.c\
hidcardformats.c\
cmdlfhid.c \
cmdlfhitag.c \
cmdlfio.c \
cmdlfindala.c \
cmdlfjablotron.c \
cmdlfnexwatch.c \
cmdlfnoralsy.c \
cmdlfparadox.c \
cmdlfpcf7931.c \
cmdlfpresco.c \
cmdlfpyramid.c \
cmdlfsecurakey.c \
cmdlft55xx.c \
cmdlfti.c \
cmdlfviking.c\
cmdlfvisa2000.c\
cmdlfpac.c\
cmdparser.c \
cmdmain.c \
cmdlft55xx.c \
cmdlfpcf7931.c\
pm3_binlib.c\
scripting.c\
cmdscript.c\
pm3_binlib.c\
pm3_bitlib.c\
protocols.c\
taginfo.c
cpu_arch = $(shell uname -m)
ifneq ($(findstring 86, $(cpu_arch)), )
MULTIARCHSRCS = hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c
endif
ifneq ($(findstring amd64, $(cpu_arch)), )
MULTIARCHSRCS = hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c
endif
ifeq ($(MULTIARCHSRCS), )
CMDSRCS += hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c
endif
ZLIBSRCS = deflate.c adler32.c trees.c zutil.c inflate.c inffast.c inftrees.c
ZLIBFLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED
#-DDEBUG -Dverbose=1
QTGUISRCS = proxgui.cpp proxguiqt.cpp proxguiqt.moc.cpp guidummy.cpp
COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o)
CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o)
OBJCOBJS = $(OBJCSRCS:%.m=$(OBJDIR)/%.o)
ZLIBOBJS = $(ZLIBSRCS:%.c=$(OBJDIR)/%.o)
MULTIARCHOBJS = $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_NOSIMD.o) \
$(MULTIARCHSRCS:%.c=$(OBJDIR)/%_MMX.o) \
$(MULTIARCHSRCS:%.c=$(OBJDIR)/%_SSE2.o) \
$(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX.o) \
$(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX2.o)
RM = rm -f
BINS = proxmark3 flasher #snooper cli
CLEAN = cli cli.exe flasher flasher.exe proxmark3 proxmark3.exe snooper snooper.exe $(CMDOBJS) $(OBJDIR)/*.o *.o *.moc.cpp
SUPPORTS_AVX512 := $(shell echo | gcc -E -mavx512f - > /dev/null 2>&1 && echo "True" )
HARD_SWITCH_NOSIMD = -mno-mmx -mno-sse2 -mno-avx -mno-avx2
HARD_SWITCH_MMX = -mmmx -mno-sse2 -mno-avx -mno-avx2
HARD_SWITCH_SSE2 = -mmmx -msse2 -mno-avx -mno-avx2
HARD_SWITCH_AVX = -mmmx -msse2 -mavx -mno-avx2
HARD_SWITCH_AVX2 = -mmmx -msse2 -mavx -mavx2
HARD_SWITCH_AVX512 = -mmmx -msse2 -mavx -mavx2 -mavx512f
ifeq "$(SUPPORTS_AVX512)" "True"
HARD_SWITCH_NOSIMD += -mno-avx512f
HARD_SWITCH_MMX += -mno-avx512f
HARD_SWITCH_SSE2 += -mno-avx512f
HARD_SWITCH_AVX += -mno-avx512f
HARD_SWITCH_AVX2 += -mno-avx512f
MULTIARCHOBJS += $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX512.o)
endif
BINS = proxmark3 flasher fpga_compress
WINBINS = $(patsubst %, %.exe, $(BINS))
CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h lualibs/usb_cmd.lua
all: lua_build $(BINS)
# need to assign dependancies to build these first...
all: lua_build jansson_build mbedtls_build cbor_build $(BINS)
all-static: LDLIBS:=-static $(LDLIBS)
all-static: snooper cli flasher
proxmark3: LDLIBS+=$(QTLDLIBS)
proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUI)
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
all-static: proxmark3 flasher fpga_compress
snooper: $(OBJDIR)/snooper.o $(COREOBJS) $(CMDOBJS) $(OBJDIR)/guidummy.o
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(QTLDLIBS) $(PCSC_LIBS)
proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) lualibs/usb_cmd.lua
$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) $(LDLIBS) -o $@
cli: $(OBJDIR)/cli.o $(COREOBJS) $(CMDOBJS) $(OBJDIR)/guidummy.o
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS) $(OBJCOBJS)
$(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@
flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS)
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
fpga_compress: $(OBJDIR)/fpga_compress.o $(ZLIBOBJS)
$(LD) $(LDFLAGS) $(ZLIBFLAGS) $^ $(LDLIBS) -o $@
$(OBJDIR)/%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
proxgui.cpp: ui/ui_overlays.h
proxguiqt.moc.cpp: proxguiqt.h
$(MOC) -o$@ $^
ui/ui_overlays.h: ui/overlays.ui
$(UIC) $^ > $@
lualibs/usb_cmd.lua: ../include/usb_cmd.h
awk -f usb_cmd_h2lua.awk $^ > $@
clean:
$(RM) $(CLEAN)
cd ../liblua && make clean
cd $(JANSSONLIBPATH) && make clean
cd $(MBEDTLSLIBPATH) && make clean
cd $(CBORLIBPATH) && make clean
tarbin: $(BINS)
$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%)
# must be run as root
install_kext: Info.plist
mkdir -p /System/Library/Extensions/Proxmark3.kext/Contents
cp Info.plist /System/Library/Extensions/Proxmark3.kext/Contents
chown -R root:wheel /System/Library/Extensions/Proxmark3.kext
chmod 755 /System/Library/Extensions/Proxmark3.kext /System/Library/Extensions/Proxmark3.kext/Contents
chmod 644 /System/Library/Extensions/Proxmark3.kext/Contents/Info.plist
rm -rf /System/Library/Caches/com.apple.kext.caches
touch /System/Library/Extensions
@echo "*** You may need to reboot for the kext to take effect."
$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%) $(WINBINS:%=client/%)
lua_build:
@echo Compiling liblua, using platform $(LUAPLATFORM)
cd ../liblua && make $(LUAPLATFORM)
jansson_build:
@echo Compiling jansson
cd $(JANSSONLIBPATH) && make all
mbedtls_build:
@echo Compiling mbedtls
cd $(MBEDTLSLIBPATH) && make all
cbor_build:
@echo Compiling tinycbor
cd $(CBORLIBPATH) && make all
.PHONY: all clean
$(OBJDIR)/%_NOSIMD.o : %.c $(OBJDIR)/%.d
$(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $<
$(OBJDIR)/%_MMX.o : %.c $(OBJDIR)/%.d
$(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $<
$(OBJDIR)/%_SSE2.o : %.c $(OBJDIR)/%.d
$(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $<
$(OBJDIR)/%_AVX.o : %.c $(OBJDIR)/%.d
$(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $<
$(OBJDIR)/%_AVX2.o : %.c $(OBJDIR)/%.d
$(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $<
$(OBJDIR)/%_AVX512.o : %.c $(OBJDIR)/%.d
$(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $<
%.o: %.c
$(OBJDIR)/%.o : %.c $(OBJDIR)/%.d
$(CC) $(DEPFLAGS) $(CFLAGS) $(ZLIBFLAGS) $(PCSC_INCLUDES) -c -o $@ $<
$(POSTCOMPILE)
%.o: %.cpp
$(OBJDIR)/%.o : %.cpp $(OBJDIR)/%.d
$(CXX) $(DEPFLAGS) $(CXXFLAGS) $(QTINCLUDES) -c -o $@ $<
$(POSTCOMPILE)
%.o: %.m
$(OBJDIR)/%.o : %.m $(OBJDIR)/%.d
$(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
$(POSTCOMPILE)
#$(CMDOBJS) $(COREOBJS): $(notdir $(%.c)) %.d
# $(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
# $(POSTCOMPILE)
#$(ZLIBOBJS): $(notdir $(%.c)) %.d
# $(CC) $(DEPFLAGS) $(CFLAGS) $(ZLIBFLAGS) -c -o $@ $<
# $(POSTCOMPILE)
#$(QTGUIOBJS): $(notdir $(%.cpp)) %.d
# $(CXX) $(DEPFLAGS) $(CXXFLAGS) -c -o $@ $<
# $(POSTCOMPILE)
DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(ZLIBSRCS) $(MULTIARCHSRCS)) \
$(patsubst %.cpp, $(OBJDIR)/%.d, $(QTGUISRCS)) \
$(patsubst %.m, $(OBJDIR)/%.d, $(OBJCSRCS)) \
$(OBJDIR)/proxmark3.d $(OBJDIR)/flash.d $(OBJDIR)/flasher.d $(OBJDIR)/fpga_compress.d
$(DEPENDENCY_FILES): ;
.PRECIOUS: $(DEPENDENCY_FILES)
-include $(DEPENDENCY_FILES)

View file

@ -1,58 +0,0 @@
//-----------------------------------------------------------------------------
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Command line binary
//-----------------------------------------------------------------------------
#include <stdio.h>
#include "sleep.h"
#include "ui.h"
#include "proxusb.h"
#include "cmdmain.h"
#define HANDLE_ERROR if (error_occured) { \
error_occured = 0;\
break;\
}
int main(int argc, char **argv)
{
if (argc != 3 && argc != 4)
{
printf("\n\tusage: cli <command 1> <command 2> [logfile (default cli.log)]\n");
printf("\n");
printf("\texample: cli hi14asnoop hi14alist h14a.log\n");
printf("\n");
return -1;
}
usb_init();
if (argc == 4)
SetLogFilename(argv[3]);
else
SetLogFilename("cli.log");
return_on_error = 1;
while (1) {
while (!OpenProxmark(0)) { sleep(1); }
while (1) {
UsbCommand cmdbuf;
CommandReceived(argv[1]);
HANDLE_ERROR;
ReceiveCommand(&cmdbuf);
HANDLE_ERROR;
for (int i = 0; i < 5; ++i) {
ReceiveCommandPoll(&cmdbuf);
}
HANDLE_ERROR;
CommandReceived(argv[2]);
HANDLE_ERROR;
}
}
CloseProxmark();
return 0;
}

View file

@ -0,0 +1,13 @@
# Command line parser
cliparser - librari for proxmark with command line parsing high level functions.
## External libraries:
### argtable
Argtable3 is a single-file, ANSI C, command-line parsing library that parses GNU-style command-line options.
You can download argtable3 from this repository https://github.com/argtable/argtable3
[argtable3 license](https://github.com/argtable/argtable3/blob/master/LICENSE)

5996
client/cliparser/argtable3.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,273 @@
/*******************************************************************************
* argtable3: Declares the main interfaces of the library
*
* This file is part of the argtable3 library.
*
* Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann
* <sheitmann@users.sourceforge.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of STEWART HEITMANN nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#ifndef ARGTABLE3
#define ARGTABLE3
#include <stdio.h> /* FILE */
#include <time.h> /* struct tm */
#ifdef __cplusplus
extern "C" {
#endif
#define ARG_REX_ICASE 1
#define ARG_DSTR_SIZE 200
#define ARG_CMD_NAME_LEN 100
#define ARG_CMD_DESCRIPTION_LEN 256
#ifndef ARG_REPLACE_GETOPT
#define ARG_REPLACE_GETOPT 1 /* use the embedded getopt as the system getopt(3) */
#endif /* ARG_REPLACE_GETOPT */
/* bit masks for arg_hdr.flag */
enum { ARG_TERMINATOR = 0x1, ARG_HASVALUE = 0x2, ARG_HASOPTVALUE = 0x4 };
#if defined(_WIN32)
#if defined(argtable3_EXPORTS)
#define ARG_EXTERN __declspec(dllexport)
#elif defined(argtable3_IMPORTS)
#define ARG_EXTERN __declspec(dllimport)
#else
#define ARG_EXTERN
#endif
#else
#define ARG_EXTERN
#endif
typedef struct _internal_arg_dstr* arg_dstr_t;
typedef void* arg_cmd_itr_t;
typedef void(arg_resetfn)(void* parent);
typedef int(arg_scanfn)(void* parent, const char* argval);
typedef int(arg_checkfn)(void* parent);
typedef void(arg_errorfn)(void* parent, arg_dstr_t ds, int error, const char* argval, const char* progname);
typedef void(arg_dstr_freefn)(char* buf);
typedef int(arg_cmdfn)(int argc, char* argv[], arg_dstr_t res);
typedef int(arg_comparefn)(const void* k1, const void* k2);
/*
* The arg_hdr struct defines properties that are common to all arg_xxx structs.
* The argtable library requires each arg_xxx struct to have an arg_hdr
* struct as its first data member.
* The argtable library functions then use this data to identify the
* properties of the command line option, such as its option tags,
* datatype string, and glossary strings, and so on.
* Moreover, the arg_hdr struct contains pointers to custom functions that
* are provided by each arg_xxx struct which perform the tasks of parsing
* that particular arg_xxx arguments, performing post-parse checks, and
* reporting errors.
* These functions are private to the individual arg_xxx source code
* and are the pointer to them are initiliased by that arg_xxx struct's
* constructor function. The user could alter them after construction
* if desired, but the original intention is for them to be set by the
* constructor and left unaltered.
*/
typedef struct arg_hdr {
char flag; /* Modifier flags: ARG_TERMINATOR, ARG_HASVALUE. */
const char* shortopts; /* String defining the short options */
const char* longopts; /* String defiing the long options */
const char* datatype; /* Description of the argument data type */
const char* glossary; /* Description of the option as shown by arg_print_glossary function */
int mincount; /* Minimum number of occurences of this option accepted */
int maxcount; /* Maximum number of occurences if this option accepted */
void* parent; /* Pointer to parent arg_xxx struct */
arg_resetfn* resetfn; /* Pointer to parent arg_xxx reset function */
arg_scanfn* scanfn; /* Pointer to parent arg_xxx scan function */
arg_checkfn* checkfn; /* Pointer to parent arg_xxx check function */
arg_errorfn* errorfn; /* Pointer to parent arg_xxx error function */
void* priv; /* Pointer to private header data for use by arg_xxx functions */
} arg_hdr_t;
typedef struct arg_rem {
struct arg_hdr hdr; /* The mandatory argtable header struct */
} arg_rem_t;
typedef struct arg_lit {
struct arg_hdr hdr; /* The mandatory argtable header struct */
int count; /* Number of matching command line args */
} arg_lit_t;
typedef struct arg_int {
struct arg_hdr hdr; /* The mandatory argtable header struct */
int count; /* Number of matching command line args */
int* ival; /* Array of parsed argument values */
} arg_int_t;
typedef struct arg_dbl {
struct arg_hdr hdr; /* The mandatory argtable header struct */
int count; /* Number of matching command line args */
double* dval; /* Array of parsed argument values */
} arg_dbl_t;
typedef struct arg_str {
struct arg_hdr hdr; /* The mandatory argtable header struct */
int count; /* Number of matching command line args */
const char** sval; /* Array of parsed argument values */
} arg_str_t;
typedef struct arg_rex {
struct arg_hdr hdr; /* The mandatory argtable header struct */
int count; /* Number of matching command line args */
const char** sval; /* Array of parsed argument values */
} arg_rex_t;
typedef struct arg_file {
struct arg_hdr hdr; /* The mandatory argtable header struct */
int count; /* Number of matching command line args*/
const char** filename; /* Array of parsed filenames (eg: /home/foo.bar) */
const char** basename; /* Array of parsed basenames (eg: foo.bar) */
const char** extension; /* Array of parsed extensions (eg: .bar) */
} arg_file_t;
typedef struct arg_date {
struct arg_hdr hdr; /* The mandatory argtable header struct */
const char* format; /* strptime format string used to parse the date */
int count; /* Number of matching command line args */
struct tm* tmval; /* Array of parsed time values */
} arg_date_t;
enum { ARG_ELIMIT = 1, ARG_EMALLOC, ARG_ENOMATCH, ARG_ELONGOPT, ARG_EMISSARG };
typedef struct arg_end {
struct arg_hdr hdr; /* The mandatory argtable header struct */
int count; /* Number of errors encountered */
int* error; /* Array of error codes */
void** parent; /* Array of pointers to offending arg_xxx struct */
const char** argval; /* Array of pointers to offending argv[] string */
} arg_end_t;
typedef struct arg_cmd_info {
char name[ARG_CMD_NAME_LEN];
char description[ARG_CMD_DESCRIPTION_LEN];
arg_cmdfn* proc;
} arg_cmd_info_t;
/**** arg_xxx constructor functions *********************************/
ARG_EXTERN struct arg_rem* arg_rem(const char* datatype, const char* glossary);
ARG_EXTERN struct arg_lit* arg_lit0(const char* shortopts, const char* longopts, const char* glossary);
ARG_EXTERN struct arg_lit* arg_lit1(const char* shortopts, const char* longopts, const char* glossary);
ARG_EXTERN struct arg_lit* arg_litn(const char* shortopts, const char* longopts, int mincount, int maxcount, const char* glossary);
ARG_EXTERN struct arg_int* arg_int0(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_int* arg_int1(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_int* arg_intn(const char* shortopts, const char* longopts, const char* datatype, int mincount, int maxcount, const char* glossary);
ARG_EXTERN struct arg_dbl* arg_dbl0(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_dbl* arg_dbl1(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_dbl* arg_dbln(const char* shortopts, const char* longopts, const char* datatype, int mincount, int maxcount, const char* glossary);
ARG_EXTERN struct arg_str* arg_str0(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_str* arg_str1(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_str* arg_strn(const char* shortopts, const char* longopts, const char* datatype, int mincount, int maxcount, const char* glossary);
ARG_EXTERN struct arg_rex* arg_rex0(const char* shortopts, const char* longopts, const char* pattern, const char* datatype, int flags, const char* glossary);
ARG_EXTERN struct arg_rex* arg_rex1(const char* shortopts, const char* longopts, const char* pattern, const char* datatype, int flags, const char* glossary);
ARG_EXTERN struct arg_rex* arg_rexn(const char* shortopts,
const char* longopts,
const char* pattern,
const char* datatype,
int mincount,
int maxcount,
int flags,
const char* glossary);
ARG_EXTERN struct arg_file* arg_file0(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_file* arg_file1(const char* shortopts, const char* longopts, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_file* arg_filen(const char* shortopts, const char* longopts, const char* datatype, int mincount, int maxcount, const char* glossary);
ARG_EXTERN struct arg_date* arg_date0(const char* shortopts, const char* longopts, const char* format, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_date* arg_date1(const char* shortopts, const char* longopts, const char* format, const char* datatype, const char* glossary);
ARG_EXTERN struct arg_date* arg_daten(const char* shortopts, const char* longopts, const char* format, const char* datatype, int mincount, int maxcount, const char* glossary);
ARG_EXTERN struct arg_end* arg_end(int maxerrors);
#define ARG_DSTR_STATIC ((arg_dstr_freefn*)0)
#define ARG_DSTR_VOLATILE ((arg_dstr_freefn*)1)
#define ARG_DSTR_DYNAMIC ((arg_dstr_freefn*)3)
/**** other functions *******************************************/
ARG_EXTERN int arg_nullcheck(void** argtable);
ARG_EXTERN int arg_parse(int argc, char** argv, void** argtable);
ARG_EXTERN void arg_print_option(FILE* fp, const char* shortopts, const char* longopts, const char* datatype, const char* suffix);
ARG_EXTERN void arg_print_syntax(FILE* fp, void** argtable, const char* suffix);
ARG_EXTERN void arg_print_syntaxv(FILE* fp, void** argtable, const char* suffix);
ARG_EXTERN void arg_print_glossary(FILE* fp, void** argtable, const char* format);
ARG_EXTERN void arg_print_glossary_gnu(FILE* fp, void** argtable);
ARG_EXTERN void arg_print_errors(FILE* fp, struct arg_end* end, const char* progname);
ARG_EXTERN void arg_print_option_ds(arg_dstr_t ds, const char* shortopts, const char* longopts, const char* datatype, const char* suffix);
ARG_EXTERN void arg_print_syntax_ds(arg_dstr_t ds, void** argtable, const char* suffix);
ARG_EXTERN void arg_print_syntaxv_ds(arg_dstr_t ds, void** argtable, const char* suffix);
ARG_EXTERN void arg_print_glossary_ds(arg_dstr_t ds, void** argtable, const char* format);
ARG_EXTERN void arg_print_glossary_gnu_ds(arg_dstr_t ds, void** argtable);
ARG_EXTERN void arg_print_errors_ds(arg_dstr_t ds, struct arg_end* end, const char* progname);
ARG_EXTERN void arg_freetable(void** argtable, size_t n);
ARG_EXTERN arg_dstr_t arg_dstr_create(void);
ARG_EXTERN void arg_dstr_destroy(arg_dstr_t ds);
ARG_EXTERN void arg_dstr_reset(arg_dstr_t ds);
ARG_EXTERN void arg_dstr_free(arg_dstr_t ds);
ARG_EXTERN void arg_dstr_set(arg_dstr_t ds, char* str, arg_dstr_freefn* free_proc);
ARG_EXTERN void arg_dstr_cat(arg_dstr_t ds, const char* str);
ARG_EXTERN void arg_dstr_catc(arg_dstr_t ds, char c);
ARG_EXTERN void arg_dstr_catf(arg_dstr_t ds, const char* fmt, ...);
ARG_EXTERN char* arg_dstr_cstr(arg_dstr_t ds);
ARG_EXTERN void arg_cmd_init(void);
ARG_EXTERN void arg_cmd_uninit(void);
ARG_EXTERN void arg_cmd_register(const char* name, arg_cmdfn* proc, const char* description);
ARG_EXTERN void arg_cmd_unregister(const char* name);
ARG_EXTERN int arg_cmd_dispatch(const char* name, int argc, char* argv[], arg_dstr_t res);
ARG_EXTERN unsigned int arg_cmd_count(void);
ARG_EXTERN arg_cmd_info_t* arg_cmd_info(const char* name);
ARG_EXTERN arg_cmd_itr_t arg_cmd_itr_create(void);
ARG_EXTERN void arg_cmd_itr_destroy(arg_cmd_itr_t itr);
ARG_EXTERN int arg_cmd_itr_advance(arg_cmd_itr_t itr);
ARG_EXTERN char* arg_cmd_itr_key(arg_cmd_itr_t itr);
ARG_EXTERN arg_cmd_info_t* arg_cmd_itr_value(arg_cmd_itr_t itr);
ARG_EXTERN int arg_cmd_itr_search(arg_cmd_itr_t itr, void* k);
ARG_EXTERN void arg_mgsort(void* data, int size, int esize, int i, int k, arg_comparefn* comparefn);
ARG_EXTERN void arg_make_get_help_msg(arg_dstr_t res);
ARG_EXTERN void arg_make_help_msg(arg_dstr_t ds, char* cmd_name, void** argtable);
ARG_EXTERN void arg_make_syntax_err_msg(arg_dstr_t ds, void** argtable, struct arg_end* end);
ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds, char* name, int help, int nerrors, void** argtable, struct arg_end* end, int* exitcode);
ARG_EXTERN void arg_set_module_name(const char* name);
ARG_EXTERN void arg_set_module_version(int major, int minor, int patch, const char* tag);
/**** deprecated functions, for back-compatibility only ********/
ARG_EXTERN void arg_free(void** argtable);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,205 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2017 Merlok
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Command line parser core commands
//-----------------------------------------------------------------------------
#include "cliparser.h"
#include <stdio.h>
#include <string.h>
void **argtable = NULL;
size_t argtableLen = 0;
char *programName = NULL;
char *programHint = NULL;
char *programHelp = NULL;
char buf[500] = {0};
int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp) {
argtable = NULL;
argtableLen = 0;
programName = vprogramName;
programHint = vprogramHint;
programHelp = vprogramHelp;
memset(buf, 0x00, 500);
return 0;
}
int CLIParserParseArg(int argc, char **argv, void* vargtable[], size_t vargtableLen, bool allowEmptyExec) {
int nerrors;
argtable = vargtable;
argtableLen = vargtableLen;
/* verify the argtable[] entries were allocated sucessfully */
if (arg_nullcheck(argtable) != 0) {
/* NULL entries were detected, some allocations must have failed */
printf("ERROR: Insufficient memory\n");
return 2;
}
/* Parse the command line as defined by argtable[] */
nerrors = arg_parse(argc, argv, argtable);
/* special case: '--help' takes precedence over error reporting */
if ((argc < 2 && !allowEmptyExec) ||((struct arg_lit *)argtable[0])->count > 0) { // help must be the first record
printf("Usage: %s", programName);
arg_print_syntaxv(stdout, argtable, "\n");
if (programHint)
printf("%s\n\n", programHint);
arg_print_glossary(stdout, argtable, " %-20s %s\n");
printf("\n");
if (programHelp)
printf("%s \n", programHelp);
return 1;
}
/* If the parser returned any errors then display them and exit */
if (nerrors > 0) {
/* Display the error details contained in the arg_end struct.*/
arg_print_errors(stdout, ((struct arg_end *)argtable[vargtableLen - 1]), programName);
printf("Try '%s --help' for more information.\n", programName);
return 3;
}
return 0;
}
enum ParserState {
PS_FIRST,
PS_ARGUMENT,
PS_OPTION,
};
#define isSpace(c)(c == ' ' || c == '\t')
int CLIParserParseString(const char* str, void* vargtable[], size_t vargtableLen, bool allowEmptyExec) {
return CLIParserParseStringEx(str, vargtable, vargtableLen, allowEmptyExec, false);
}
int CLIParserParseStringEx(const char* str, void* vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData) {
int argc = 0;
char *argv[200] = {NULL};
int len = strlen(str);
char *bufptr = buf;
char *spaceptr = NULL;
enum ParserState state = PS_FIRST;
argv[argc++] = bufptr;
// param0 = program name
memcpy(buf, programName, strlen(programName) + 1); // with 0x00
bufptr += strlen(programName) + 1;
if (len)
argv[argc++] = bufptr;
// parse params
for (int i = 0; i < len; i++) {
switch(state){
case PS_FIRST: // first char
if (!clueData || str[i] == '-'){ // first char before space is '-' - next element - option OR not "clueData" for not-option fields
state = PS_OPTION;
if (spaceptr) {
bufptr = spaceptr;
*bufptr = 0x00;
bufptr++;
argv[argc++] = bufptr;
}
}
spaceptr = NULL;
case PS_ARGUMENT:
if (state == PS_FIRST)
state = PS_ARGUMENT;
if (isSpace(str[i])) {
spaceptr = bufptr;
state = PS_FIRST;
}
*bufptr = str[i];
bufptr++;
break;
case PS_OPTION:
if (isSpace(str[i])){
state = PS_FIRST;
*bufptr = 0x00;
bufptr++;
argv[argc++] = bufptr;
break;
}
*bufptr = str[i];
bufptr++;
break;
}
}
return CLIParserParseArg(argc, argv, vargtable, vargtableLen, allowEmptyExec);
}
void CLIParserFree() {
arg_freetable(argtable, argtableLen);
argtable = NULL;
return;
}
// convertors
int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) {
*datalen = 0;
int ibuf = 0;
uint8_t buf[256] = {0};
int res = CLIParamStrToBuf(argstr, buf, maxdatalen * 2, &ibuf); // *2 because here HEX
if (res || !ibuf)
return res;
switch(param_gethex_to_eol((char *)buf, 0, data, maxdatalen, datalen)) {
case 1:
printf("Parameter error: Invalid HEX value.\n");
return 1;
case 2:
printf("Parameter error: parameter too large.\n");
return 2;
case 3:
printf("Parameter error: Hex string must have even number of digits.\n");
return 3;
}
return 0;
}
int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) {
*datalen = 0;
if (!argstr->count)
return 0;
uint8_t buf[256] = {0};
int ibuf = 0;
for (int i = 0; i < argstr->count; i++) {
int len = strlen(argstr->sval[i]);
memcpy(&buf[ibuf], argstr->sval[i], len);
ibuf += len;
}
buf[ibuf] = 0;
if (!ibuf)
return 0;
if (ibuf > maxdatalen)
return 2;
memcpy(data, buf, ibuf);
*datalen = ibuf;
return 0;
}

View file

@ -0,0 +1,41 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2017 Merlok
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Command line parser core commands
//-----------------------------------------------------------------------------
#include "argtable3.h"
#include "util.h"
#include <stdbool.h>
#define arg_param_begin arg_lit0("hH", "help", "print this help and exit")
#define arg_param_end arg_end(20)
#define arg_getsize(a) (sizeof(a) / sizeof(a[0]))
#define arg_get_lit(n)(((struct arg_lit*)argtable[n])->count)
#define arg_get_int_count(n)(((struct arg_int*)argtable[n])->count)
#define arg_get_int(n)(((struct arg_int*)argtable[n])->ival[0])
#define arg_get_int_def(n,def)(arg_get_int_count(n)?(arg_get_int(n)):(def))
#define arg_get_str(n)((struct arg_str*)argtable[n])
#define arg_get_str_len(n)(strlen(((struct arg_str*)argtable[n])->sval[0]))
#define arg_strx1(shortopts, longopts, datatype, glossary) (arg_strn((shortopts), (longopts), (datatype), 1, 250, (glossary)))
#define arg_strx0(shortopts, longopts, datatype, glossary) (arg_strn((shortopts), (longopts), (datatype), 0, 250, (glossary)))
#define CLIExecWithReturn(cmd, atbl, ifempty) if (CLIParserParseString(cmd, atbl, arg_getsize(atbl), ifempty)){CLIParserFree();return 0;}
#define CLIGetHexBLessWithReturn(paramnum, data, datalen, delta) if (CLIParamHexToBuf(arg_get_str(paramnum), data, sizeof(data) - (delta), datalen)) {CLIParserFree();return 1;}
#define CLIGetHexWithReturn(paramnum, data, datalen) if (CLIParamHexToBuf(arg_get_str(paramnum), data, sizeof(data), datalen)) {CLIParserFree();return 1;}
#define CLIGetStrWithReturn(paramnum, data, datalen) if (CLIParamStrToBuf(arg_get_str(paramnum), data, sizeof(data), datalen)) {CLIParserFree();return 1;}
extern int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp);
extern int CLIParserParseString(const char* str, void* argtable[], size_t vargtableLen, bool allowEmptyExec);
extern int CLIParserParseStringEx(const char* str, void* vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData);
extern int CLIParserParseArg(int argc, char **argv, void* argtable[], size_t vargtableLen, bool allowEmptyExec);
extern void CLIParserFree();
extern int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen);
extern int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen);

File diff suppressed because it is too large Load diff

View file

@ -11,34 +11,70 @@
#ifndef CMDDATA_H__
#define CMDDATA_H__
#include <stdlib.h> //size_t
#include <stdint.h> //uint_32+
#include <stdbool.h> //bool
#include "cmdparser.h" // for command_t
command_t * CmdDataCommands();
int CmdData(const char *Cmd);
int CmdAmp(const char *Cmd);
int Cmdaskdemod(const char *Cmd);
void printDemodBuff(void);
void setDemodBuf(uint8_t *buff, size_t size, size_t startIdx);
bool getDemodBuf(uint8_t *buff, size_t *size);
void save_restoreDB(uint8_t saveOpt);// option '1' to save DemodBuffer any other to restore
int CmdPrintDemodBuff(const char *Cmd);
int Cmdaskrawdemod(const char *Cmd);
int Cmdaskmandemod(const char *Cmd);
int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose);
int CmdAutoCorr(const char *Cmd);
int CmdBiphaseDecodeRaw(const char *Cmd);
int CmdBitsamples(const char *Cmd);
int CmdBitstream(const char *Cmd);
int CmdBuffClear(const char *Cmd);
int CmdDec(const char *Cmd);
int CmdDetectClockRate(const char *Cmd);
int CmdFSKdemod(const char *Cmd);
int CmdFSKrawdemod(const char *Cmd);
int CmdPSK1rawDemod(const char *Cmd);
int CmdPSK2rawDemod(const char *Cmd);
int CmdGrid(const char *Cmd);
int CmdGetBitStream(const char *Cmd);
int CmdHexsamples(const char *Cmd);
int CmdHide(const char *Cmd);
int CmdHpf(const char *Cmd);
int CmdLoad(const char *Cmd);
int CmdLtrim(const char *Cmd);
int CmdManchesterDemod(const char *Cmd);
int CmdManchesterMod(const char *Cmd);
int CmdRtrim(const char *Cmd);
int Cmdmandecoderaw(const char *Cmd);
int CmdNorm(const char *Cmd);
int CmdNRZrawDemod(const char *Cmd);
int CmdPlot(const char *Cmd);
int CmdPrintDemodBuff(const char *Cmd);
int CmdRawDemod(const char *Cmd);
int CmdSamples(const char *Cmd);
int CmdTuneSamples(const char *Cmd);
int CmdSave(const char *Cmd);
int CmdScale(const char *Cmd);
int CmdThreshold(const char *Cmd);
int CmdDirectionalThreshold(const char *Cmd);
int CmdZerocrossings(const char *Cmd);
int ASKbiphaseDemod(const char *Cmd, bool verbose);
int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType);
int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck);
int FSKrawDemod(const char *Cmd, bool verbose);
int PSKDemod(const char *Cmd, bool verbose);
int NRZrawDemod(const char *Cmd, bool verbose);
int getSamples(int n, bool silent);
void setClockGrid(int clk, int offset);
int directionalThreshold(const int* in, int *out, size_t len, int8_t up, int8_t down);
extern int AskEdgeDetect(const int *in, int *out, int len, int threshold);
//int autoCorr(const int* in, int *out, size_t len, int window);
#define MAX_DEMOD_BUF_LEN (1024*128)
extern uint8_t DemodBuffer[MAX_DEMOD_BUF_LEN];
extern size_t DemodBufferLen;
extern int g_DemodStartIdx;
extern int g_DemodClock;
extern uint8_t g_debugMode;
#define BIGBUF_SIZE 40000
#endif

View file

@ -1,5 +1,6 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
// Merlok - 2017
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
@ -8,13 +9,14 @@
// High frequency commands
//-----------------------------------------------------------------------------
#include <stdio.h>
//#include "proxusb.h"
#include "proxmark3.h"
#include "graph.h"
#include "cmdhf.h"
#include <math.h>
#include "usb_cmd.h"
#include "comms.h"
#include "ui.h"
#include "cmdparser.h"
#include "cmdhf.h"
#include "cliparser/cliparser.h"
#include "cmdhf14a.h"
#include "cmdhf14b.h"
#include "cmdhf15.h"
@ -22,6 +24,14 @@
#include "cmdhflegic.h"
#include "cmdhficlass.h"
#include "cmdhfmf.h"
#include "cmdhfmfp.h"
#include "cmdhfmfu.h"
#include "cmdhftopaz.h"
#include "cmdhflist.h"
#include "cmdhffido.h"
#include "cmddata.h"
#include "graph.h"
#include "fpga.h"
static int CmdHelp(const char *Cmd);
@ -32,24 +42,124 @@ int CmdHFTune(const char *Cmd)
return 0;
}
static command_t CommandTable[] =
int CmdHFSearch(const char *Cmd){
int ans = 0;
PrintAndLog("");
ans = CmdHF14AInfo("s");
if (ans > 0) {
PrintAndLog("\nValid ISO14443A Tag Found - Quiting Search\n");
return ans;
}
ans = HFiClassReader(false, false);
if (ans) {
PrintAndLog("\nValid iClass Tag (or PicoPass Tag) Found - Quiting Search\n");
return ans;
}
ans = HF15Reader("", false);
if (ans) {
PrintAndLog("\nValid ISO15693 Tag Found - Quiting Search\n");
return ans;
}
//14b is longest test currently (and rarest chip type) ... put last
ans = infoHF14B(false);
if (ans) {
PrintAndLog("\nValid ISO14443B Tag Found - Quiting Search\n");
return ans;
}
ans = CmdLegicRFRead("");
if (ans == 0) {
PrintAndLog("\nValid Legic Tag Found - Quiting Search\n");
return ans;
}
PrintAndLog("\nno known/supported 13.56 MHz tags found\n");
return 0;
}
int CmdHFSnoop(const char *Cmd)
{
{"help", CmdHelp, 1, "This help"},
{"14a", CmdHF14A, 1, "{ ISO14443A RFIDs... }"},
{"14b", CmdHF14B, 1, "{ ISO14443B RFIDs... }"},
{"15", CmdHF15, 1, "{ ISO15693 RFIDs... }"},
{"epa", CmdHFEPA, 1, "{ German Identification Card... }"},
{"legic", CmdHFLegic, 0, "{ LEGIC RFIDs... }"},
{"iclass", CmdHFiClass, 1, "{ ICLASS RFIDs... }"},
{"mf", CmdHFMF, 1, "{ MIFARE RFIDs... }"},
{"tune", CmdHFTune, 0, "Continuously measure HF antenna tuning"},
{NULL, NULL, 0, NULL}
char * pEnd;
UsbCommand c = {CMD_HF_SNIFFER, {strtol(Cmd, &pEnd,0),strtol(pEnd, &pEnd,0),0}};
SendCommand(&c);
return 0;
}
// static void InterpolateShannon(int *source, size_t source_len, int *dest, size_t dest_len)
// {
// int *buf = (int*)malloc(source_len * sizeof(int));
// memcpy(buf, source, source_len * sizeof(int));
// for (int i = 0; i < source_len; i++) {
// buf[i] += 128;
// }
// for (int i = 0; i < dest_len; i++) {
// float value = 0.0;
// for (int j = 0; j < source_len; j++) {
// if (i * source_len == j * dest_len) { // sin(0) / 0 = 1
// value += (float)buf[j];
// } else {
// value += (float)buf[j] * sin(((float)i*source_len/dest_len-j)*3.1415) / (((float)i*source_len/dest_len-j)*3.1415);
// }
// }
// dest[i] = value - 128;
// }
// free(buf);
// }
static int CmdHFPlot(const char *Cmd)
{
CLIParserInit("hf plot",
"Plots HF signal after RF signal path and A/D conversion.",
"This can be used after any hf command and will show the last few milliseconds of the HF signal.\n"
"Note: If the last hf command terminated because of a timeout you will most probably see nothing.\n");
void* argtable[] = {
arg_param_begin,
arg_param_end
};
CLIExecWithReturn(Cmd, argtable, true);
uint8_t buf[FPGA_TRACE_SIZE];
if (GetFromFpgaRAM(buf, FPGA_TRACE_SIZE)) {
for (size_t i = 0; i < FPGA_TRACE_SIZE; i++) {
GraphBuffer[i] = (int)buf[i] - 128;
}
GraphTraceLen = FPGA_TRACE_SIZE;
// InterpolateShannon(GraphBuffer, FPGA_TRACE_SIZE, GraphBuffer, FPGA_TRACE_SIZE*8/7);
// GraphTraceLen = FPGA_TRACE_SIZE*8/7;
ShowGraphWindow();
RepaintGraphWindow();
}
return 0;
}
static command_t CommandTable[] =
{
{"help", CmdHelp, 1, "This help"},
{"14a", CmdHF14A, 0, "{ ISO14443A RFIDs... }"},
{"14b", CmdHF14B, 0, "{ ISO14443B RFIDs... }"},
{"15", CmdHF15, 1, "{ ISO15693 RFIDs... }"},
{"epa", CmdHFEPA, 0, "{ German Identification Card... }"},
{"legic", CmdHFLegic, 0, "{ LEGIC RFIDs... }"},
{"iclass", CmdHFiClass, 1, "{ ICLASS RFIDs... }"},
{"mf", CmdHFMF, 1, "{ MIFARE RFIDs... }"},
{"mfu", CmdHFMFUltra, 1, "{ MIFARE Ultralight RFIDs... }"},
{"mfp", CmdHFMFP, 0, "{ MIFARE Plus RFIDs... }"},
{"topaz", CmdHFTopaz, 0, "{ TOPAZ (NFC Type 1) RFIDs... }"},
{"fido", CmdHFFido, 0, "{ FIDO and FIDO2 authenticators... }"},
{"tune", CmdHFTune, 0, "Continuously measure HF antenna tuning"},
{"list", CmdHFList, 1, "List protocol data in trace buffer"},
{"plot", CmdHFPlot, 0, "Plot signal"},
{"search", CmdHFSearch, 0, "Search for known HF tags [preliminary]"},
{"snoop", CmdHFSnoop, 0, "<samples to skip (10000)> <triggers to skip (1)> Generic HF Snoop"},
{NULL, NULL, 0, NULL}
};
int CmdHF(const char *Cmd)
{
CmdsParse(CommandTable, Cmd);
return 0;
return 0;
}
int CmdHelp(const char *Cmd)

File diff suppressed because it is too large Load diff

View file

@ -12,12 +12,23 @@
#ifndef CMDHF14A_H__
#define CMDHF14A_H__
int CmdHF14A(const char *Cmd);
#include <stdint.h>
#include <stdbool.h>
#include "mifare.h"
int CmdHF14AList(const char *Cmd);
int CmdHF14AMifare(const char *Cmd);
int CmdHF14AReader(const char *Cmd);
int CmdHF14ASim(const char *Cmd);
int CmdHF14ASnoop(const char *Cmd);
extern int CmdHF14A(const char *Cmd);
extern int CmdHF14AMfDbg(const char* cmd);
extern int CmdHF14AList(const char *Cmd);
extern int CmdHF14AMifare(const char *Cmd);
extern int CmdHF14AReader(const char *Cmd);
extern int CmdHF14AInfo(const char *Cmd);
extern int CmdHF14ASim(const char *Cmd);
extern int CmdHF14ASnoop(const char *Cmd);
extern void DropField();
extern int Hf14443_4aGetCardData(iso14a_card_select_t * card);
extern int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
extern int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
#endif

File diff suppressed because it is too large Load diff

View file

@ -11,15 +11,16 @@
#ifndef CMDHF14B_H__
#define CMDHF14B_H__
int CmdHF14B(const char *Cmd);
#include <stdbool.h>
int CmdHF14BDemod(const char *Cmd);
int CmdHF14B(const char *Cmd);
int CmdHF14BList(const char *Cmd);
int CmdHF14BRead(const char *Cmd);
int CmdHF14Sim(const char *Cmd);
int CmdHFSimlisten(const char *Cmd);
int CmdHF14BInfo(const char *Cmd);
int CmdHF14BSim(const char *Cmd);
int CmdHF14BSnoop(const char *Cmd);
int CmdSri512Read(const char *Cmd);
int CmdSrix4kRead(const char *Cmd);
int CmdHF14BWrite( const char *cmd);
int infoHF14B(bool verbose);
#endif

File diff suppressed because it is too large Load diff

View file

@ -11,15 +11,9 @@
#ifndef CMDHF15_H__
#define CMDHF15_H__
int CmdHF15(const char *Cmd);
#include <stdbool.h>
int CmdHF15Demod(const char *Cmd);
int CmdHF15Read(const char *Cmd);
int CmdHF15Reader(const char *Cmd);
int CmdHF15Sim(const char *Cmd);
int CmdHF15Record(const char *Cmd);
int CmdHF15Cmd(const char*Cmd);
int CmdHF15CmdHelp(const char*Cmd);
int CmdHF15Help(const char*Cmd);
extern int CmdHF15(const char *Cmd);
extern int HF15Reader(const char *Cmd, bool verbose);
#endif

View file

@ -8,15 +8,20 @@
// Commands related to the German electronic Identification Card
//-----------------------------------------------------------------------------
#include "cmdhfepa.h"
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include "util.h"
//#include "proxusb.h"
#include "proxmark3.h"
#include "util_posix.h"
#include "comms.h"
#include "ui.h"
#include "cmdparser.h"
#include "common.h"
#include "cmdmain.h"
#include "sleep.h"
#include "cmdhfepa.h"
static int CmdHelp(const char *Cmd);
@ -29,23 +34,23 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
unsigned int n = 0;
// delay between requests
unsigned int d = 0;
sscanf(Cmd, "%u %u %u", &m, &n, &d);
// values are expected to be > 0
m = m > 0 ? m : 1;
n = n > 0 ? n : 1;
PrintAndLog("Collecting %u %"hhu"-byte nonces", n, m);
PrintAndLog("Start: %u", time(NULL));
PrintAndLog("Collecting %u %u-byte nonces", n, m);
PrintAndLog("Start: %" PRIu64 , msclock()/1000);
// repeat n times
for (unsigned int i = 0; i < n; i++) {
// execute PACE
UsbCommand c = {CMD_EPA_PACE_COLLECT_NONCE, {(int)m, 0, 0}};
SendCommand(&c);
UsbCommand resp;
WaitForResponse(CMD_ACK,&resp);
WaitForResponse(CMD_ACK,&resp);
// check if command failed
if (resp.arg[0] != 0) {
@ -54,27 +59,138 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
size_t nonce_length = resp.arg[1];
char *nonce = (char *) malloc(2 * nonce_length + 1);
for(int j = 0; j < nonce_length; j++) {
snprintf(nonce + (2 * j), 3, "%02X", resp.d.asBytes[j]);
sprintf(nonce + (2 * j), "%02X", resp.d.asBytes[j]);
}
// print nonce
PrintAndLog("Length: %d, Nonce: %s",resp.arg[1], nonce);
PrintAndLog("Length: %d, Nonce: %s", nonce_length, nonce);
free(nonce);
}
if (i < n - 1) {
sleep(d);
}
}
PrintAndLog("End: %u", time(NULL));
PrintAndLog("End: %" PRIu64, msclock()/1000);
return 1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////The commands lie below here/////////////////////////////////////////////////////////////////////////////////////////
// perform the PACE protocol by replaying APDUs
int CmdHFEPAPACEReplay(const char *Cmd)
{
// the 4 APDUs which are replayed + their lengths
uint8_t msesa_apdu[41], gn_apdu[8], map_apdu[75];
uint8_t pka_apdu[75], ma_apdu[18], apdu_lengths[5] = {0};
// pointers to the arrays to be able to iterate
uint8_t *apdus[] = {msesa_apdu, gn_apdu, map_apdu, pka_apdu, ma_apdu};
// usage message
static const char *usage_msg =
"Please specify 5 APDUs separated by spaces. "
"Example:\n preplay 0022C1A4 1068000000 1086000002 1234ABCDEF 1A2B3C4D";
// Proxmark response
UsbCommand resp;
int skip = 0, skip_add = 0, scan_return = 0;
// for each APDU
for (int i = 0; i < sizeof(apdu_lengths); i++) {
// scan to next space or end of string
while (Cmd[skip] != ' ' && Cmd[skip] != '\0') {
// convert
scan_return = sscanf(Cmd + skip, "%2X%n",
(unsigned int *) (apdus[i] + apdu_lengths[i]),
&skip_add);
if (scan_return < 1) {
PrintAndLog((char *)usage_msg);
PrintAndLog("Not enough APDUs! Try again!");
return 0;
}
skip += skip_add;
apdu_lengths[i]++;
}
// break on EOF
if (Cmd[skip] == '\0') {
if (i < sizeof(apdu_lengths) - 1) {
PrintAndLog((char *)usage_msg);
return 0;
}
break;
}
// skip the space
skip++;
}
// transfer the APDUs to the Proxmark
UsbCommand usb_cmd;
usb_cmd.cmd = CMD_EPA_PACE_REPLAY;
for (int i = 0; i < sizeof(apdu_lengths); i++) {
// APDU number
usb_cmd.arg[0] = i + 1;
// transfer the APDU in several parts if necessary
for (int j = 0; j * sizeof(usb_cmd.d.asBytes) < apdu_lengths[i]; j++) {
// offset into the APDU
usb_cmd.arg[1] = j * sizeof(usb_cmd.d.asBytes);
// amount of data in this packet
int packet_length = apdu_lengths[i] - (j * sizeof(usb_cmd.d.asBytes));
if (packet_length > sizeof(usb_cmd.d.asBytes)) {
packet_length = sizeof(usb_cmd.d.asBytes);
}
usb_cmd.arg[2] = packet_length;
memcpy(usb_cmd.d.asBytes, // + (j * sizeof(usb_cmd.d.asBytes)),
apdus[i] + (j * sizeof(usb_cmd.d.asBytes)),
packet_length);
SendCommand(&usb_cmd);
WaitForResponse(CMD_ACK, &resp);
if (resp.arg[0] != 0) {
PrintAndLog("Transfer of APDU #%d Part %d failed!", i, j);
return 0;
}
}
}
// now perform the replay
usb_cmd.arg[0] = 0;
SendCommand(&usb_cmd);
WaitForResponse(CMD_ACK, &resp);
if (resp.arg[0] != 0) {
PrintAndLog("\nPACE replay failed in step %u!", (uint32_t)resp.arg[0]);
PrintAndLog("Measured times:");
PrintAndLog("MSE Set AT: %u us", resp.d.asDwords[0]);
PrintAndLog("GA Get Nonce: %u us", resp.d.asDwords[1]);
PrintAndLog("GA Map Nonce: %u us", resp.d.asDwords[2]);
PrintAndLog("GA Perform Key Agreement: %u us", resp.d.asDwords[3]);
PrintAndLog("GA Mutual Authenticate: %u us", resp.d.asDwords[4]);
} else {
PrintAndLog("PACE replay successfull!");
PrintAndLog("MSE Set AT: %u us", resp.d.asDwords[0]);
PrintAndLog("GA Get Nonce: %u us", resp.d.asDwords[1]);
PrintAndLog("GA Map Nonce: %u us", resp.d.asDwords[2]);
PrintAndLog("GA Perform Key Agreement: %u us", resp.d.asDwords[3]);
PrintAndLog("GA Mutual Authenticate: %u us", resp.d.asDwords[4]);
}
return 1;
}
////////////////////////////////The new commands lie above here/////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// UI-related stuff
static const command_t CommandTable[] =
static const command_t CommandTable[] =
{
{"help", CmdHelp, 1, "This help"},
{"cnonces", CmdHFEPACollectPACENonces, 0,
"<m> <n> <d> Acquire n>0 encrypted PACE nonces of size m>0 with d sec pauses"},
{"preplay", CmdHFEPAPACEReplay, 0,
"<mse> <get> <map> <pka> <ma> Perform PACE protocol by replaying given APDUs"},
{NULL, NULL, 0, NULL}
};
@ -86,10 +202,7 @@ int CmdHelp(const char *Cmd)
int CmdHFEPA(const char *Cmd)
{
// flush
WaitForResponseTimeout(CMD_ACK,NULL,100);
// parse
CmdsParse(CommandTable, Cmd);
return 0;
}
(void)WaitForResponseTimeout(CMD_ACK,NULL,100);
CmdsParse(CommandTable, Cmd);
return 0;
}

926
client/cmdhffido.c Normal file
View file

@ -0,0 +1,926 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2018 Merlok
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// High frequency MIFARE Plus commands
//-----------------------------------------------------------------------------
//
// Documentation here:
//
// FIDO Alliance specifications
// https://fidoalliance.org/download/
// FIDO NFC Protocol Specification v1.0
// https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-nfc-protocol-v1.2-ps-20170411.html
// FIDO U2F Raw Message Formats
// https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-raw-message-formats-v1.2-ps-20170411.html
//-----------------------------------------------------------------------------
#include "cmdhffido.h"
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <jansson.h>
#include <mbedtls/x509_crt.h>
#include <mbedtls/x509.h>
#include <mbedtls/pk.h>
#include "comms.h"
#include "cmdmain.h"
#include "util.h"
#include "ui.h"
#include "proxmark3.h"
#include "mifare.h"
#include "emv/emvcore.h"
#include "emv/emvjson.h"
#include "emv/dump.h"
#include "emv/apduinfo.h"
#include "cliparser/cliparser.h"
#include "crypto/asn1utils.h"
#include "crypto/libpcrypto.h"
#include "fido/cbortools.h"
#include "fido/fidocore.h"
#include "fido/cose.h"
static int CmdHelp(const char *Cmd);
int CmdHFFidoInfo(const char *cmd) {
if (cmd && strlen(cmd) > 0)
PrintAndLog("WARNING: command don't have any parameters.\n");
// info about 14a part
CmdHF14AInfo("");
// FIDO info
PrintAndLog("--------------------------------------------");
SetAPDULogging(false);
uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = FIDOSelect(true, true, buf, sizeof(buf), &len, &sw);
if (res) {
DropField();
return res;
}
if (sw != 0x9000) {
if (sw)
PrintAndLog("Not a FIDO card! APDU response: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
else
PrintAndLog("APDU exchange error. Card returns 0x0000.");
DropField();
return 0;
}
if (!strncmp((char *)buf, "U2F_V2", 7)) {
if (!strncmp((char *)buf, "FIDO_2_0", 8)) {
PrintAndLog("FIDO2 authenricator detected. Version: %.*s", len, buf);
} else {
PrintAndLog("FIDO authenricator detected (not standard U2F).");
PrintAndLog("Non U2F authenticator version:");
dump_buffer((const unsigned char *)buf, len, NULL, 0);
}
} else {
PrintAndLog("FIDO U2F authenricator detected. Version: %.*s", len, buf);
}
res = FIDO2GetInfo(buf, sizeof(buf), &len, &sw);
DropField();
if (res) {
return res;
}
if (sw != 0x9000) {
PrintAndLog("FIDO2 version not exists (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return 0;
}
if(buf[0]) {
PrintAndLog("FIDO2 ger version error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0]));
return 0;
}
if (len > 1) {
// if (false) {
// PrintAndLog("FIDO2 version: (len=%d)", len);
// dump_buffer((const unsigned char *)buf, len, NULL, 0);
// }
PrintAndLog("FIDO2 version CBOR decoded:");
TinyCborPrintFIDOPackage(fido2CmdGetInfo, true, &buf[1], len - 1);
} else {
PrintAndLog("FIDO2 version length error");
}
return 0;
}
json_t *OpenJson(int paramnum, char *fname, void* argtable[], bool *err) {
json_t *root = NULL;
json_error_t error;
*err = false;
uint8_t jsonname[250] ={0};
char *cjsonname = (char *)jsonname;
int jsonnamelen = 0;
// CLIGetStrWithReturn(paramnum, jsonname, &jsonnamelen);
if (CLIParamStrToBuf(arg_get_str(paramnum), jsonname, sizeof(jsonname), &jsonnamelen)) {
CLIParserFree();
return NULL;
}
// current path + file name
if (!strstr(cjsonname, ".json"))
strcat(cjsonname, ".json");
if (jsonnamelen) {
strcpy(fname, get_my_executable_directory());
strcat(fname, cjsonname);
if (access(fname, F_OK) != -1) {
root = json_load_file(fname, 0, &error);
if (!root) {
PrintAndLog("ERROR: json error on line %d: %s", error.line, error.text);
*err = true;
return NULL;
}
if (!json_is_object(root)) {
PrintAndLog("ERROR: Invalid json format. root must be an object.");
json_decref(root);
*err = true;
return NULL;
}
} else {
root = json_object();
}
}
return root;
}
int CmdHFFidoRegister(const char *cmd) {
uint8_t data[64] = {0};
int chlen = 0;
uint8_t cdata[250] = {0};
int applen = 0;
uint8_t adata[250] = {0};
json_t *root = NULL;
CLIParserInit("hf fido reg",
"Initiate a U2F token registration. Needs two 32-byte hash number. \nchallenge parameter (32b) and application parameter (32b).",
"Usage:\n\thf fido reg -> execute command with 2 parameters, filled 0x00\n"
"\thf fido reg 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with parameters"
"\thf fido reg -p s0 s1 -> execute command with plain parameters");
void* argtable[] = {
arg_param_begin,
arg_lit0("aA", "apdu", "show APDU reqests and responses"),
arg_litn("vV", "verbose", 0, 2, "show technical data. vv - show full certificates data"),
arg_lit0("pP", "plain", "send plain ASCII to challenge and application parameters instead of HEX"),
arg_lit0("tT", "tlv", "Show DER certificate contents in TLV representation"),
arg_str0("jJ", "json", "fido.json", "JSON input / output file name for parameters."),
arg_str0(NULL, NULL, "<HEX/ASCII challenge parameter (32b HEX/1..16 chars)>", NULL),
arg_str0(NULL, NULL, "<HEX/ASCII application parameter (32b HEX/1..16 chars)>", NULL),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool APDULogging = arg_get_lit(1);
bool verbose = arg_get_lit(2);
bool verbose2 = arg_get_lit(2) > 1;
bool paramsPlain = arg_get_lit(3);
bool showDERTLV = arg_get_lit(4);
char fname[250] = {0};
bool err;
root = OpenJson(5, fname, argtable, &err);
if(err)
return 1;
if (root) {
size_t jlen;
JsonLoadBufAsHex(root, "$.ChallengeParam", data, 32, &jlen);
JsonLoadBufAsHex(root, "$.ApplicationParam", &data[32], 32, &jlen);
}
if (paramsPlain) {
memset(cdata, 0x00, 32);
CLIGetStrWithReturn(6, cdata, &chlen);
if (chlen && chlen > 16) {
PrintAndLog("ERROR: challenge parameter length in ASCII mode must be less than 16 chars instead of: %d", chlen);
return 1;
}
} else {
CLIGetHexWithReturn(6, cdata, &chlen);
if (chlen && chlen != 32) {
PrintAndLog("ERROR: challenge parameter length must be 32 bytes only.");
return 1;
}
}
if (chlen)
memmove(data, cdata, 32);
if (paramsPlain) {
memset(adata, 0x00, 32);
CLIGetStrWithReturn(7, adata, &applen);
if (applen && applen > 16) {
PrintAndLog("ERROR: application parameter length in ASCII mode must be less than 16 chars instead of: %d", applen);
return 1;
}
} else {
CLIGetHexWithReturn(7, adata, &applen);
if (applen && applen != 32) {
PrintAndLog("ERROR: application parameter length must be 32 bytes only.");
return 1;
}
}
if (applen)
memmove(&data[32], adata, 32);
CLIParserFree();
SetAPDULogging(APDULogging);
// challenge parameter [32 bytes] - The challenge parameter is the SHA-256 hash of the Client Data, a stringified JSON data structure that the FIDO Client prepares
// application parameter [32 bytes] - The application parameter is the SHA-256 hash of the UTF-8 encoding of the application identity
uint8_t buf[2048] = {0};
size_t len = 0;
uint16_t sw = 0;
DropField();
int res = FIDOSelect(true, true, buf, sizeof(buf), &len, &sw);
if (res) {
PrintAndLog("Can't select authenticator. res=%x. Exit...", res);
DropField();
return res;
}
if (sw != 0x9000) {
PrintAndLog("Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
DropField();
return 2;
}
res = FIDORegister(data, buf, sizeof(buf), &len, &sw);
DropField();
if (res) {
PrintAndLog("Can't execute register command. res=%x. Exit...", res);
return res;
}
if (sw != 0x9000) {
PrintAndLog("ERROR execute register command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return 3;
}
PrintAndLog("");
if (APDULogging)
PrintAndLog("---------------------------------------------------------------");
PrintAndLog("data len: %d", len);
if (verbose2) {
PrintAndLog("--------------data----------------------");
dump_buffer((const unsigned char *)buf, len, NULL, 0);
PrintAndLog("--------------data----------------------");
}
if (buf[0] != 0x05) {
PrintAndLog("ERROR: First byte must be 0x05, but it %2x", buf[0]);
return 5;
}
PrintAndLog("User public key: %s", sprint_hex(&buf[1], 65));
uint8_t keyHandleLen = buf[66];
PrintAndLog("Key handle[%d]: %s", keyHandleLen, sprint_hex(&buf[67], keyHandleLen));
int derp = 67 + keyHandleLen;
int derLen = (buf[derp + 2] << 8) + buf[derp + 3] + 4;
if (verbose2) {
PrintAndLog("DER certificate[%d]:\n------------------DER-------------------", derLen);
dump_buffer_simple((const unsigned char *)&buf[derp], derLen, NULL);
PrintAndLog("\n----------------DER---------------------");
} else {
if (verbose)
PrintAndLog("------------------DER-------------------");
PrintAndLog("DER certificate[%d]: %s...", derLen, sprint_hex(&buf[derp], 20));
}
// check and print DER certificate
uint8_t public_key[65] = {0};
// print DER certificate in TLV view
if (showDERTLV) {
PrintAndLog("----------------DER TLV-----------------");
asn1_print(&buf[derp], derLen, " ");
PrintAndLog("----------------DER TLV-----------------");
}
FIDOCheckDERAndGetKey(&buf[derp], derLen, verbose, public_key, sizeof(public_key));
// get hash
int hashp = 1 + 65 + 1 + keyHandleLen + derLen;
PrintAndLog("Hash[%d]: %s", len - hashp, sprint_hex(&buf[hashp], len - hashp));
// check ANSI X9.62 format ECDSA signature (on P-256)
uint8_t rval[300] = {0};
uint8_t sval[300] = {0};
res = ecdsa_asn1_get_signature(&buf[hashp], len - hashp, rval, sval);
if (!res) {
if (verbose) {
PrintAndLog(" r: %s", sprint_hex(rval, 32));
PrintAndLog(" s: %s", sprint_hex(sval, 32));
}
uint8_t xbuf[4096] = {0};
size_t xbuflen = 0;
res = FillBuffer(xbuf, sizeof(xbuf), &xbuflen,
"\x00", 1,
&data[32], 32, // application parameter
&data[0], 32, // challenge parameter
&buf[67], keyHandleLen, // keyHandle
&buf[1], 65, // user public key
NULL, 0);
//PrintAndLog("--xbuf(%d)[%d]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
res = ecdsa_signature_verify(MBEDTLS_ECP_DP_SECP256R1, public_key, xbuf, xbuflen, &buf[hashp], len - hashp, true);
if (res) {
if (res == MBEDTLS_ERR_ECP_VERIFY_FAILED) {
PrintAndLog("Signature is NOT VALID.");
} else {
PrintAndLog("Other signature check error: %x %s", (res<0)?-res:res, ecdsa_get_error(res));
}
} else {
PrintAndLog("Signature is OK.");
}
} else {
PrintAndLog("Invalid signature. res=%d.", res);
}
PrintAndLog("\nauth command: ");
printf("hf fido auth %s%s", paramsPlain?"-p ":"", sprint_hex_inrow(&buf[67], keyHandleLen));
if(chlen || applen)
printf(" %s", paramsPlain?(char *)cdata:sprint_hex_inrow(cdata, 32));
if(applen)
printf(" %s", paramsPlain?(char *)adata:sprint_hex_inrow(adata, 32));
printf("\n");
if (root) {
JsonSaveBufAsHex(root, "ChallengeParam", data, 32);
JsonSaveBufAsHex(root, "ApplicationParam", &data[32], 32);
JsonSaveBufAsHexCompact(root, "PublicKey", &buf[1], 65);
JsonSaveInt(root, "KeyHandleLen", keyHandleLen);
JsonSaveBufAsHexCompact(root, "KeyHandle", &buf[67], keyHandleLen);
JsonSaveBufAsHexCompact(root, "DER", &buf[67 + keyHandleLen], derLen);
res = json_dump_file(root, fname, JSON_INDENT(2));
if (res) {
PrintAndLog("ERROR: can't save the file: %s", fname);
return 200;
}
PrintAndLog("File `%s` saved.", fname);
// free json object
json_decref(root);
}
return 0;
};
int CmdHFFidoAuthenticate(const char *cmd) {
uint8_t data[512] = {0};
uint8_t hdata[250] = {0};
bool public_key_loaded = false;
uint8_t public_key[65] = {0};
int hdatalen = 0;
uint8_t keyHandleLen = 0;
json_t *root = NULL;
CLIParserInit("hf fido auth",
"Initiate a U2F token authentication. Needs key handle and two 32-byte hash number. \nkey handle(var 0..255), challenge parameter (32b) and application parameter (32b).",
"Usage:\n\thf fido auth 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with 2 parameters, filled 0x00 and key handle\n"
"\thf fido auth 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f "
"000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with parameters");
void* argtable[] = {
arg_param_begin,
arg_lit0("aA", "apdu", "show APDU reqests and responses"),
arg_lit0("vV", "verbose", "show technical data"),
arg_lit0("pP", "plain", "send plain ASCII to challenge and application parameters instead of HEX"),
arg_rem("default mode:", "dont-enforce-user-presence-and-sign"),
arg_lit0("uU", "user", "mode: enforce-user-presence-and-sign"),
arg_lit0("cC", "check", "mode: check-only"),
arg_str0("jJ", "json", "fido.json", "JSON input / output file name for parameters."),
arg_str0("kK", "key", "public key to verify signature", NULL),
arg_str0(NULL, NULL, "<HEX key handle (var 0..255b)>", NULL),
arg_str0(NULL, NULL, "<HEX/ASCII challenge parameter (32b HEX/1..16 chars)>", NULL),
arg_str0(NULL, NULL, "<HEX/ASCII application parameter (32b HEX/1..16 chars)>", NULL),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool APDULogging = arg_get_lit(1);
bool verbose = arg_get_lit(2);
bool paramsPlain = arg_get_lit(3);
uint8_t controlByte = 0x08;
if (arg_get_lit(5))
controlByte = 0x03;
if (arg_get_lit(6))
controlByte = 0x07;
char fname[250] = {0};
bool err;
root = OpenJson(7, fname, argtable, &err);
if(err)
return 1;
if (root) {
size_t jlen;
JsonLoadBufAsHex(root, "$.ChallengeParam", data, 32, &jlen);
JsonLoadBufAsHex(root, "$.ApplicationParam", &data[32], 32, &jlen);
JsonLoadBufAsHex(root, "$.KeyHandle", &data[65], 512 - 67, &jlen);
keyHandleLen = jlen & 0xff;
data[64] = keyHandleLen;
JsonLoadBufAsHex(root, "$.PublicKey", public_key, 65, &jlen);
public_key_loaded = (jlen > 0);
}
// public key
CLIGetHexWithReturn(8, hdata, &hdatalen);
if (hdatalen && hdatalen != 65) {
PrintAndLog("ERROR: public key length must be 65 bytes only.");
return 1;
}
if (hdatalen) {
memmove(public_key, hdata, hdatalen);
public_key_loaded = true;
}
CLIGetHexWithReturn(9, hdata, &hdatalen);
if (hdatalen > 255) {
PrintAndLog("ERROR: application parameter length must be less than 255.");
return 1;
}
if (hdatalen) {
keyHandleLen = hdatalen;
data[64] = keyHandleLen;
memmove(&data[65], hdata, keyHandleLen);
}
if (paramsPlain) {
memset(hdata, 0x00, 32);
CLIGetStrWithReturn(9, hdata, &hdatalen);
if (hdatalen && hdatalen > 16) {
PrintAndLog("ERROR: challenge parameter length in ASCII mode must be less than 16 chars instead of: %d", hdatalen);
return 1;
}
} else {
CLIGetHexWithReturn(10, hdata, &hdatalen);
if (hdatalen && hdatalen != 32) {
PrintAndLog("ERROR: challenge parameter length must be 32 bytes only.");
return 1;
}
}
if (hdatalen)
memmove(data, hdata, 32);
if (paramsPlain) {
memset(hdata, 0x00, 32);
CLIGetStrWithReturn(11, hdata, &hdatalen);
if (hdatalen && hdatalen > 16) {
PrintAndLog("ERROR: application parameter length in ASCII mode must be less than 16 chars instead of: %d", hdatalen);
return 1;
}
} else {
CLIGetHexWithReturn(10, hdata, &hdatalen);
if (hdatalen && hdatalen != 32) {
PrintAndLog("ERROR: application parameter length must be 32 bytes only.");
return 1;
}
}
if (hdatalen)
memmove(&data[32], hdata, 32);
CLIParserFree();
SetAPDULogging(APDULogging);
// (in parameter) conrtol byte 0x07 - check only, 0x03 - user presense + cign. 0x08 - sign only
// challenge parameter [32 bytes]
// application parameter [32 bytes]
// key handle length [1b] = N
// key handle [N]
uint8_t datalen = 32 + 32 + 1 + keyHandleLen;
uint8_t buf[2048] = {0};
size_t len = 0;
uint16_t sw = 0;
DropField();
int res = FIDOSelect(true, true, buf, sizeof(buf), &len, &sw);
if (res) {
PrintAndLog("Can't select authenticator. res=%x. Exit...", res);
DropField();
return res;
}
if (sw != 0x9000) {
PrintAndLog("Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
DropField();
return 2;
}
res = FIDOAuthentication(data, datalen, controlByte, buf, sizeof(buf), &len, &sw);
DropField();
if (res) {
PrintAndLog("Can't execute authentication command. res=%x. Exit...", res);
return res;
}
if (sw != 0x9000) {
PrintAndLog("ERROR execute authentication command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return 3;
}
PrintAndLog("---------------------------------------------------------------");
PrintAndLog("User presence: %s", (buf[0]?"verified":"not verified"));
uint32_t cntr = (uint32_t)bytes_to_num(&buf[1], 4);
PrintAndLog("Counter: %d", cntr);
PrintAndLog("Hash[%d]: %s", len - 5, sprint_hex(&buf[5], len - 5));
// check ANSI X9.62 format ECDSA signature (on P-256)
uint8_t rval[300] = {0};
uint8_t sval[300] = {0};
res = ecdsa_asn1_get_signature(&buf[5], len - 5, rval, sval);
if (!res) {
if (verbose) {
PrintAndLog(" r: %s", sprint_hex(rval, 32));
PrintAndLog(" s: %s", sprint_hex(sval, 32));
}
if (public_key_loaded) {
uint8_t xbuf[4096] = {0};
size_t xbuflen = 0;
res = FillBuffer(xbuf, sizeof(xbuf), &xbuflen,
&data[32], 32, // application parameter
&buf[0], 1, // user presence
&buf[1], 4, // counter
data, 32, // challenge parameter
NULL, 0);
//PrintAndLog("--xbuf(%d)[%d]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
res = ecdsa_signature_verify(MBEDTLS_ECP_DP_SECP256R1, public_key, xbuf, xbuflen, &buf[5], len - 5, true);
if (res) {
if (res == MBEDTLS_ERR_ECP_VERIFY_FAILED) {
PrintAndLog("Signature is NOT VALID.");
} else {
PrintAndLog("Other signature check error: %x %s", (res<0)?-res:res, ecdsa_get_error(res));
}
} else {
PrintAndLog("Signature is OK.");
}
} else {
PrintAndLog("No public key provided. can't check signature.");
}
} else {
PrintAndLog("Invalid signature. res=%d.", res);
}
if (root) {
JsonSaveBufAsHex(root, "ChallengeParam", data, 32);
JsonSaveBufAsHex(root, "ApplicationParam", &data[32], 32);
JsonSaveInt(root, "KeyHandleLen", keyHandleLen);
JsonSaveBufAsHexCompact(root, "KeyHandle", &data[65], keyHandleLen);
JsonSaveInt(root, "Counter", cntr);
res = json_dump_file(root, fname, JSON_INDENT(2));
if (res) {
PrintAndLog("ERROR: can't save the file: %s", fname);
return 200;
}
PrintAndLog("File `%s` saved.", fname);
// free json object
json_decref(root);
}
return 0;
};
void CheckSlash(char *fileName) {
if ((fileName[strlen(fileName) - 1] != '/') &&
(fileName[strlen(fileName) - 1] != '\\'))
strcat(fileName, "/");
}
int GetExistsFileNameJson(char *prefixDir, char *reqestedFileName, char *fileName) {
fileName[0] = 0x00;
strcpy(fileName, get_my_executable_directory());
CheckSlash(fileName);
strcat(fileName, prefixDir);
CheckSlash(fileName);
strcat(fileName, reqestedFileName);
if (!strstr(fileName, ".json"))
strcat(fileName, ".json");
if (access(fileName, F_OK) < 0) {
strcpy(fileName, get_my_executable_directory());
CheckSlash(fileName);
strcat(fileName, reqestedFileName);
if (!strstr(fileName, ".json"))
strcat(fileName, ".json");
if (access(fileName, F_OK) < 0) {
return 1; // file not found
}
}
return 0;
}
int CmdHFFido2MakeCredential(const char *cmd) {
json_error_t error;
json_t *root = NULL;
char fname[300] = {0};
CLIParserInit("hf fido make",
"Execute a FIDO2 Make Credentional command. Needs json file with parameters. Sample file `fido2.json`. File can be placed in proxmark directory or in `proxmark/fido` directory.",
"Usage:\n\thf fido make -> execute command default parameters file `fido2.json`\n"
"\thf fido make test.json -> execute command with parameters file `text.json`");
void* argtable[] = {
arg_param_begin,
arg_lit0("aA", "apdu", "show APDU reqests and responses"),
arg_litn("vV", "verbose", 0, 2, "show technical data. vv - show full certificates data"),
arg_lit0("tT", "tlv", "Show DER certificate contents in TLV representation"),
arg_lit0("cC", "cbor", "show CBOR decoded data"),
arg_str0(NULL, NULL, "<json file name>", "JSON input / output file name for parameters. Default `fido2.json`"),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool APDULogging = arg_get_lit(1);
bool verbose = arg_get_lit(2);
bool verbose2 = arg_get_lit(2) > 1;
bool showDERTLV = arg_get_lit(3);
bool showCBOR = arg_get_lit(4);
uint8_t jsonname[250] ={0};
char *cjsonname = (char *)jsonname;
int jsonnamelen = 0;
CLIGetStrWithReturn(5, jsonname, &jsonnamelen);
if (!jsonnamelen) {
strcat(cjsonname, "fido2");
jsonnamelen = strlen(cjsonname);
}
CLIParserFree();
SetAPDULogging(APDULogging);
int res = GetExistsFileNameJson("fido", cjsonname, fname);
if(res) {
PrintAndLog("ERROR: Can't found the json file.");
return res;
}
PrintAndLog("fname: %s\n", fname);
root = json_load_file(fname, 0, &error);
if (!root) {
PrintAndLog("ERROR: json error on line %d: %s", error.line, error.text);
return 1;
}
uint8_t data[2048] = {0};
size_t datalen = 0;
uint8_t buf[2048] = {0};
size_t len = 0;
uint16_t sw = 0;
DropField();
res = FIDOSelect(true, true, buf, sizeof(buf), &len, &sw);
if (res) {
PrintAndLog("Can't select authenticator. res=%x. Exit...", res);
DropField();
return res;
}
if (sw != 0x9000) {
PrintAndLog("Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
DropField();
return 2;
}
res = FIDO2CreateMakeCredentionalReq(root, data, sizeof(data), &datalen);
if (res)
return res;
if (showCBOR) {
PrintAndLog("CBOR make credentional request:");
PrintAndLog("---------------- CBOR ------------------");
TinyCborPrintFIDOPackage(fido2CmdMakeCredential, false, data, datalen);
PrintAndLog("---------------- CBOR ------------------");
}
res = FIDO2MakeCredential(data, datalen, buf, sizeof(buf), &len, &sw);
DropField();
if (res) {
PrintAndLog("Can't execute make credential command. res=%x. Exit...", res);
return res;
}
if (sw != 0x9000) {
PrintAndLog("ERROR execute make credential command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return 3;
}
if(buf[0]) {
PrintAndLog("FIDO2 make credential error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0]));
return 0;
}
PrintAndLog("MakeCredential result (%d b) OK.", len);
if (showCBOR) {
PrintAndLog("CBOR make credentional response:");
PrintAndLog("---------------- CBOR ------------------");
TinyCborPrintFIDOPackage(fido2CmdMakeCredential, true, &buf[1], len - 1);
PrintAndLog("---------------- CBOR ------------------");
}
// parse returned cbor
FIDO2MakeCredentionalParseRes(root, &buf[1], len - 1, verbose, verbose2, showCBOR, showDERTLV);
if (root) {
res = json_dump_file(root, fname, JSON_INDENT(2));
if (res) {
PrintAndLog("ERROR: can't save the file: %s", fname);
return 200;
}
PrintAndLog("File `%s` saved.", fname);
}
json_decref(root);
return 0;
};
int CmdHFFido2GetAssertion(const char *cmd) {
json_error_t error;
json_t *root = NULL;
char fname[300] = {0};
CLIParserInit("hf fido assert",
"Execute a FIDO2 Get Assertion command. Needs json file with parameters. Sample file `fido2.json`. File can be placed in proxmark directory or in `proxmark/fido` directory.",
"Usage:\n\thf fido assert -> execute command default parameters file `fido2.json`\n"
"\thf fido assert test.json -l -> execute command with parameters file `text.json` and add to request CredentialId");
void* argtable[] = {
arg_param_begin,
arg_lit0("aA", "apdu", "show APDU reqests and responses"),
arg_litn("vV", "verbose", 0, 2, "show technical data. vv - show full certificates data"),
arg_lit0("cC", "cbor", "show CBOR decoded data"),
arg_lit0("lL", "list", "add CredentialId from json to allowList. Needs if `rk` option is `false` (authenticator don't store credential to its memory)"),
arg_str0(NULL, NULL, "<json file name>", "JSON input / output file name for parameters. Default `fido2.json`"),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool APDULogging = arg_get_lit(1);
bool verbose = arg_get_lit(2);
bool verbose2 = arg_get_lit(2) > 1;
bool showCBOR = arg_get_lit(3);
bool createAllowList = arg_get_lit(4);
uint8_t jsonname[250] ={0};
char *cjsonname = (char *)jsonname;
int jsonnamelen = 0;
CLIGetStrWithReturn(5, jsonname, &jsonnamelen);
if (!jsonnamelen) {
strcat(cjsonname, "fido2");
jsonnamelen = strlen(cjsonname);
}
CLIParserFree();
SetAPDULogging(APDULogging);
int res = GetExistsFileNameJson("fido", "fido2", fname);
if(res) {
PrintAndLog("ERROR: Can't found the json file.");
return res;
}
PrintAndLog("fname: %s\n", fname);
root = json_load_file(fname, 0, &error);
if (!root) {
PrintAndLog("ERROR: json error on line %d: %s", error.line, error.text);
return 1;
}
uint8_t data[2048] = {0};
size_t datalen = 0;
uint8_t buf[2048] = {0};
size_t len = 0;
uint16_t sw = 0;
DropField();
res = FIDOSelect(true, true, buf, sizeof(buf), &len, &sw);
if (res) {
PrintAndLog("Can't select authenticator. res=%x. Exit...", res);
DropField();
return res;
}
if (sw != 0x9000) {
PrintAndLog("Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
DropField();
return 2;
}
res = FIDO2CreateGetAssertionReq(root, data, sizeof(data), &datalen, createAllowList);
if (res)
return res;
if (showCBOR) {
PrintAndLog("CBOR get assertion request:");
PrintAndLog("---------------- CBOR ------------------");
TinyCborPrintFIDOPackage(fido2CmdGetAssertion, false, data, datalen);
PrintAndLog("---------------- CBOR ------------------");
}
res = FIDO2GetAssertion(data, datalen, buf, sizeof(buf), &len, &sw);
DropField();
if (res) {
PrintAndLog("Can't execute get assertion command. res=%x. Exit...", res);
return res;
}
if (sw != 0x9000) {
PrintAndLog("ERROR execute get assertion command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return 3;
}
if(buf[0]) {
PrintAndLog("FIDO2 get assertion error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0]));
return 0;
}
PrintAndLog("GetAssertion result (%d b) OK.", len);
if (showCBOR) {
PrintAndLog("CBOR get assertion response:");
PrintAndLog("---------------- CBOR ------------------");
TinyCborPrintFIDOPackage(fido2CmdGetAssertion, true, &buf[1], len - 1);
PrintAndLog("---------------- CBOR ------------------");
}
// parse returned cbor
FIDO2GetAssertionParseRes(root, &buf[1], len - 1, verbose, verbose2, showCBOR);
if (root) {
res = json_dump_file(root, fname, JSON_INDENT(2));
if (res) {
PrintAndLog("ERROR: can't save the file: %s", fname);
return 200;
}
PrintAndLog("File `%s` saved.", fname);
}
json_decref(root);
return 0;
};
static command_t CommandTable[] =
{
{"help", CmdHelp, 1, "This help."},
{"info", CmdHFFidoInfo, 0, "Info about FIDO tag."},
{"reg", CmdHFFidoRegister, 0, "FIDO U2F Registration Message."},
{"auth", CmdHFFidoAuthenticate, 0, "FIDO U2F Authentication Message."},
{"make", CmdHFFido2MakeCredential, 0, "FIDO2 MakeCredential command."},
{"assert", CmdHFFido2GetAssertion, 0, "FIDO2 GetAssertion command."},
{NULL, NULL, 0, NULL}
};
int CmdHFFido(const char *Cmd) {
(void)WaitForResponseTimeout(CMD_ACK,NULL,100);
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

27
client/cmdhffido.h Normal file
View file

@ -0,0 +1,27 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2018 Merlok
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// High frequency FIDO U2F and FIDO2 contactless authenticators
//-----------------------------------------------------------------------------
//
// Documentation here:
//
// FIDO Alliance specifications
// https://fidoalliance.org/download/
// FIDO NFC Protocol Specification v1.0
// https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-nfc-protocol-v1.2-ps-20170411.html
// FIDO U2F Raw Message Formats
// https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-raw-message-formats-v1.2-ps-20170411.html
//-----------------------------------------------------------------------------
#ifndef CMDHFFIDO_H__
#define CMDHFFIDO_H__
extern int CmdHFFido(const char *Cmd);
#endif

File diff suppressed because it is too large Load diff

View file

@ -13,11 +13,6 @@
#define CMDHFICLASS_H__
int CmdHFiClass(const char *Cmd);
int CmdHFiClassSnoop(const char *Cmd);
int CmdHFiClassSim(const char *Cmd);
int CmdHFiClassList(const char *Cmd);
int CmdHFiClassReader(const char *Cmd);
int saveFile(const char *preferredName, const char *suffix, const void* data, size_t datalen);
int HFiClassReader(bool loop, bool verbose);
#endif

View file

@ -8,41 +8,43 @@
// High frequency Legic commands
//-----------------------------------------------------------------------------
#include "cmdhflegic.h"
#include <stdio.h>
#include <string.h>
//#include "proxusb.h"
#include "proxmark3.h"
#include "data.h"
#include <inttypes.h>
#include "comms.h"
#include "ui.h"
#include "cmdparser.h"
#include "cmdhflegic.h"
#include "cmdmain.h"
#include "util.h"
#include "../include/legic.h"
static int CmdHelp(const char *Cmd);
static command_t CommandTable[] =
static command_t CommandTable[] =
{
{"help", CmdHelp, 1, "This help"},
{"decode", CmdLegicDecode, 0, "Display deobfuscated and decoded LEGIC RF tag data (use after hf legic reader)"},
{"reader", CmdLegicRFRead, 0, "[offset [length]] -- read bytes from a LEGIC card"},
{"save", CmdLegicSave, 0, "<filename> [<length>] -- Store samples"},
{"load", CmdLegicLoad, 0, "<filename> -- Restore samples"},
{"sim", CmdLegicRfSim, 0, "[phase drift [frame drift [req/resp drift]]] Start tag simulator (use after load or read)"},
{"write", CmdLegicRfWrite,0, "<offset> <length> -- Write sample buffer (user after load or read)"},
{"fill", CmdLegicRfFill, 0, "<offset> <length> <value> -- Fill/Write tag with constant value"},
{NULL, NULL, 0, NULL}
{"help", CmdHelp, 1, "This help"},
{"decode", CmdLegicDecode, 0, "Display deobfuscated and decoded LEGIC RF tag data (use after hf legic reader)"},
{"reader", CmdLegicRFRead, 0, "[offset [length]] -- read bytes from a LEGIC card"},
{"save", CmdLegicSave, 0, "<filename> [<length>] -- Store samples"},
{"load", CmdLegicLoad, 0, "<filename> -- Restore samples"},
{"sim", CmdLegicRfSim, 0, "[tagtype, 0:MIM22, 1:MIM256, 2:MIM1024] Start tag simulator (use after load or read)"},
{"write", CmdLegicRfWrite,0, "<offset> <length> -- Write sample buffer (user after load or read)"},
{"fill", CmdLegicRfFill, 0, "<offset> <length> <value> -- Fill/Write tag with constant value"},
{NULL, NULL, 0, NULL}
};
int CmdHFLegic(const char *Cmd)
{
CmdsParse(CommandTable, Cmd);
return 0;
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
CmdsHelp(CommandTable);
return 0;
CmdsHelp(CommandTable);
return 0;
}
/*
@ -52,299 +54,327 @@ int CmdHelp(const char *Cmd)
*/
int CmdLegicDecode(const char *Cmd)
{
int i, j, k, n;
int segment_len = 0;
int segment_flag = 0;
int stamp_len = 0;
int crc = 0;
int wrp = 0;
int wrc = 0;
uint8_t data_buf[1024]; // receiver buffer
char out_string[3076]; // just use big buffer - bad practice
char token_type[4];
// copy data from proxmark into buffer
GetFromBigBuf(data_buf,sizeof(data_buf),0);
WaitForResponse(CMD_ACK,NULL);
// Output CDF System area (9 bytes) plus remaining header area (12 bytes)
PrintAndLog("\nCDF: System Area");
PrintAndLog("MCD: %02x, MSN: %02x %02x %02x, MCC: %02x",
data_buf[0],
data_buf[1],
data_buf[2],
data_buf[3],
data_buf[4]
);
crc = data_buf[4];
switch (data_buf[5]&0x7f) {
case 0x00 ... 0x2f:
strncpy(token_type, "IAM",sizeof(token_type));
break;
case 0x30 ... 0x6f:
strcpy(token_type, "SAM");
break;
case 0x70 ... 0x7f:
strcpy(token_type, "GAM");
break;
default:
strcpy(token_type, "???");
break;
}
stamp_len = 0xfc - data_buf[6];
PrintAndLog("DCF: %02x %02x, Token_Type=%s (OLE=%01u), Stamp_len=%02u",
data_buf[5],
data_buf[6],
token_type,
(data_buf[5]&0x80)>>7,
stamp_len
);
PrintAndLog("WRP=%02u, WRC=%01u, RD=%01u, raw=%02x, SSC=%02x",
data_buf[7]&0x0f,
(data_buf[7]&0x70)>>4,
(data_buf[7]&0x80)>>7,
data_buf[7],
data_buf[8]
);
PrintAndLog("Remaining Header Area");
PrintAndLog("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
data_buf[9],
data_buf[10],
data_buf[11],
data_buf[12],
data_buf[13],
data_buf[14],
data_buf[15],
data_buf[16],
data_buf[17],
data_buf[18],
data_buf[19],
data_buf[20],
data_buf[21]
);
PrintAndLog("\nADF: User Area");
i = 22;
for (n=0; n<64; n++) {
segment_len = ((data_buf[i+1]^crc)&0x0f) * 256 + (data_buf[i]^crc);
segment_flag = ((data_buf[i+1]^crc)&0xf0)>>4;
wrp = (data_buf[i+2]^crc);
wrc = ((data_buf[i+3]^crc)&0x70)>>4;
PrintAndLog("Segment %02u: raw header=%02x %02x %02x %02x, flag=%01x (valid=%01u, last=%01u), len=%04u, WRP=%02u, WRC=%02u, RD=%01u, CRC=%02x",
n,
data_buf[i]^crc,
data_buf[i+1]^crc,
data_buf[i+2]^crc,
data_buf[i+3]^crc,
segment_flag,
(segment_flag&0x4)>>2,
(segment_flag&0x8)>>3,
segment_len,
wrp,
wrc,
((data_buf[i+3]^crc)&0x80)>>7,
(data_buf[i+4]^crc)
);
i+=5;
if (wrc>0) {
PrintAndLog("WRC protected area:");
for (k=0, j=0; k < wrc && j<(sizeof(out_string)-3); k++, i++, j += 3) {
sprintf(&out_string[j], "%02x", (data_buf[i]^crc));
out_string[j+2] = ' ';
};
out_string[j] = '\0';
PrintAndLog("%s", out_string);
}
if (wrp>wrc) {
PrintAndLog("Remaining write protected area:");
for (k=0, j=0; k < (wrp-wrc) && j<(sizeof(out_string)-3); k++, i++, j += 3) {
sprintf(&out_string[j], "%02x", (data_buf[i]^crc));
out_string[j+2] = ' ';
};
out_string[j] = '\0';
PrintAndLog("%s", out_string);
if((wrp-wrc) == 8) {
sprintf(out_string,"Card ID: %2X%02X%02X",data_buf[i-4]^crc,data_buf[i-3]^crc,data_buf[i-2]^crc);
PrintAndLog("%s", out_string);
}
}
PrintAndLog("Remaining segment payload:");
for (k=0, j=0; k < (segment_len - wrp - 5) && j<(sizeof(out_string)-3); k++, i++, j += 3) {
sprintf(&out_string[j], "%02x", (data_buf[i]^crc));
out_string[j+2] = ' ';
};
out_string[j] = '\0';
PrintAndLog("%s", out_string);
// end with last segment
if (segment_flag & 0x8)
return 0;
};
return 0;
int i, j, k, n;
int segment_len = 0;
int segment_flag = 0;
int stamp_len = 0;
int crc = 0;
int wrp = 0;
int wrc = 0;
uint8_t data_buf[1053]; // receiver buffer
char out_string[3076]; // just use big buffer - bad practice
char token_type[4];
// copy data from proxmark into buffer
GetFromBigBuf(data_buf, sizeof(data_buf), 0, NULL, -1, false);
// Output CDF System area (9 bytes) plus remaining header area (12 bytes)
PrintAndLog("\nCDF: System Area");
PrintAndLog("MCD: %02x, MSN: %02x %02x %02x, MCC: %02x",
data_buf[0],
data_buf[1],
data_buf[2],
data_buf[3],
data_buf[4]
);
crc = data_buf[4];
switch (data_buf[5]&0x7f) {
case 0x00 ... 0x2f:
strncpy(token_type, "IAM",sizeof(token_type));
break;
case 0x30 ... 0x6f:
strcpy(token_type, "SAM");
break;
case 0x70 ... 0x7f:
strcpy(token_type, "GAM");
break;
default:
strcpy(token_type, "???");
break;
}
stamp_len = 0xfc - data_buf[6];
PrintAndLog("DCF: %02x %02x, Token_Type=%s (OLE=%01u), Stamp_len=%02u",
data_buf[5],
data_buf[6],
token_type,
(data_buf[5]&0x80)>>7,
stamp_len
);
PrintAndLog("WRP=%02u, WRC=%01u, RD=%01u, raw=%02x, SSC=%02x",
data_buf[7]&0x0f,
(data_buf[7]&0x70)>>4,
(data_buf[7]&0x80)>>7,
data_buf[7],
data_buf[8]
);
PrintAndLog("Remaining Header Area");
PrintAndLog("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
data_buf[9],
data_buf[10],
data_buf[11],
data_buf[12],
data_buf[13],
data_buf[14],
data_buf[15],
data_buf[16],
data_buf[17],
data_buf[18],
data_buf[19],
data_buf[20],
data_buf[21]
);
PrintAndLog("\nADF: User Area");
i = 22;
for (n=0; n<64; n++) {
segment_len = ((data_buf[i+1]^crc)&0x0f) * 256 + (data_buf[i]^crc);
segment_flag = ((data_buf[i+1]^crc)&0xf0)>>4;
wrp = (data_buf[i+2]^crc);
wrc = ((data_buf[i+3]^crc)&0x70)>>4;
PrintAndLog("Segment %02u: raw header=%02x %02x %02x %02x, flag=%01x (valid=%01u, last=%01u), len=%04u, WRP=%02u, WRC=%02u, RD=%01u, CRC=%02x",
n,
data_buf[i]^crc,
data_buf[i+1]^crc,
data_buf[i+2]^crc,
data_buf[i+3]^crc,
segment_flag,
(segment_flag&0x4)>>2,
(segment_flag&0x8)>>3,
segment_len,
wrp,
wrc,
((data_buf[i+3]^crc)&0x80)>>7,
(data_buf[i+4]^crc)
);
i+=5;
if (wrc>0) {
PrintAndLog("WRC protected area:");
for (k=0, j=0; k < wrc && j<(sizeof(out_string)-3); k++, i++, j += 3) {
sprintf(&out_string[j], "%02x", (data_buf[i]^crc));
out_string[j+2] = ' ';
};
out_string[j] = '\0';
PrintAndLog("%s", out_string);
}
if (wrp>wrc) {
PrintAndLog("Remaining write protected area:");
for (k=0, j=0; k < (wrp-wrc) && j<(sizeof(out_string)-3); k++, i++, j += 3) {
sprintf(&out_string[j], "%02x", (data_buf[i]^crc));
out_string[j+2] = ' ';
};
out_string[j] = '\0';
PrintAndLog("%s", out_string);
if((wrp-wrc) == 8) {
sprintf(out_string,"Card ID: %2X%02X%02X",data_buf[i-4]^crc,data_buf[i-3]^crc,data_buf[i-2]^crc);
PrintAndLog("%s", out_string);
}
}
PrintAndLog("Remaining segment payload:");
for (k=0, j=0; k < (segment_len - wrp - 5) && j<(sizeof(out_string)-3); k++, i++, j += 3) {
sprintf(&out_string[j], "%02x", (data_buf[i]^crc));
out_string[j+2] = ' ';
};
out_string[j] = '\0';
PrintAndLog("%s", out_string);
// end with last segment
if (segment_flag & 0x8)
return 0;
};
return 0;
}
int CmdLegicRFRead(const char *Cmd)
{
int byte_count=0,offset=0;
sscanf(Cmd, "%i %i", &offset, &byte_count);
if(byte_count == 0) byte_count = -1;
if(byte_count + offset > 1024) byte_count = 1024 - offset;
UsbCommand c={CMD_READER_LEGIC_RF, {offset, byte_count, 0}};
SendCommand(&c);
return 0;
int byte_count=0,offset=0;
sscanf(Cmd, "%i %i", &offset, &byte_count);
if(byte_count == 0) byte_count = -1;
if(byte_count + offset > 1024) byte_count = 1024 - offset;
UsbCommand c={CMD_READER_LEGIC_RF, {offset, byte_count, 0}};
SendCommand(&c);
UsbCommand resp;
WaitForResponse(CMD_ACK,&resp);
switch (resp.arg[0]) {
legic_card_select_t card;
case 0:
memcpy(&card, resp.d.asBytes, sizeof(card));
PrintAndLog("Card (MIM %i) read, use 'hf legic decode' or", card.cardsize);
PrintAndLog("'data hexsamples %d' to view results", (resp.arg[1] + 7) & ~7);
break;
case 1:
PrintAndLog("No or unknown card found, aborting");
break;
case 2:
PrintAndLog("operation failed @ 0x%03.3x", resp.arg[1]);
break;
}
return resp.arg[0];
}
int CmdLegicLoad(const char *Cmd)
{
FILE *f = fopen(Cmd, "r");
if(!f) {
PrintAndLog("couldn't open '%s'", Cmd);
return -1;
}
char line[80]; int offset = 0; unsigned int data[8];
while(fgets(line, sizeof(line), f)) {
int res = sscanf(line, "%x %x %x %x %x %x %x %x",
&data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]);
if(res != 8) {
PrintAndLog("Error: could not read samples");
fclose(f);
return -1;
}
UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {offset, 0, 0}};
int j; for(j = 0; j < 8; j++) {
c.d.asBytes[j] = data[j];
}
SendCommand(&c);
WaitForResponse(CMD_ACK, NULL);
offset += 8;
}
fclose(f);
PrintAndLog("loaded %u samples", offset);
return 0;
char filename[FILE_PATH_SIZE] = {0x00};
int len = 0;
if (param_getchar(Cmd, 0) == 'h' || param_getchar(Cmd, 0)== 0x00) {
PrintAndLog("It loads datasamples from the file `filename`");
PrintAndLog("Usage: hf legic load <file name>");
PrintAndLog(" sample: hf legic load filename");
return 0;
}
len = strlen(Cmd);
if (len > FILE_PATH_SIZE) {
PrintAndLog("Filepath too long (was %s bytes), max allowed is %s ", len, FILE_PATH_SIZE);
return 0;
}
memcpy(filename, Cmd, len);
FILE *f = fopen(filename, "r");
if (!f) {
PrintAndLog("couldn't open '%s'", Cmd);
return -1;
}
char line[80]; int offset = 0; unsigned int data[8];
while (fgets(line, sizeof(line), f)) {
int res = sscanf(line, "%x %x %x %x %x %x %x %x",
&data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]);
if (res != 8) {
PrintAndLog("Error: could not read samples");
fclose(f);
return -1;
}
UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {offset, 1, 0}};
int j; for(j = 0; j < 8; j++) {
c.d.asBytes[j] = data[j];
}
SendCommand(&c);
WaitForResponse(CMD_ACK, NULL);
offset += 8;
}
fclose(f);
PrintAndLog("loaded %u samples", offset);
return 0;
}
int CmdLegicSave(const char *Cmd)
{
int requested = 1024;
int offset = 0;
int delivered = 0;
char filename[1024];
uint8_t got[1024];
sscanf(Cmd, " %s %i %i", filename, &requested, &offset);
int requested = 1024;
int offset = 0;
int delivered = 0;
char filename[FILE_PATH_SIZE];
uint8_t got[1024];
/* If no length given save entire legic read buffer */
/* round up to nearest 8 bytes so the saved data can be used with legicload */
if (requested == 0) {
requested = 1024;
}
if (requested % 8 != 0) {
int remainder = requested % 8;
requested = requested + 8 - remainder;
}
if (offset + requested > sizeof(got)) {
PrintAndLog("Tried to read past end of buffer, <bytes> + <offset> > 1024");
return 0;
}
FILE *f = fopen(filename, "w");
if(!f) {
PrintAndLog("couldn't open '%s'", Cmd+1);
return -1;
}
sscanf(Cmd, " %s %i %i", filename, &requested, &offset);
GetFromBigBuf(got,requested,offset);
WaitForResponse(CMD_ACK,NULL);
/* If no length given save entire legic read buffer */
/* round up to nearest 8 bytes so the saved data can be used with legicload */
if (requested == 0) {
requested = 1024;
}
if (requested % 8 != 0) {
int remainder = requested % 8;
requested = requested + 8 - remainder;
}
if (offset + requested > sizeof(got)) {
PrintAndLog("Tried to read past end of buffer, <bytes> + <offset> > 1024");
return 0;
}
for (int j = 0; j < requested; j += 8) {
fprintf(f, "%02x %02x %02x %02x %02x %02x %02x %02x\n",
got[j+0],
got[j+1],
got[j+2],
got[j+3],
got[j+4],
got[j+5],
got[j+6],
got[j+7]
);
delivered += 8;
if (delivered >= requested)
break;
}
FILE *f = fopen(filename, "w");
if (!f) {
PrintAndLog("couldn't open '%s'", Cmd+1);
return -1;
}
fclose(f);
PrintAndLog("saved %u samples", delivered);
return 0;
GetFromBigBuf(got, requested, offset, NULL, -1, false);
for (int j = 0; j < requested; j += 8) {
fprintf(f, "%02x %02x %02x %02x %02x %02x %02x %02x\n",
got[j+0],
got[j+1],
got[j+2],
got[j+3],
got[j+4],
got[j+5],
got[j+6],
got[j+7]
);
delivered += 8;
if (delivered >= requested)
break;
}
fclose(f);
PrintAndLog("saved %u samples", delivered);
return 0;
}
int CmdLegicRfSim(const char *Cmd)
{
UsbCommand c={CMD_SIMULATE_TAG_LEGIC_RF};
c.arg[0] = 6;
c.arg[1] = 3;
c.arg[2] = 0;
sscanf(Cmd, " %"lli" %"lli" %"lli, &c.arg[0], &c.arg[1], &c.arg[2]);
c.arg[0] = 1;
sscanf(Cmd, " %" SCNi64, &c.arg[0]);
SendCommand(&c);
return 0;
}
int CmdLegicRfWrite(const char *Cmd)
{
UsbCommand c={CMD_WRITER_LEGIC_RF};
int res = sscanf(Cmd, " 0x%"llx" 0x%"llx, &c.arg[0], &c.arg[1]);
if(res != 2) {
UsbCommand c={CMD_WRITER_LEGIC_RF};
int res = sscanf(Cmd, " 0x%" SCNx64 " 0x%" SCNx64, &c.arg[0], &c.arg[1]);
if (res != 2) {
PrintAndLog("Please specify the offset and length as two hex strings");
return -1;
}
SendCommand(&c);
return 0;
return -1;
}
SendCommand(&c);
return 0;
}
int CmdLegicRfFill(const char *Cmd)
{
UsbCommand cmd ={CMD_WRITER_LEGIC_RF};
int res = sscanf(Cmd, " 0x%"llx" 0x%"llx" 0x%"llx, &cmd.arg[0], &cmd.arg[1], &cmd.arg[2]);
if(res != 3) {
PrintAndLog("Please specify the offset, length and value as two hex strings");
return -1;
}
UsbCommand cmd ={CMD_WRITER_LEGIC_RF};
int res = sscanf(Cmd, " 0x%" SCNx64 " 0x%" SCNx64 " 0x%" SCNx64, &cmd.arg[0], &cmd.arg[1], &cmd.arg[2]);
if (res != 3) {
PrintAndLog("Please specify the offset, length and value as two hex strings");
return -1;
}
int i;
UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {0, 0, 0}};
for(i = 0; i < 48; i++) {
c.d.asBytes[i] = cmd.arg[2];
}
for(i = 0; i < 22; i++) {
c.arg[0] = i*48;
SendCommand(&c);
WaitForResponse(CMD_ACK,NULL);
}
SendCommand(&cmd);
return 0;
int i;
UsbCommand c={CMD_DOWNLOADED_SIM_SAMPLES_125K, {0, 1, 0}};
for (i = 0; i < 48; i++) {
c.d.asBytes[i] = cmd.arg[2];
}
for (i = 0; i < 22; i++) {
c.arg[0] = i*48;
SendCommand(&c);
WaitForResponse(CMD_ACK,NULL);
}
SendCommand(&cmd);
return 0;
}

1249
client/cmdhflist.c Normal file

File diff suppressed because it is too large Load diff

16
client/cmdhflist.h Normal file
View file

@ -0,0 +1,16 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
// Copyright (C) Merlok - 2017
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// Command: hf mf list. It shows data from arm buffer.
//-----------------------------------------------------------------------------
#ifndef CMDHFLIST_H
#define CMDHFLIST_H
extern int CmdHFList(const char *Cmd);
#endif // CMDHFLIST_H

File diff suppressed because it is too large Load diff

View file

@ -11,48 +11,6 @@
#ifndef CMDHFMF_H__
#define CMDHFMF_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "proxmark3.h"
#include "iso14443crc.h"
#include "data.h"
//#include "proxusb.h"
#include "ui.h"
#include "cmdparser.h"
#include "common.h"
#include "util.h"
#include "mifarehost.h"
int CmdHFMF(const char *Cmd);
int CmdHF14AMfDbg(const char* cmd);
int CmdHF14AMfRdBl(const char* cmd);
int CmdHF14AMfURdBl(const char* cmd);
int CmdHF14AMfRdSc(const char* cmd);
int CmdHF14SMfURdCard(const char* cmd);
int CmdHF14AMfDump(const char* cmd);
int CmdHF14AMfRestore(const char* cmd);
int CmdHF14AMfWrBl(const char* cmd);
int CmdHF14AMfUWrBl(const char* cmd);
int CmdHF14AMfChk(const char* cmd);
int CmdHF14AMifare(const char* cmd);
int CmdHF14AMfNested(const char* cmd);
int CmdHF14AMfSniff(const char* cmd);
int CmdHF14AMf1kSim(const char* cmd);
int CmdHF14AMfEClear(const char* cmd);
int CmdHF14AMfEGet(const char* cmd);
int CmdHF14AMfESet(const char* cmd);
int CmdHF14AMfELoad(const char* cmd);
int CmdHF14AMfESave(const char* cmd);
int CmdHF14AMfECFill(const char* cmd);
int CmdHF14AMfEKeyPrn(const char* cmd);
int CmdHF14AMfCSetUID(const char* cmd);
int CmdHF14AMfCSetBlk(const char* cmd);
int CmdHF14AMfCGetBlk(const char* cmd);
int CmdHF14AMfCGetSc(const char* cmd);
int CmdHF14AMfCLoad(const char* cmd);
int CmdHF14AMfCSave(const char* cmd);
extern int CmdHFMF(const char *Cmd);
#endif

2740
client/cmdhfmfhard.c Normal file

File diff suppressed because it is too large Load diff

48
client/cmdhfmfhard.h Normal file
View file

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2015 piwi
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// hf mf hardnested command
//-----------------------------------------------------------------------------
#ifndef CMDHFMFHARD_H__
#define CMDHFMFHARD_H__
#include <stdint.h>
#include <stdbool.h>
#define NUM_SUMS 19 // number of possible sum property values
typedef struct guess_sum_a8 {
float prob;
uint64_t num_states;
uint8_t sum_a8_idx;
} guess_sum_a8_t;
typedef struct noncelistentry {
uint32_t nonce_enc;
uint8_t par_enc;
void *next;
} noncelistentry_t;
typedef struct noncelist {
uint16_t num;
uint16_t Sum;
guess_sum_a8_t sum_a8_guess[NUM_SUMS];
bool sum_a8_guess_dirty;
float expected_num_brute_force;
uint8_t BitFlips[0x400];
uint32_t *states_bitarray[2];
uint32_t num_states_bitarray[2];
bool all_bitflips_dirty[2];
noncelistentry_t *first;
} noncelist_t;
int mfnestedhard(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *trgkey, bool nonce_file_read, bool nonce_file_write, bool slow, int tests);
void hardnested_print_progress(uint32_t nonces, char *activity, float brute_force, uint64_t min_diff_print_time);
#endif

867
client/cmdhfmfp.c Normal file
View file

@ -0,0 +1,867 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2018 Merlok
// Copyright (C) 2018 drHatson
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// High frequency MIFARE Plus commands
//-----------------------------------------------------------------------------
#include "cmdhfmfp.h"
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "comms.h"
#include "cmdmain.h"
#include "util.h"
#include "ui.h"
#include "cmdhf14a.h"
#include "mifare.h"
#include "mifare/mifare4.h"
#include "mifare/mad.h"
#include "mifare/ndef.h"
#include "cliparser/cliparser.h"
#include "crypto/libpcrypto.h"
#include "emv/dump.h"
static const uint8_t DefaultKey[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
static int CmdHelp(const char *Cmd);
int CmdHFMFPInfo(const char *cmd) {
if (cmd && strlen(cmd) > 0)
PrintAndLog("WARNING: command don't have any parameters.\n");
// info about 14a part
CmdHF14AInfo("");
// Mifare Plus info
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}};
SendCommand(&c);
UsbCommand resp;
WaitForResponse(CMD_ACK,&resp);
iso14a_card_select_t card;
memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
uint64_t select_status = resp.arg[0]; // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
if (select_status == 1 || select_status == 2) {
PrintAndLog("----------------------------------------------");
PrintAndLog("Mifare Plus info:");
// MIFARE Type Identification Procedure
// https://www.nxp.com/docs/en/application-note/AN10833.pdf
uint16_t ATQA = card.atqa[0] + (card.atqa[1] << 8);
if (ATQA == 0x0004) PrintAndLog("ATQA: Mifare Plus 2k 4bUID");
if (ATQA == 0x0002) PrintAndLog("ATQA: Mifare Plus 4k 4bUID");
if (ATQA == 0x0044) PrintAndLog("ATQA: Mifare Plus 2k 7bUID");
if (ATQA == 0x0042) PrintAndLog("ATQA: Mifare Plus 4k 7bUID");
uint8_t SLmode = 0xff;
if (card.sak == 0x08) {
PrintAndLog("SAK: Mifare Plus 2k 7bUID");
if (select_status == 2) SLmode = 1;
}
if (card.sak == 0x18) {
PrintAndLog("SAK: Mifare Plus 4k 7bUID");
if (select_status == 2) SLmode = 1;
}
if (card.sak == 0x10) {
PrintAndLog("SAK: Mifare Plus 2k");
if (select_status == 2) SLmode = 2;
}
if (card.sak == 0x11) {
PrintAndLog("SAK: Mifare Plus 4k");
if (select_status == 2) SLmode = 2;
}
if (card.sak == 0x20) {
PrintAndLog("SAK: Mifare Plus SL0/SL3 or Mifare desfire");
if (card.ats_len > 0) {
SLmode = 3;
// check SL0
uint8_t data[250] = {0};
int datalen = 0;
// https://github.com/Proxmark/proxmark3/blob/master/client/scripts/mifarePlus.lua#L161
uint8_t cmd[3 + 16] = {0xa8, 0x90, 0x90, 0x00};
int res = ExchangeRAW14a(cmd, sizeof(cmd), false, false, data, sizeof(data), &datalen);
if (!res && datalen > 1 && data[0] == 0x09) {
SLmode = 0;
}
}
}
if (SLmode != 0xff)
PrintAndLog("Mifare Plus SL mode: SL%d", SLmode);
else
PrintAndLog("Mifare Plus SL mode: unknown(");
} else {
PrintAndLog("Mifare Plus info not available.");
}
DropField();
return 0;
}
int CmdHFMFPWritePerso(const char *cmd) {
uint8_t keyNum[64] = {0};
int keyNumLen = 0;
uint8_t key[64] = {0};
int keyLen = 0;
CLIParserInit("hf mfp wrp",
"Executes Write Perso command. Can be used in SL0 mode only.",
"Usage:\n\thf mfp wrp 4000 000102030405060708090a0b0c0d0e0f -> write key (00..0f) to key number 4000 \n"
"\thf mfp wrp 4000 -> write default key(0xff..0xff) to key number 4000");
void* argtable[] = {
arg_param_begin,
arg_lit0("vV", "verbose", "show internal data."),
arg_str1(NULL, NULL, "<HEX key number (2b)>", NULL),
arg_strx0(NULL, NULL, "<HEX key (16b)>", NULL),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool verbose = arg_get_lit(1);
CLIGetHexWithReturn(2, keyNum, &keyNumLen);
CLIGetHexWithReturn(3, key, &keyLen);
CLIParserFree();
mfpSetVerboseMode(verbose);
if (!keyLen) {
memmove(key, DefaultKey, 16);
keyLen = 16;
}
if (keyNumLen != 2) {
PrintAndLog("Key number length must be 2 bytes instead of: %d", keyNumLen);
return 1;
}
if (keyLen != 16) {
PrintAndLog("Key length must be 16 bytes instead of: %d", keyLen);
return 1;
}
uint8_t data[250] = {0};
int datalen = 0;
int res = MFPWritePerso(keyNum, key, true, false, data, sizeof(data), &datalen);
if (res) {
PrintAndLog("Exchange error: %d", res);
return res;
}
if (datalen != 3) {
PrintAndLog("Command must return 3 bytes instead of: %d", datalen);
return 1;
}
if (data[0] != 0x90) {
PrintAndLog("Command error: %02x %s", data[0], mfpGetErrorDescription(data[0]));
return 1;
}
PrintAndLog("Write OK.");
return 0;
}
uint16_t CardAddresses[] = {0x9000, 0x9001, 0x9002, 0x9003, 0x9004, 0xA000, 0xA001, 0xA080, 0xA081, 0xC000, 0xC001};
int CmdHFMFPInitPerso(const char *cmd) {
int res;
uint8_t key[256] = {0};
int keyLen = 0;
uint8_t keyNum[2] = {0};
uint8_t data[250] = {0};
int datalen = 0;
CLIParserInit("hf mfp initp",
"Executes Write Perso command for all card's keys. Can be used in SL0 mode only.",
"Usage:\n\thf mfp initp 000102030405060708090a0b0c0d0e0f -> fill all the keys with key (00..0f)\n"
"\thf mfp initp -vv -> fill all the keys with default key(0xff..0xff) and show all the data exchange");
void* argtable[] = {
arg_param_begin,
arg_litn("vV", "verbose", 0, 2, "show internal data."),
arg_strx0(NULL, NULL, "<HEX key (16b)>", NULL),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool verbose = arg_get_lit(1);
bool verbose2 = arg_get_lit(1) > 1;
CLIGetHexWithReturn(2, key, &keyLen);
CLIParserFree();
if (keyLen && keyLen != 16) {
PrintAndLog("Key length must be 16 bytes instead of: %d", keyLen);
return 1;
}
if (!keyLen)
memmove(key, DefaultKey, 16);
mfpSetVerboseMode(verbose2);
for (uint16_t sn = 0x4000; sn < 0x4050; sn++) {
keyNum[0] = sn >> 8;
keyNum[1] = sn & 0xff;
res = MFPWritePerso(keyNum, key, (sn == 0x4000), true, data, sizeof(data), &datalen);
if (!res && (datalen == 3) && data[0] == 0x09) {
PrintAndLog("2k card detected.");
break;
}
if (res || (datalen != 3) || data[0] != 0x90) {
PrintAndLog("Write error on address %04x", sn);
break;
}
}
mfpSetVerboseMode(verbose);
for (int i = 0; i < sizeof(CardAddresses) / 2; i++) {
keyNum[0] = CardAddresses[i] >> 8;
keyNum[1] = CardAddresses[i] & 0xff;
res = MFPWritePerso(keyNum, key, false, true, data, sizeof(data), &datalen);
if (!res && (datalen == 3) && data[0] == 0x09) {
PrintAndLog("Skipped[%04x]...", CardAddresses[i]);
} else {
if (res || (datalen != 3) || data[0] != 0x90) {
PrintAndLog("Write error on address %04x", CardAddresses[i]);
break;
}
}
}
DropField();
if (res)
return res;
PrintAndLog("Done.");
return 0;
}
int CmdHFMFPCommitPerso(const char *cmd) {
CLIParserInit("hf mfp commitp",
"Executes Commit Perso command. Can be used in SL0 mode only.",
"Usage:\n\thf mfp commitp -> \n");
void* argtable[] = {
arg_param_begin,
arg_lit0("vV", "verbose", "show internal data."),
arg_int0(NULL, NULL, "SL mode", NULL),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool verbose = arg_get_lit(1);
CLIParserFree();
mfpSetVerboseMode(verbose);
uint8_t data[250] = {0};
int datalen = 0;
int res = MFPCommitPerso(true, false, data, sizeof(data), &datalen);
if (res) {
PrintAndLog("Exchange error: %d", res);
return res;
}
if (datalen != 3) {
PrintAndLog("Command must return 3 bytes instead of: %d", datalen);
return 1;
}
if (data[0] != 0x90) {
PrintAndLog("Command error: %02x %s", data[0], mfpGetErrorDescription(data[0]));
return 1;
}
PrintAndLog("Switch level OK.");
return 0;
}
int CmdHFMFPAuth(const char *cmd) {
uint8_t keyn[250] = {0};
int keynlen = 0;
uint8_t key[250] = {0};
int keylen = 0;
CLIParserInit("hf mfp auth",
"Executes AES authentication command for Mifare Plus card",
"Usage:\n\thf mfp auth 4000 000102030405060708090a0b0c0d0e0f -> executes authentication\n"
"\thf mfp auth 9003 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -v -> executes authentication and shows all the system data\n");
void* argtable[] = {
arg_param_begin,
arg_lit0("vV", "verbose", "show internal data."),
arg_str1(NULL, NULL, "<Key Num (HEX 2 bytes)>", NULL),
arg_str1(NULL, NULL, "<Key Value (HEX 16 bytes)>", NULL),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool verbose = arg_get_lit(1);
CLIGetHexWithReturn(2, keyn, &keynlen);
CLIGetHexWithReturn(3, key, &keylen);
CLIParserFree();
if (keynlen != 2) {
PrintAndLog("ERROR: <Key Num> must be 2 bytes long instead of: %d", keynlen);
return 1;
}
if (keylen != 16) {
PrintAndLog("ERROR: <Key Value> must be 16 bytes long instead of: %d", keylen);
return 1;
}
return MifareAuth4(NULL, keyn, key, true, false, verbose);
}
int CmdHFMFPRdbl(const char *cmd) {
uint8_t keyn[2] = {0};
uint8_t key[250] = {0};
int keylen = 0;
CLIParserInit("hf mfp rdbl",
"Reads several blocks from Mifare Plus card.",
"Usage:\n\thf mfp rdbl 0 000102030405060708090a0b0c0d0e0f -> executes authentication and read block 0 data\n"
"\thf mfp rdbl 1 -v -> executes authentication and shows sector 1 data with default key 0xFF..0xFF and some additional data\n");
void* argtable[] = {
arg_param_begin,
arg_lit0("vV", "verbose", "show internal data."),
arg_int0("nN", "count", "blocks count (by default 1).", NULL),
arg_lit0("bB", "keyb", "use key B (by default keyA)."),
arg_lit0("pP", "plain", "plain communication mode between reader and card."),
arg_int1(NULL, NULL, "<Block Num (0..255)>", NULL),
arg_str0(NULL, NULL, "<Key Value (HEX 16 bytes)>", NULL),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, false);
bool verbose = arg_get_lit(1);
int blocksCount = arg_get_int_def(2, 1);
bool keyB = arg_get_lit(3);
int plain = arg_get_lit(4);
uint32_t blockn = arg_get_int(5);
CLIGetHexWithReturn(6, key, &keylen);
CLIParserFree();
mfpSetVerboseMode(verbose);
if (!keylen) {
memmove(key, DefaultKey, 16);
keylen = 16;
}
if (blockn > 255) {
PrintAndLog("ERROR: <Block Num> must be in range [0..255] instead of: %d", blockn);
return 1;
}
if (keylen != 16) {
PrintAndLog("ERROR: <Key Value> must be 16 bytes long instead of: %d", keylen);
return 1;
}
// 3 blocks - wo iso14443-4 chaining
if (blocksCount > 3) {
PrintAndLog("ERROR: blocks count must be less than 3 instead of: %d", blocksCount);
return 1;
}
if (blocksCount > 1 && mfIsSectorTrailer(blockn)) {
PrintAndLog("WARNING: trailer!");
}
uint8_t sectorNum = mfSectorNum(blockn & 0xff);
uint16_t uKeyNum = 0x4000 + sectorNum * 2 + (keyB ? 1 : 0);
keyn[0] = uKeyNum >> 8;
keyn[1] = uKeyNum & 0xff;
if (verbose)
PrintAndLog("--block:%d sector[%d]:%02x key:%04x", blockn, mfNumBlocksPerSector(sectorNum), sectorNum, uKeyNum);
mf4Session session;
int res = MifareAuth4(&session, keyn, key, true, true, verbose);
if (res) {
PrintAndLog("Authentication error: %d", res);
return res;
}
uint8_t data[250] = {0};
int datalen = 0;
uint8_t mac[8] = {0};
res = MFPReadBlock(&session, plain, blockn & 0xff, blocksCount, false, false, data, sizeof(data), &datalen, mac);
if (res) {
PrintAndLog("Read error: %d", res);
return res;
}
if (datalen && data[0] != 0x90) {
PrintAndLog("Card read error: %02x %s", data[0], mfpGetErrorDescription(data[0]));
return 6;
}
if (datalen != 1 + blocksCount * 16 + 8 + 2) {
PrintAndLog("Error return length:%d", datalen);
return 5;
}
int indx = blockn;
for(int i = 0; i < blocksCount; i++) {
PrintAndLog("data[%03d]: %s", indx, sprint_hex(&data[1 + i * 16], 16));
indx++;
if (mfIsSectorTrailer(indx) && i != blocksCount - 1){
PrintAndLog("data[%03d]: ------------------- trailer -------------------", indx);
indx++;
}
}
if (memcmp(&data[blocksCount * 16 + 1], mac, 8)) {
PrintAndLog("WARNING: mac not equal...");
PrintAndLog("MAC card: %s", sprint_hex(&data[blocksCount * 16 + 1], 8));
PrintAndLog("MAC reader: %s", sprint_hex(mac, 8));
} else {
if(verbose)
PrintAndLog("MAC: %s", sprint_hex(&data[blocksCount * 16 + 1], 8));
}
return 0;
}
int CmdHFMFPRdsc(const char *cmd) {
uint8_t keyn[2] = {0};
uint8_t key[250] = {0};
int keylen = 0;
CLIParserInit("hf mfp rdsc",
"Reads one sector from Mifare Plus card.",
"Usage:\n\thf mfp rdsc 0 000102030405060708090a0b0c0d0e0f -> executes authentication and read sector 0 data\n"
"\thf mfp rdsc 1 -v -> executes authentication and shows sector 1 data with default key 0xFF..0xFF and some additional data\n");
void* argtable[] = {
arg_param_begin,
arg_lit0("vV", "verbose", "show internal data."),
arg_lit0("bB", "keyb", "use key B (by default keyA)."),
arg_lit0("pP", "plain", "plain communication mode between reader and card."),
arg_int1(NULL, NULL, "<Sector Num (0..255)>", NULL),
arg_str0(NULL, NULL, "<Key Value (HEX 16 bytes)>", NULL),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, false);
bool verbose = arg_get_lit(1);
bool keyB = arg_get_lit(2);
bool plain = arg_get_lit(3);
uint32_t sectorNum = arg_get_int(4);
CLIGetHexWithReturn(5, key, &keylen);
CLIParserFree();
mfpSetVerboseMode(verbose);
if (!keylen) {
memmove(key, DefaultKey, 16);
keylen = 16;
}
if (sectorNum > 39) {
PrintAndLog("ERROR: <Sector Num> must be in range [0..39] instead of: %d", sectorNum);
return 1;
}
if (keylen != 16) {
PrintAndLog("ERROR: <Key Value> must be 16 bytes long instead of: %d", keylen);
return 1;
}
uint16_t uKeyNum = 0x4000 + sectorNum * 2 + (keyB ? 1 : 0);
keyn[0] = uKeyNum >> 8;
keyn[1] = uKeyNum & 0xff;
if (verbose)
PrintAndLog("--sector[%d]:%02x key:%04x", mfNumBlocksPerSector(sectorNum), sectorNum, uKeyNum);
mf4Session session;
int res = MifareAuth4(&session, keyn, key, true, true, verbose);
if (res) {
PrintAndLog("Authentication error: %d", res);
return res;
}
uint8_t data[250] = {0};
int datalen = 0;
uint8_t mac[8] = {0};
for(int n = mfFirstBlockOfSector(sectorNum); n < mfFirstBlockOfSector(sectorNum) + mfNumBlocksPerSector(sectorNum); n++) {
res = MFPReadBlock(&session, plain, n & 0xff, 1, false, true, data, sizeof(data), &datalen, mac);
if (res) {
PrintAndLog("Read error: %d", res);
DropField();
return res;
}
if (datalen && data[0] != 0x90) {
PrintAndLog("Card read error: %02x %s", data[0], mfpGetErrorDescription(data[0]));
DropField();
return 6;
}
if (datalen != 1 + 16 + 8 + 2) {
PrintAndLog("Error return length:%d", datalen);
DropField();
return 5;
}
PrintAndLog("data[%03d]: %s", n, sprint_hex(&data[1], 16));
if (memcmp(&data[1 + 16], mac, 8)) {
PrintAndLog("WARNING: mac on block %d not equal...", n);
PrintAndLog("MAC card: %s", sprint_hex(&data[1 + 16], 8));
PrintAndLog("MAC reader: %s", sprint_hex(mac, 8));
} else {
if(verbose)
PrintAndLog("MAC: %s", sprint_hex(&data[1 + 16], 8));
}
}
DropField();
return 0;
}
int CmdHFMFPWrbl(const char *cmd) {
uint8_t keyn[2] = {0};
uint8_t key[250] = {0};
int keylen = 0;
uint8_t datain[250] = {0};
int datainlen = 0;
CLIParserInit("hf mfp wrbl",
"Writes one block to Mifare Plus card.",
"Usage:\n\thf mfp wrbl 1 ff0000000000000000000000000000ff 000102030405060708090a0b0c0d0e0f -> writes block 1 data\n"
"\thf mfp wrbl 2 ff0000000000000000000000000000ff -v -> writes block 2 data with default key 0xFF..0xFF and some additional data\n");
void* argtable[] = {
arg_param_begin,
arg_lit0("vV", "verbose", "show internal data."),
arg_lit0("bB", "keyb", "use key B (by default keyA)."),
arg_int1(NULL, NULL, "<Block Num (0..255)>", NULL),
arg_str1(NULL, NULL, "<Data (HEX 16 bytes)>", NULL),
arg_str0(NULL, NULL, "<Key (HEX 16 bytes)>", NULL),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, false);
bool verbose = arg_get_lit(1);
bool keyB = arg_get_lit(2);
uint32_t blockNum = arg_get_int(3);
CLIGetHexWithReturn(4, datain, &datainlen);
CLIGetHexWithReturn(5, key, &keylen);
CLIParserFree();
mfpSetVerboseMode(verbose);
if (!keylen) {
memmove(key, DefaultKey, 16);
keylen = 16;
}
if (blockNum > 39) {
PrintAndLog("ERROR: <Block Num> must be in range [0..255] instead of: %d", blockNum);
return 1;
}
if (keylen != 16) {
PrintAndLog("ERROR: <Key> must be 16 bytes long instead of: %d", keylen);
return 1;
}
if (datainlen != 16) {
PrintAndLog("ERROR: <Data> must be 16 bytes long instead of: %d", datainlen);
return 1;
}
uint8_t sectorNum = mfSectorNum(blockNum & 0xff);
uint16_t uKeyNum = 0x4000 + sectorNum * 2 + (keyB ? 1 : 0);
keyn[0] = uKeyNum >> 8;
keyn[1] = uKeyNum & 0xff;
if (verbose)
PrintAndLog("--block:%d sector[%d]:%02x key:%04x", blockNum & 0xff, mfNumBlocksPerSector(sectorNum), sectorNum, uKeyNum);
mf4Session session;
int res = MifareAuth4(&session, keyn, key, true, true, verbose);
if (res) {
PrintAndLog("Authentication error: %d", res);
return res;
}
uint8_t data[250] = {0};
int datalen = 0;
uint8_t mac[8] = {0};
res = MFPWriteBlock(&session, blockNum & 0xff, datain, false, false, data, sizeof(data), &datalen, mac);
if (res) {
PrintAndLog("Write error: %d", res);
DropField();
return res;
}
if (datalen != 3 && (datalen != 3 + 8)) {
PrintAndLog("Error return length:%d", datalen);
DropField();
return 5;
}
if (datalen && data[0] != 0x90) {
PrintAndLog("Card write error: %02x %s", data[0], mfpGetErrorDescription(data[0]));
DropField();
return 6;
}
if (memcmp(&data[1], mac, 8)) {
PrintAndLog("WARNING: mac not equal...");
PrintAndLog("MAC card: %s", sprint_hex(&data[1], 8));
PrintAndLog("MAC reader: %s", sprint_hex(mac, 8));
} else {
if(verbose)
PrintAndLog("MAC: %s", sprint_hex(&data[1], 8));
}
DropField();
PrintAndLog("Write OK.");
return 0;
}
int CmdHFMFPMAD(const char *cmd) {
CLIParserInit("hf mfp mad",
"Checks and prints Mifare Application Directory (MAD)",
"Usage:\n\thf mfp mad -> shows MAD if exists\n"
"\thf mfp mad -a 03e1 -k d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7 -> shows NDEF data if exists\n");
void *argtable[] = {
arg_param_begin,
arg_lit0("vV", "verbose", "show technical data"),
arg_str0("aA", "aid", "print all sectors with aid", NULL),
arg_str0("kK", "key", "key for printing sectors", NULL),
arg_lit0("bB", "keyb", "use key B for access printing sectors (by default: key A)"),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool verbose = arg_get_lit(1);
uint8_t aid[2] = {0};
int aidlen;
CLIGetHexWithReturn(2, aid, &aidlen);
uint8_t key[16] = {0};
int keylen;
CLIGetHexWithReturn(3, key, &keylen);
bool keyB = arg_get_lit(4);
CLIParserFree();
if (aidlen != 2 && keylen > 0) {
PrintAndLogEx(WARNING, "do not need a key without aid.");
}
uint8_t sector0[16 * 4] = {0};
uint8_t sector10[16 * 4] = {0};
if (mfpReadSector(MF_MAD1_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector0, verbose)) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(ERR, "read sector 0 error. card don't have MAD or don't have MAD on default keys.");
return 2;
}
if (verbose) {
for (int i = 0; i < 4; i ++)
PrintAndLogEx(NORMAL, "[%d] %s", i, sprint_hex(&sector0[i * 16], 16));
}
bool haveMAD2 = false;
MAD1DecodeAndPrint(sector0, verbose, &haveMAD2);
if (haveMAD2) {
if (mfpReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector10, verbose)) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(ERR, "read sector 0x10 error. card don't have MAD or don't have MAD on default keys.");
return 2;
}
MAD2DecodeAndPrint(sector10, verbose);
}
if (aidlen == 2) {
uint16_t aaid = (aid[0] << 8) + aid[1];
PrintAndLogEx(NORMAL, "\n-------------- AID 0x%04x ---------------", aaid);
uint16_t mad[7 + 8 + 8 + 8 + 8] = {0};
size_t madlen = 0;
if (MADDecode(sector0, sector10, mad, &madlen)) {
PrintAndLogEx(ERR, "can't decode mad.");
return 10;
}
uint8_t akey[16] = {0};
memcpy(akey, g_mifarep_ndef_key, 16);
if (keylen == 16) {
memcpy(akey, key, 16);
}
for (int i = 0; i < madlen; i++) {
if (aaid == mad[i]) {
uint8_t vsector[16 * 4] = {0};
if (mfpReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, akey, vsector, false)) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(ERR, "read sector %d error.", i + 1);
return 2;
}
for (int j = 0; j < (verbose ? 4 : 3); j ++)
PrintAndLogEx(NORMAL, " [%03d] %s", (i + 1) * 4 + j, sprint_hex(&vsector[j * 16], 16));
}
}
}
return 0;
}
int CmdHFMFPNDEF(const char *cmd) {
CLIParserInit("hf mfp ndef",
"Prints NFC Data Exchange Format (NDEF)",
"Usage:\n\thf mfp ndef -> shows NDEF data\n"
"\thf mfp ndef -a 03e1 -k d3f7d3f7d3f7d3f7d3f7d3f7d3f7d3f7 -> shows NDEF data with custom AID and key\n");
void *argtable[] = {
arg_param_begin,
arg_litn("vV", "verbose", 0, 2, "show technical data"),
arg_str0("aA", "aid", "replace default aid for NDEF", NULL),
arg_str0("kK", "key", "replace default key for NDEF", NULL),
arg_lit0("bB", "keyb", "use key B for access sectors (by default: key A)"),
arg_param_end
};
CLIExecWithReturn(cmd, argtable, true);
bool verbose = arg_get_lit(1);
bool verbose2 = arg_get_lit(1) > 1;
uint8_t aid[2] = {0};
int aidlen;
CLIGetHexWithReturn(2, aid, &aidlen);
uint8_t key[16] = {0};
int keylen;
CLIGetHexWithReturn(3, key, &keylen);
bool keyB = arg_get_lit(4);
CLIParserFree();
uint16_t ndefAID = 0x03e1;
if (aidlen == 2)
ndefAID = (aid[0] << 8) + aid[1];
uint8_t ndefkey[16] = {0};
memcpy(ndefkey, g_mifarep_ndef_key, 16);
if (keylen == 16) {
memcpy(ndefkey, key, 16);
}
uint8_t sector0[16 * 4] = {0};
uint8_t sector10[16 * 4] = {0};
uint8_t data[4096] = {0};
int datalen = 0;
PrintAndLogEx(NORMAL, "");
if (mfpReadSector(MF_MAD1_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector0, verbose)) {
PrintAndLogEx(ERR, "read sector 0 error. card don't have MAD or don't have MAD on default keys.");
return 2;
}
bool haveMAD2 = false;
int res = MADCheck(sector0, NULL, verbose, &haveMAD2);
if (res) {
PrintAndLogEx(ERR, "MAD error %d.", res);
return res;
}
if (haveMAD2) {
if (mfpReadSector(MF_MAD2_SECTOR, MF_KEY_A, (uint8_t *)g_mifarep_mad_key, sector10, verbose)) {
PrintAndLogEx(ERR, "read sector 0x10 error. card don't have MAD or don't have MAD on default keys.");
return 2;
}
}
uint16_t mad[7 + 8 + 8 + 8 + 8] = {0};
size_t madlen = 0;
if (MADDecode(sector0, (haveMAD2 ? sector10 : NULL), mad, &madlen)) {
PrintAndLogEx(ERR, "can't decode mad.");
return 10;
}
printf("data reading:");
for (int i = 0; i < madlen; i++) {
if (ndefAID == mad[i]) {
uint8_t vsector[16 * 4] = {0};
if (mfpReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, ndefkey, vsector, false)) {
PrintAndLogEx(ERR, "read sector %d error.", i + 1);
return 2;
}
memcpy(&data[datalen], vsector, 16 * 3);
datalen += 16 * 3;
printf(".");
}
}
printf(" OK\n");
if (!datalen) {
PrintAndLogEx(ERR, "no NDEF data.");
return 11;
}
if (verbose2) {
PrintAndLogEx(NORMAL, "NDEF data:");
dump_buffer(data, datalen, stdout, 1);
}
NDEFDecodeAndPrint(data, datalen, verbose);
return 0;
}
static command_t CommandTable[] =
{
{"help", CmdHelp, 1, "This help"},
{"info", CmdHFMFPInfo, 0, "Info about Mifare Plus tag"},
{"wrp", CmdHFMFPWritePerso, 0, "Write Perso command"},
{"initp", CmdHFMFPInitPerso, 0, "Fills all the card's keys"},
{"commitp", CmdHFMFPCommitPerso, 0, "Move card to SL1 or SL3 mode"},
{"auth", CmdHFMFPAuth, 0, "Authentication"},
{"rdbl", CmdHFMFPRdbl, 0, "Read blocks"},
{"rdsc", CmdHFMFPRdsc, 0, "Read sectors"},
{"wrbl", CmdHFMFPWrbl, 0, "Write blocks"},
{"mad", CmdHFMFPMAD, 0, "Checks and prints MAD"},
{"ndef", CmdHFMFPNDEF, 0, "Prints NDEF records from card"},
{NULL, NULL, 0, NULL}
};
int CmdHFMFP(const char *Cmd) {
(void)WaitForResponseTimeout(CMD_ACK,NULL,100);
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

18
client/cmdhfmfp.h Normal file
View file

@ -0,0 +1,18 @@
//-----------------------------------------------------------------------------
// Copyright (C) 2018 Merlok
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
// High frequency MIFARE Plus commands
//-----------------------------------------------------------------------------
#ifndef CMDHFMFP_H__
#define CMDHFMFP_H__
#include "mifare/mifaredefault.h"
extern int CmdHFMFP(const char *Cmd);
#endif

1861
client/cmdhfmfu.c Normal file

File diff suppressed because it is too large Load diff

10
client/cmdhfmfu.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef CMDHFMFU_H__
#define CMDHFMFU_H__
#include <stdint.h>
extern int CmdHFMFUltra(const char *Cmd);
extern uint32_t GetHF14AMfU_Type(void);
extern int ul_print_type(uint32_t tagtype, uint8_t spacer);
#endif

Some files were not shown because too many files have changed in this diff Show more