Merge pull request #23 from Mstrodl/feature/winbio-data
Support multiple fingers on DBus service
This commit is contained in:
commit
e003dbeb1a
3 changed files with 58 additions and 8 deletions
|
|
@ -29,6 +29,7 @@ from validitysensor.usb import usb
|
|||
from validitysensor.sid import sid_from_string
|
||||
from validitysensor.db import subtype_to_string, db, SidIdentity, User
|
||||
from validitysensor.sensor import sensor, RebootException
|
||||
from validitysensor.winbio_constants import finger_ids
|
||||
|
||||
GLib.threads_init()
|
||||
|
||||
|
|
@ -141,7 +142,14 @@ class Device(dbus.service.Object):
|
|||
def EnrollStart(self, user, finger_name):
|
||||
logging.debug('In EnrollStart %s for %s' % (finger_name, user))
|
||||
|
||||
# left-ring-finger => LH
|
||||
hand = 'LH' if finger_name[0] == 'l' else 'RH'
|
||||
# left-ring-finger => RING_FINGER
|
||||
generic_finger = '_'.join(finger_name.split('-')[1:]).upper()
|
||||
winbio_name = 'WINBIO_ANSI_381_POS_' + hand + '_' + generic_finger
|
||||
|
||||
usr = self.user2identity(user)
|
||||
index = finger_ids.get(winbio_name, None)
|
||||
|
||||
def update_cb(rsp, e):
|
||||
if e is not None:
|
||||
|
|
@ -151,7 +159,7 @@ class Device(dbus.service.Object):
|
|||
|
||||
def run():
|
||||
try:
|
||||
sensor.enroll(usr, 0xf5, update_cb) # TODO parse the finger name
|
||||
sensor.enroll(usr, index, update_cb)
|
||||
self.EnrollStatus('enroll-completed', True)
|
||||
except usb_core.USBError as e:
|
||||
logging.exception(e)
|
||||
|
|
@ -161,9 +169,16 @@ class Device(dbus.service.Object):
|
|||
logging.exception(e)
|
||||
self.EnrollStatus('enroll-failed', True)
|
||||
|
||||
thread = Thread(target=run)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
if index == None:
|
||||
logging.exception(
|
||||
'Unknown finger name passed to enroll? ' +
|
||||
finger_name + ' (' + winbio_name + ')'
|
||||
)
|
||||
self.EnrollStatus('enroll-failed', True)
|
||||
else:
|
||||
thread = Thread(target=run)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
@dbus.service.signal(dbus_interface=INTERFACE_NAME, signature='sb')
|
||||
def VerifyStatus(self, result, done):
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from binascii import hexlify
|
|||
from .blobs import db_write_enable
|
||||
from .flash import call_cleanups
|
||||
from .sid import *
|
||||
from .winbio_constants import finger_names
|
||||
|
||||
class UserStorage():
|
||||
def __init__(self, dbid, name):
|
||||
|
|
@ -26,10 +27,8 @@ class User():
|
|||
return '<User: dbid=%04x identity=%s fingers=%s>' % (self.dbid, repr(self.identity), repr(self.fingers))
|
||||
|
||||
def subtype_to_string(s: int):
|
||||
if s < 0xf5 or s > 0xfe:
|
||||
return 'Unknown'
|
||||
|
||||
return 'WINBIO_FINGER_UNSPECIFIED_POS_%02d' % (s - 0xf5 + 1)
|
||||
finger_name = finger_names.get(s, None)
|
||||
return finger_name or 'Unknown'
|
||||
|
||||
def parse_user_storage(rsp):
|
||||
rc, = unpack('<H', rsp[:2])
|
||||
|
|
|
|||
36
validitysensor/winbio_constants.py
Normal file
36
validitysensor/winbio_constants.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
finger_ids = {
|
||||
# https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.16299.0/shared/winbio_types.h#L864-L878
|
||||
"WINBIO_ANSI_381_POS_UNKNOWN": 0,
|
||||
"WINBIO_ANSI_381_POS_RH_THUMB": 1,
|
||||
"WINBIO_ANSI_381_POS_RH_INDEX_FINGER": 2,
|
||||
"WINBIO_ANSI_381_POS_RH_MIDDLE_FINGER": 3,
|
||||
"WINBIO_ANSI_381_POS_RH_RING_FINGER": 4,
|
||||
"WINBIO_ANSI_381_POS_RH_LITTLE_FINGER": 5,
|
||||
"WINBIO_ANSI_381_POS_LH_THUMB": 6,
|
||||
"WINBIO_ANSI_381_POS_LH_INDEX_FINGER": 7,
|
||||
"WINBIO_ANSI_381_POS_LH_MIDDLE_FINGER": 8,
|
||||
"WINBIO_ANSI_381_POS_LH_RING_FINGER": 9,
|
||||
"WINBIO_ANSI_381_POS_LH_LITTLE_FINGER": 10,
|
||||
|
||||
"WINBIO_ANSI_381_POS_RH_FOUR_FINGERS": 13,
|
||||
"WINBIO_ANSI_381_POS_LH_FOUR_FINGERS": 14,
|
||||
"WINBIO_ANSI_381_POS_TWO_THUMBS": 15,
|
||||
|
||||
|
||||
# https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.16299.0/shared/winbio_types.h#L920-L929
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_01": 0xf5,
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_02": 0xf6,
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_03": 0xf7,
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_04": 0xf8,
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_05": 0xf9,
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_06": 0xfa,
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_07": 0xfb,
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_08": 0xfc,
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_09": 0xfd,
|
||||
"WINBIO_FINGER_UNSPECIFIED_POS_10": 0xfe
|
||||
}
|
||||
|
||||
# Store the keys in the reverse order for faster lookups
|
||||
finger_names = {}
|
||||
for name, index in finger_ids.items():
|
||||
finger_names[index] = name
|
||||
Loading…
Reference in a new issue