iafilatov / libfprint

libfrpint driver for a family of Elantech fingerprint sensors
https://cgit.freedesktop.org/libfprint/libfprint/
GNU Lesser General Public License v2.1
146 stars 20 forks source link

Add Elan driver #1

Closed iafilatov closed 6 years ago

iafilatov commented 6 years ago

@anarsoul Sorry to bother you but could you please take another look at this?

anarsoul commented 6 years ago

Sure

anarsoul commented 6 years ago

Mostly looks OK. See 2 minor comments above. Please squash all your commits into a single commit and verify that it works fine with fprint_demo [1] for all the operations (enroll and verify) after you cancel a scan.

[1] https://www.freedesktop.org/wiki/Software/fprint/fprint_demo/

iafilatov commented 6 years ago

Squashed. Verified that fprintd_demo works after a scan has been canceled. I've been using this driver for about month now and haven't seen any problems (the biggest issue is that it needs a rather steady swipe because otherwise scans are bad).

iafilatov commented 6 years ago

Ok, so I went back to an older commit to answer the question about why I needed to wait for events there. Here's fprintd-verify with fp_handle_events_timeout():

Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_imgdev_image_captured]
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_img_detect_minutiae] minutiae scan completed in 0.027080 secs
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_img_detect_minutiae] detected 74 minutiae
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [print_data_new] driver=15 devtype=0000
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_img_compare_print_data] score 18
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_img_compare_print_data] score 12
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_img_compare_print_data] score 6
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_img_compare_print_data] score 5
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_img_compare_print_data] score 25
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [elan_set_finger_present]
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_imgdev_report_finger_status] finger removed
Dec  3 22:41:27 melchior fprintd[14919]: async:debug [fpi_drvcb_report_verify_result] result 1
Dec  3 22:41:27 melchior fprintd[14919]: ** Message: verify_cb: result verify-match (1)
Dec  3 22:41:27 melchior fprintd[14919]: drv:debug [__ssm_call_handler] 0x23f4070 entering state 5
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [elan_set_finger_present]
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [elan_run_cmds]
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [elan_run_next_cmd]
Dec  3 22:41:27 melchior fprintd[14919]: async:debug [fp_async_verify_stop]
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [dev_deactivate]
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [elan_cmd_cb]
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [elan_cmd_done]
Dec  3 22:41:27 melchior fprintd[14919]: drv:debug [fpi_ssm_mark_completed] 0x23f4070 completed with status 0
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [capture_complete]
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [elan_deactivate]
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [elan_dev_reset]
Dec  3 22:41:27 melchior fprintd[14919]: fp:debug [fpi_imgdev_deactivate_complete]
Dec  3 22:41:27 melchior fprintd[14919]: async:debug [fpi_drvcb_verify_stopped]
Dec  3 22:41:27 melchior fprintd[14919]: elan:debug [dev_deinit]
Dec  3 22:41:27 melchior fprintd[14919]: async:debug [fpi_drvcb_close_complete]
Dec  3 22:41:27 melchior fprintd[14919]: ** Message: no longer monitoring fd 14
Dec  3 22:41:27 melchior fprintd[14919]: ** Message: released device 0

Here's the same with fp_handle_events_timeout() commented out:

Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [fpi_imgdev_image_captured]
Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [fpi_img_detect_minutiae] minutiae scan completed in 0.018527 secs
Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [fpi_img_detect_minutiae] detected 46 minutiae
Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [print_data_new] driver=15 devtype=0000
Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [fpi_img_compare_print_data] score 12
Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [fpi_img_compare_print_data] score 7
Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [fpi_img_compare_print_data] score 25
Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [fpi_img_compare_print_data] score 8
Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [fpi_img_compare_print_data] score 21
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_set_finger_present]
Dec  3 22:39:33 melchior fprintd[14025]: fp:debug [fpi_imgdev_report_finger_status] finger removed
Dec  3 22:39:33 melchior fprintd[14025]: async:debug [fpi_drvcb_report_verify_result] result 1
Dec  3 22:39:33 melchior fprintd[14025]: ** Message: verify_cb: result verify-match (1)
Dec  3 22:39:33 melchior fprintd[14025]: drv:debug [__ssm_call_handler] 0xe05430 entering state 5
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_set_finger_present]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_run_cmds]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_run_next_cmd]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_cmd_cb]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_cmd_done]
Dec  3 22:39:33 melchior fprintd[14025]: drv:debug [fpi_ssm_mark_completed] 0xe05430 completed with status 0
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [capture_complete]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_capture]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_dev_reset]
Dec  3 22:39:33 melchior fprintd[14025]: drv:debug [__ssm_call_handler] 0xdc8a40 entering state 0
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_run_cmds]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_run_next_cmd]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_cmd_cb]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_cmd_done]
Dec  3 22:39:33 melchior fprintd[14025]: drv:debug [__ssm_call_handler] 0xdc8a40 entering state 1
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_run_cmds]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_run_next_cmd]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_cmd_cb]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [elan_cmd_read]
Dec  3 22:39:33 melchior fprintd[14025]: async:debug [fp_async_verify_stop]
Dec  3 22:39:33 melchior fprintd[14025]: elan:debug [dev_deactivate]
====> hangs here until I swipe my finger again or the read times out
Dec  3 22:39:43 melchior fprintd[14025]: elan:debug [elan_dev_reset]
Dec  3 22:39:43 melchior fprintd[14025]: fp:debug [fpi_imgdev_deactivate_complete]
Dec  3 22:39:43 melchior fprintd[14025]: async:debug [fpi_drvcb_verify_stopped]
Dec  3 22:39:43 melchior fprintd[14025]: async:error [fpi_drvcb_verify_stopped] BUG at async.c:275
Dec  3 22:39:43 melchior fprintd[14025]: elan:debug [dev_deinit]
Dec  3 22:39:43 melchior fprintd[14025]: async:debug [fpi_drvcb_close_complete]
Dec  3 22:39:43 melchior fprintd[14025]: ** Message: no longer monitoring fd 14
Dec  3 22:39:43 melchior fprintd[14025]: ** Message: released device 0

It appeared that an additional call to handle events was needed to make sure the lib calls dev_deactivate before another capture sequence starts. And it started right after the previous capture ended because that's what's needed for enroll (and that's what I saw other drivers do).

After I changed the driver to schedule another capture instead of calling it directly, it became unnecessary to handle events explicitly. I'm not sure but I think this is because the sequence of activate -> calibrate -> capture now returns to the caller instead of going capture -> capture -> capture -> ...

It would benefit driver developers if they knew better what the lib will call at each stage and what's expected of the drivers. It's not that easy to understand just by looking at other drivers. For ex. I kinda understand that the driver's "activate" subroutine will be called and it should end with the driver submitting an image. But it it necessary to report finger status? How to report errors properly? And so on. I'd write a memo but TBH even having implemented a driver I don't understand everything completely.

BTW, should I write a "Driver quality" page as well?

anarsoul commented 6 years ago

Yeah, that's true that libfprint lacks documentation for driver developers. I have no plans to address it currently, so it would be really nice if you want to jump in and write it.

As for 'Driver quality' page - it's up to you. It would be nice if you write one, but it's not a strong requirement, since wiki seems to be outdated anyway.

anarsoul commented 6 years ago

Merged into fd.o master: https://cgit.freedesktop.org/libfprint/libfprint/commit/?id=cfe60c0640e445d4bf0af25482f5187a89bc643b

iafilatov commented 6 years ago

Thanks!

caxerx commented 6 years ago

is there any way to work with device number 0x903 reader?

iafilatov commented 6 years ago

I have usb dumps of 0903 but I can't promise anything now as I don't have that much time right now. From what I can tell, there are 2 main problems:

  1. The images are dark and could require post-processing.
  2. The sensor is square. And because the scanned area is small, we'd have to stitch a couple of them to get more minutiae. But since they are square, the orientation is unknown. The same device could be oriented differently in different laptops. So this would require a different stitching algorithm or some kind of config variable. I don't have a good way to solve this right now.
caxerx commented 6 years ago

Thanks for reply, hope there have one day that will work. Seem's there are more fingerprint sensor like this now.