support multiple fingers, expose winbio names

This commit is contained in:
Mary Strodl 2020-08-06 00:19:44 -04:00
parent d7906ce3a9
commit c4bb1ad040
No known key found for this signature in database
GPG key ID: 23B7FC1590D8E30E
3 changed files with 59 additions and 8 deletions

View file

@ -24,6 +24,7 @@ from validitysensor.usb import usb
from validitysensor.sid import sid_from_string
from validitysensor.db import subtype_to_string, db
from validitysensor.sensor import sensor, reboot, RebootException
from validitysensor.winbio_constants import finger_ids
GLib.threads_init()
@ -129,6 +130,13 @@ class Device(dbus.service.Object):
logging.debug('In EnrollStart %s for %s' % (finger_name, user))
pw=pwd.getpwnam(user)
uid=pw.pw_uid
# 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
def update_cb(rsp, e):
if e is not None:
self.EnrollStatus('enroll-retry-scan', False)
@ -137,7 +145,7 @@ class Device(dbus.service.Object):
def run():
try:
sensor.enroll(uid2identity(uid), 0xf5, update_cb) # TODO parse the finger name
sensor.enroll(uid2identity(uid), index, update_cb)
self.EnrollStatus('enroll-completed', True)
except usb_core.USBError as e:
logging.exception(e)
@ -147,9 +155,17 @@ class Device(dbus.service.Object):
logging.exception(e)
self.EnrollStatus('enroll-failed', True)
thread = Thread(target=run)
thread.daemon = True
thread.start()
index = finger_ids.get(winbio_name, None)
if index == None:
logging.error(
'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')

View file

@ -8,6 +8,7 @@ from binascii import hexlify, unhexlify
from .blobs import db_write_enable
from .flash import call_cleanups
from .sid import *
from .winbio_constants import finger_names, finger_ids
class UserStorage():
def __init__(self, dbid, name):
@ -28,10 +29,8 @@ class User():
return '<User: dbid=%04x identity=%s fingers=%s>' % (self.dbid, repr(self.identity), repr(self.fingers))
def subtype_to_string(s):
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])

View 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