Skip to content

Instantly share code, notes, and snippets.

@bosb
Last active January 4, 2019 22:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bosb/8124a4a8274f64ac90b14cb213e1cdd5 to your computer and use it in GitHub Desktop.
Save bosb/8124a4a8274f64ac90b14cb213e1cdd5 to your computer and use it in GitHub Desktop.
Step through all possible modulations/configurations for ISO/IEC 15693 with CR95HF-VMD5T from STMicroelectronics discovery kit M24LR-DISCOVERY used command: Inventory
#!/usr/local/bin/python
# Author: Thorsten Bosbach 09/2018
# Step through all possible modulations/configurations for ISO/IEC 15693 with CR95HF-VMD5T from STMicroelectronics discovery kit M24LR-DISCOVERY
# Used command: Inventory
# Never forget, to read after every write, else strange looking results ;-) !
import hid
import time
import sys
import numpy
# Looks like there is some timing involved to get repeatable reliable result
sleepy = 0.02
# To check reliability, how often should each command get executed in a row - I would expect each time of this same result
repeat = 1
# Read from CR95HF and print as hex, if no error
def print_read(h):
count = 0
for n in range(0, 1):
time.sleep(0.3)
d = h.read(64)
new_str = ""
for i in range(0, d[2]+3):
new_str += "%02x " % d[i]
# 0x80: no error; last byte 0x00: CRC ok
if d[1] == 0x80 and d[d[2]+2] == 0x00:
#if d[1] == 0x80:
print new_str
count += 1
else:
print "**"
return count
# connect to reader
h = hid.device()
h.open(0x0483, 0xd0d0)
# use command to verify connection without tag available
h.write([0x02, 0xbc])
print_read(h)
# Possible modes as reader, from datasheet cr95hf.pdf DocID018669 Rev 12 page 21 Table 12
# bits
# 5:4: 00: 26 Kbps (H) 01: 52 Kbps 10: 6 Kbps (L) 11: RFU
# 3: 0: Respect 312-us delay 1: Wait for SOF (1)
# 2: 0: 100% modulation (100) 1: 10% modulation (10)
# 1: 0: Single subcarrier (S) 1: Dual subcarrier (D)
# 0: Append CRC if set to 1. (1)
# As a table, list of combinations, most important to me is speed and subcarrier
# 8 4 2 1
# Kbps SOF Modulation Subcarrier Append_CRC : Hex
# 10 0 0 0 1 : 0x21
# l 0 0 1 1 : 0x23
# 01 0 0 0 1 : 0x11
# x 0 0 1 1 : 0x13
# 00 0 0 0 1 : 0x01
# h 0 0 1 1 : 0x03
# Always let the CRC calculated by reader
# Inner array with these base values
reader = [0x03, 0x01, 0x13, 0x11, 0x23, 0x21]
# Outer array to switch: Respect 312-us delay + 100% modulation, Wait for SOF + 100% modulation, Respect 312-us delay + 10% modulation, Wait for SOF + 10% modulation
addition = [0x00, 0x08, 0x04, 0x0c]
# ISO command request flag combinations for speed and subcarrier ISO-15693-3.pdf 7.3.1 Request flags
# bits 1-4:
# Sub-carrier Data_rate
# 0x04: single low
# 0x06: single high
# 0x05: dual low
# 0x07: dual high
# bits 5-8: 0x20 1 slot
token = [0x24, 0x26, 0x25, 0x27]
# array big enough to count successfull recievements
# token, reader, addition
result_array = numpy.zeros((0x28,0x24,0x0e))
# Outer loop
for a in addition:
print "+++" + "%02x" % a + "+++++++++++++++++++++++++++++"
# Inner loop
for r in reader:
# Set reader configuration
h.write([0x01, 0x02, 0x02, 0x01, r+a])
print_read(h)
print "---" + "%02x" % r + '----------------------------'
for t in token:
for i in range(0, repeat):
time.sleep(sleepy)
# inventory command
h.write([0x01, 0x04, 0x03, t, 0x01, 0x00])
time.sleep(sleepy)
sys.stdout.write("0x%02x " % t)
result_array[t][r][a] += print_read(h)
# reader field off
h.write([0x01, 0x02, 0x02, 0x00, 0x00])
print_read(h)
# Switch reader field off
h.write([0x01, 0x02, 0x02, 0x00, 0x00])
print_read(h)
h.close()
# print summary - see upcoming blog entry for theory behind this :-) and how it came to this....
sys.stdout.write(' ')
for a in addition:
sys.stdout.write("%x" % a)
print '-'
sys.stdout.write(' ')
for r in reader:
sys.stdout.write("0x%02x|" % r)
print '-'
for t in token:
sys.stdout.write("0x%02x: " % t)
for r in reader:
for a in addition:
if result_array[t][r][a] == 0:
sys.stdout.write(' ')
else:
sys.stdout.write(str(int(result_array[t][r][a])))
sys.stdout.write('|')
print '-'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment