Ver Fonte

Merge branch 'release' of https://tree.clementinecomputing.com/clementinecomputing/popufare into release

clementinecomputing há 5 anos atrás
pai
commit
6e659520cc

+ 102 - 19
busunit-PIU/scripts/capture-mag-hid

@@ -21,6 +21,8 @@
 import os, sys, evdev, asyncio, os.path
 from evdev import InputDevice, categorize, ecodes
 
+VERBOSE_LEVEL = 0
+
 dev_init = False
 dev = { }
 
@@ -30,6 +32,60 @@ evfns_n = 13
 evfns_bd = "/dev/input/"
 evfns = [ ]
 
+ecode_map = {
+  ecodes.KEY_1 : { "code": 2, "ascii": "1", "shift":"!"},       ecodes.KEY_2 : { "code": 3, "ascii": "2", "shift":"@"},
+  ecodes.KEY_3 : { "code": 4, "ascii": "3", "shift":"#"},       ecodes.KEY_4 : { "code": 5, "ascii": "4", "shift":"$"},
+  ecodes.KEY_5 : { "code": 6, "ascii": "5", "shift":"%"},       ecodes.KEY_6 : { "code": 7, "ascii": "6", "shift": "^"},
+  ecodes.KEY_7 : { "code": 8, "ascii": "7", "shift":"&"},       ecodes.KEY_8 : { "code": 9, "ascii": "8", "shift":"*"},
+  ecodes.KEY_9 : { "code": 10, "ascii": "9", "shift":"("},      ecodes.KEY_0 : { "code": 11, "ascii": "0", "shift":")"},
+  ecodes.KEY_MINUS : { "code": 12, "ascii": "-", "shift":"_"},  ecodes.KEY_EQUAL : { "code": 13, "ascii": "=", "shift":"+"},
+  ecodes.KEY_BACKSPACE : { "code": 14, "ascii": "", "shift":""},ecodes.KEY_TAB : { "code": 15, "ascii": "\t"},
+  ecodes.KEY_Q : { "code": 16, "ascii": "q", "shift":"Q"},      ecodes.KEY_W : { "code": 17, "ascii": "w", "shift":"W"},
+  ecodes.KEY_E : { "code": 18, "ascii": "e", "shift":"E"},      ecodes.KEY_R : { "code": 19, "ascii": "r", "shift":"R"},
+  ecodes.KEY_T : { "code": 20, "ascii": "t", "shift":"T"},      ecodes.KEY_Y : { "code": 21, "ascii": "y", "shift":"Y"},
+  ecodes.KEY_U : { "code": 22, "ascii": "u", "shift":"U"},      ecodes.KEY_I : { "code": 23, "ascii": "i", "shift":"I"},
+  ecodes.KEY_O : { "code": 24, "ascii": "o", "shift":"O"},      ecodes.KEY_P : { "code": 25, "ascii": "p", "shift":"P"},
+  ecodes.KEY_LEFTBRACE : { "code": 26, "ascii": "[", "shift":"{"}, ecodes.KEY_RIGHTBRACE : { "code": 27, "ascii": "]", "shift":"}"},
+  ecodes.KEY_ENTER : { "code": 28, "ascii": "\n", "shift":""},  ecodes.KEY_A : { "code": 30, "ascii": "a", "shift":"A"},
+  ecodes.KEY_S : { "code": 31, "ascii": "s", "shift":"S"},      ecodes.KEY_D : { "code": 32, "ascii": "d", "shift":"D"},
+  ecodes.KEY_F : { "code": 33, "ascii": "f", "shift":"F"},      ecodes.KEY_G : { "code": 34, "ascii": "g", "shift":"G"},
+  ecodes.KEY_H : { "code": 35, "ascii": "h", "shift":"H"},      ecodes.KEY_J : { "code": 36, "ascii": "j", "shift":"J"},
+  ecodes.KEY_K : { "code": 37, "ascii": "k", "shift":"K"},      ecodes.KEY_L : { "code": 38, "ascii": "l", "shift":"L"},
+  ecodes.KEY_SEMICOLON : { "code": 39, "ascii": ";", "shift":":"}, ecodes.KEY_APOSTROPHE : { "code": 40, "ascii": "'", "shift":'"'},
+  ecodes.KEY_BACKSLASH : { "code": 43, "ascii": "\\", "shift":"|"}, ecodes.KEY_Z : { "code": 44, "ascii": "z", "shift":"Z"},
+  ecodes.KEY_X : { "code": 45, "ascii": "x", "shift":"X"},      ecodes.KEY_C : { "code": 46, "ascii": "c", "shift":"C"},
+  ecodes.KEY_V : { "code": 47, "ascii": "v", "shift":"V"},      ecodes.KEY_B : { "code": 48, "ascii": "b", "shift":"B"},
+  ecodes.KEY_N : { "code": 49, "ascii": "n", "shift":"N"},      ecodes.KEY_M : { "code": 50, "ascii": "m", "shift":"M"},
+  ecodes.KEY_COMMA : { "code": 51, "ascii": ",", "shift":"<"},  ecodes.KEY_DOT : { "code": 52, "ascii": ".", "shift":">"},
+  ecodes.KEY_SLASH : { "code": 53, "ascii": "/", "shift":"?"},  ecodes.KEY_KPASTERISK : { "code": 55, "ascii": "*"},
+  ecodes.KEY_SPACE : { "code": 57, "ascii": " "},               ecodes.KEY_KP7 : { "code": 71, "ascii": "7"},
+  ecodes.KEY_KP8 : { "code": 72, "ascii": "8"},                 ecodes.KEY_KP9 : { "code": 73, "ascii": "9"},
+  ecodes.KEY_KPMINUS : { "code": 74, "ascii": "-"},             ecodes.KEY_KP4 : { "code": 75, "ascii": "4"},
+  ecodes.KEY_KP5 : { "code": 76, "ascii": "5"},                 ecodes.KEY_KP6 : { "code": 77, "ascii": "6"},
+  ecodes.KEY_KPPLUS : { "code": 78, "ascii": "+"},              ecodes.KEY_KP1 : { "code": 79, "ascii": "1"},
+  ecodes.KEY_KP2 : { "code": 80, "ascii": "2"},                 ecodes.KEY_KP3 : { "code": 81, "ascii": "3"},
+  ecodes.KEY_KP0 : { "code": 82, "ascii": "0"},                 ecodes.KEY_KPDOT : { "code": 83, "ascii": "."},
+  ecodes.KEY_KPENTER : { "code": 96, "ascii": "\n"},            ecodes.KEY_LINEFEED : { "code": 101, "ascii": "\r"},
+  ecodes.KEY_DELETE : { "code": 111, "ascii": ""}
+}
+
+
+def code_ascii_map(code, shift):
+  shift_down = False
+  if (shift[ecodes.KEY_RIGHTSHIFT] > 0) or (shift[ecodes.KEY_LEFTSHIFT] > 0):
+    shift_down = True
+
+  #print("###", code, shift, code in ecode_map)
+
+  if code in ecode_map:
+    if "shift" not in ecode_map[code]:
+      return ecode_map[code]["ascii"]
+    if shift_down:
+      return ecode_map[code]["shift"]
+    return ecode_map[code]["ascii"]
+
+  return ""
+
 for x in range(evfns_n):
   fn = evfns_bd + "event" + str(x)
   if (os.path.exists(fn)):
@@ -37,35 +93,62 @@ for x in range(evfns_n):
 
 for evfn in evfns:
   _dev = evdev.InputDevice(evfn)
-  print("device:", _dev.name)
+  if VERBOSE_LEVEL >= 2: print("## device:", _dev.name)
   if _dev.name == HID_NAME:
     dev_init = True
     dev = _dev
     break
 
 if not dev_init:
-  print("could not find device, exiting")
-  sys.exit(0)
+  sys.stderr.write("ERROR: could not find device, exiting\n")
+  sys.exit(-1)
 
-print(dev)
-print(dev.capabilities())
-print(dev.capabilities(verbose=True))
+if VERBOSE_LEVEL >= 2:
+  print("##", dev)
+  print("##", dev.capabilities())
+  print("##", dev.capabilities(verbose=True))
+  sys.stdout.flush()
 
 dev.grab()
 
+kb_shift_state = {
+  ecodes.KEY_RIGHTSHIFT: 0,
+  ecodes.KEY_LEFTSHIFT: 0
+}
+buf = ""
 for event in dev.read_loop():
   if event.type == ecodes.EV_KEY:
-    print(categorize(event))
-
-sys.exit(0)
-
-
-async def print_events(device):
-  async for event in device.async_read_loop():
-    print(device.path, evdev.categorize(event, sep=':'))
 
-for device in dev:
-  asyncio.ensure_future(print_events(dev))
-
-
-print("...")
+    if event.code == ecodes.KEY_RIGHTSHIFT:
+      kb_shift_state[ecodes.KEY_RIGHTSHIFT] = event.value
+
+    elif event.code == ecodes.KEY_LEFTSHIFT:
+      kb_shift_state[ecodes.KEY_LEFTSHIFT] = event.value
+
+    if VERBOSE_LEVEL>=2:
+      print("##", event.type, event.code, event.value, categorize(event))
+      print("##", kb_shift_state)
+      sys.stdout.flush()
+
+    # 'down'
+    #
+    if (event.value == 1):
+      ch = code_ascii_map(event.code, kb_shift_state)
+
+      if (ch == '\n'):
+        print(buf)
+        sys.stdout.flush()
+        buf = ""
+      else:
+        buf += ch
+
+#sys.exit(0)
+#async def print_events(device):
+#  async for event in device.async_read_loop():
+#    print(device.path, evdev.categorize(event, sep=':'))
+#
+#for device in dev:
+#  asyncio.ensure_future(print_events(dev))
+#
+#
+#print("...")

+ 9 - 12
busunit-PIU/scripts/proxmark3-lf-hid-read.lua

@@ -17,6 +17,11 @@
 -- along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
 --
 
+-- example usage:
+--
+-- stdbuf -eL -oL ./proxmark3 /dev/ttyACM0 -l lf-hid-read.lua | tee lf-hid-read.log
+--
+
 local cmds = require('commands')
 local getopt = require('getopt')
 local bin = require('bin')
@@ -25,23 +30,15 @@ local format=string.format
 local floor=math.floor
 local os = require("os")
 
-function sleep (a) 
-    local sec = tonumber(os.clock() + a); 
-    while (os.clock() < sec) do 
-    end 
-end
-
 local function main(args)
-  print( string.rep('--',30) )
-  print( string.rep('--',30) )
+  print( string.rep('#',30) )
+  print( string.rep('#',30) )
 
   -- core.console will go async when waiting for the proxmark to return
   -- so need to wait for a response (sleep)
+  --
   core.console('lf hid read')
-  -- sleep(30) -- run for 30 seconds
-  os.execute("sleep 30")
+  os.execute("sleep infinity")
   
-  print( string.rep('--',30) )
-
 end
 main(args)

+ 10 - 4
busunit-PIU/scripts/setup-system

@@ -64,9 +64,10 @@ apt-get install -y jq
 useradd bus
 
 mkdir -p git
-
 pushd git
 
+  git clone https://tree.clementinecomputing.com/clementinecomputing/popufare
+
   git clone https://github.com/proxmark/proxmark3.git
   pushd proxmark3
     git pull
@@ -89,9 +90,14 @@ pushd git
 popd
 
 
+# setup `proxmark3` client program state
+#
+mkdir -p /home/bus/bin
 
+cp /root/git/proxmark3/client/proxmark3 /home/bus/bin
+cp -R /root/git/proxmark3/client/lualibs /home/bus/bin/
+cp -R /root/git/proxmark3/client/scripts /home/bus/bin/
+cp /root/git/popufare/busunit-PIU/scripts/proxmark3-lf-hid-read.lua /home/bus/bin/scripts
 
-
-
-
+chown -R bus:bus /home/bus
 

+ 8 - 0
experiment/production/PIU-Notes.md

@@ -242,6 +242,14 @@ Note that the `HID_NAME` is specific to the USB magstripe reader I had on hand.
 Multiple of the same could be attached and would need to be differentiated by the `/dev/input/event*` endpoints.
 
 
+---
+
+I'm still playing around with a policy on the USB magstripe reader use but there are a few things of note:
+
+* [disabling USB inputs through udev](https://incenp.org/notes/2014/disable-new-usb-input-devices.html)
+* Getting errors on startup of the form "couldn't find an input interrupt endpoint" [SO: usbhid can't find input interrupt endpoint](https://unix.stackexchange.com/questions/116615/usbhid-cant-find-input-interrupt-endpoint)
+
+
 
 Display
 ---