mirror of
https://github.com/RfidResearchGroup/ChameleonMini.git
synced 2026-05-12 11:20:37 -07:00
Decode sniffing data with parityBit in Python Software
If parity bit check failed, ! is appended to the data and raw data is diaplayed Currently Software layer parity bit check and removal is only enabled in sniffing mode (cherry picked from commit 2cfd54a)
This commit is contained in:
@@ -2,6 +2,40 @@
|
||||
|
||||
import struct
|
||||
import binascii
|
||||
import math
|
||||
|
||||
def checkParityBit(data):
|
||||
byteCount = len(data)
|
||||
# Short frame, no parityBit
|
||||
if (byteCount == 1):
|
||||
return (True, data)
|
||||
|
||||
# 9 bit is a group, validate bit count is calculated below
|
||||
bitCount = int((byteCount*8)/9) * 9
|
||||
parsedData = bytearray(int(bitCount/9))
|
||||
|
||||
oneCounter = 0 # Counter for count ones in a byte
|
||||
for i in range(0, bitCount):
|
||||
# Get bit i in data
|
||||
byteIndex = math.floor(i/8)
|
||||
bitIndex = i % 8
|
||||
bit = (data[byteIndex] >> bitIndex) & 0x01
|
||||
|
||||
# Check parityBit
|
||||
# Current bit is parityBit
|
||||
if(i % 9 == 8):
|
||||
# Even number of ones in current byte
|
||||
if(oneCounter % 2 and bit == 1):
|
||||
return (False, data)
|
||||
# Odd number of ones in current byte
|
||||
elif((not oneCounter % 2) and bit == 0):
|
||||
return (False, data)
|
||||
oneCounter = 0
|
||||
# Current bit is normal bit
|
||||
else:
|
||||
oneCounter += bit
|
||||
parsedData[int(i/9)] |= bit << (i%9)
|
||||
return (True, parsedData)
|
||||
|
||||
def noDecoder(data):
|
||||
return ""
|
||||
@@ -12,6 +46,13 @@ def textDecoder(data):
|
||||
def binaryDecoder(data):
|
||||
return binascii.hexlify(data).decode()
|
||||
|
||||
def binaryParityDecoder(data):
|
||||
isValid, checkedData = checkParityBit(data)
|
||||
if(isValid):
|
||||
return binascii.hexlify(checkedData).decode()
|
||||
else:
|
||||
return binascii.hexlify(checkedData).decode()+"!"
|
||||
|
||||
eventTypes = {
|
||||
0x00: { 'name': 'EMPTY', 'decoder': noDecoder },
|
||||
0x10: { 'name': 'GENERIC', 'decoder': textDecoder },
|
||||
@@ -25,6 +66,12 @@ eventTypes = {
|
||||
0x42: { 'name': 'CODEC RX W/PARITY', 'decoder': binaryDecoder },
|
||||
0x43: { 'name': 'CODEC TX W/PARITY', 'decoder': binaryDecoder },
|
||||
|
||||
0x44: { 'name': 'CODEC RX SNI READER', 'decoder': binaryDecoder },
|
||||
0x45: { 'name': 'CODEC RX SNI READER W/PARITY', 'decoder': binaryParityDecoder },
|
||||
0x46: { 'name': 'CODEC RX SNI CARD', 'decoder': binaryDecoder },
|
||||
0x47: { 'name': 'CODEC RX SNI CARD W/PARITY', 'decoder': binaryParityDecoder },
|
||||
|
||||
|
||||
0x80: { 'name': 'APP READ', 'decoder': binaryDecoder },
|
||||
0x81: { 'name': 'APP WRITE', 'decoder': binaryDecoder },
|
||||
0x84: { 'name': 'APP INC', 'decoder': binaryDecoder },
|
||||
|
||||
@@ -58,6 +58,7 @@ def main():
|
||||
else:
|
||||
verboseFunc = None
|
||||
|
||||
print("\nNote: If parityBit check failed, '!' is appended to the decoded data and raw data with parity bit is displayed.\n")
|
||||
if (args.live):
|
||||
# Live logging mode
|
||||
if (args.port is not None):
|
||||
|
||||
Reference in New Issue
Block a user