diff --git a/0002-fix-ukey-manager-Fixed-a-crash-caused-by-repeatedly-.patch b/0002-fix-ukey-manager-Fixed-a-crash-caused-by-repeatedly-.patch new file mode 100644 index 0000000000000000000000000000000000000000..43110c7d164ecc14865280367509faa2c7655505 --- /dev/null +++ b/0002-fix-ukey-manager-Fixed-a-crash-caused-by-repeatedly-.patch @@ -0,0 +1,30 @@ +From 5b329ca4e7610efb23b7077d5af201290bd3fb61 Mon Sep 17 00:00:00 2001 +From: luoqing +Date: Mon, 3 Jul 2023 16:41:09 +0800 +Subject: [PATCH 2/6] fix(ukey-manager):Fixed a crash caused by repeatedly + calling disConnectDev in resetUkey and destructor to release the same device + handle +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 修复在resetUkey和析构函数中重复调用disConnectDev释放相同的设备句柄从而导致崩溃的问题 +--- + ukey-manager/ukey-manager.cpp | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/ukey-manager/ukey-manager.cpp b/ukey-manager/ukey-manager.cpp +index 30cd23a..d815d72 100644 +--- a/ukey-manager/ukey-manager.cpp ++++ b/ukey-manager/ukey-manager.cpp +@@ -62,7 +62,6 @@ bool UkeyManager::initDriver() + ULONG UkeyManager::resetUkey() + { + ULONG ulReval = m_driver->resetUkey(m_devHandle); +- m_driver->disConnectDev(m_devHandle); + return ulReval; + } + +-- +2.33.0 + diff --git a/0003-refactor-Modify-the-code-according-to-the-https-gite.patch b/0003-refactor-Modify-the-code-according-to-the-https-gite.patch new file mode 100644 index 0000000000000000000000000000000000000000..f0a01648c60629245ac18f4bc91f7c33fb2402d9 --- /dev/null +++ b/0003-refactor-Modify-the-code-according-to-the-https-gite.patch @@ -0,0 +1,1752 @@ +From fe1104186ef3fe8978b75b01960cd147c99665bf Mon Sep 17 00:00:00 2001 +From: luoqing +Date: Thu, 6 Jul 2023 14:41:24 +0800 +Subject: [PATCH 3/6] refactor(*):Modify the code according to the + https://gitee.com/openeuler/kiran-authentication-devices/pulls/17 review + opinions +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 根据 https://gitee.com/openeuler/kiran-authentication-devices/pulls/17 评审意见修改代码 +--- + CMakeLists.txt | 7 +- + data/CMakeLists.txt | 14 +- + data/config.h.in | 5 +- + data/device.conf | 26 ++-- + data/driver.conf | 5 +- + include/auth-enum.h | 5 - + src/auth-device-manager.cpp | 130 +++++++++--------- + src/auth-device-manager.h | 10 +- + src/config-helper.cpp | 67 ++++++--- + src/config-helper.h | 15 +- + src/device/auth-device.cpp | 86 ++++++++++-- + src/device/auth-device.h | 30 ++-- + src/device/bio-device.cpp | 47 +++---- + src/device/bio-device.h | 18 +-- + src/device/device-creator.cpp | 19 +-- + src/device/device-creator.h | 2 +- + src/device/finger-vein/fv-sd-device.cpp | 32 +---- + src/device/finger-vein/fv-sd-device.h | 4 +- + src/device/fingerprint/fp-zk-device.cpp | 30 +--- + src/device/fingerprint/fp-zk-device.h | 4 +- + .../multi-function/mf-iristar-device.cpp | 32 ++--- + src/device/multi-function/mf-iristar-device.h | 7 +- + src/device/ukey/ukey-skf-device.cpp | 77 +++-------- + src/device/ukey/ukey-skf-device.h | 6 +- + .../multi-function/mf-iristar-driver.cpp | 71 +++------- + src/driver/multi-function/mf-iristar-driver.h | 8 +- + src/feature-db.cpp | 2 +- + src/utils.cpp | 29 +--- + src/utils.h | 3 - + ukey-manager/ukey-manager.cpp | 1 + + 30 files changed, 359 insertions(+), 433 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 122d4be..d1189aa 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -19,9 +19,14 @@ set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + + set(TRANSLATION_INSTALL_DIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/translations) +-configure_file(${CMAKE_SOURCE_DIR}/data/config.h.in ${CMAKE_BINARY_DIR}/config.h) ++set(CONF_INSTALL_DIR /${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME}) + + add_subdirectory(src) + add_subdirectory(data) + add_subdirectory(ukey-manager) + ++ ++set(KAD_INSTALL_INCLUDE ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) ++ ++install(FILES ${PROJECT_SOURCE_DIR}/include/kiran-auth-device-i.h ++ DESTINATION ${KAD_INSTALL_INCLUDE}/) +diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt +index 44846ff..617cd14 100644 +--- a/data/CMakeLists.txt ++++ b/data/CMakeLists.txt +@@ -1,6 +1,5 @@ + cmake_minimum_required(VERSION 3.2) + +-set(SYSCONFDIR "/etc") + # init variables + if(SYSTEMD_FOUND) + pkg_get_variable(SYSTEM_UNIT_DIR systemd systemdsystemunitdir) +@@ -29,15 +28,16 @@ install(FILES ${PROJECT_BINARY_DIR}/data/com.kylinsec.Kiran.AuthDevice.service + DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/dbus-1/system-services) + + install(FILES ${PROJECT_SOURCE_DIR}/data/driver.conf +- DESTINATION ${SYSCONFDIR}/${PROJECT_NAME}) ++ DESTINATION ${CONF_INSTALL_DIR}) + + install(FILES ${PROJECT_SOURCE_DIR}/data/device.conf +- DESTINATION ${SYSCONFDIR}/${PROJECT_NAME}) ++ DESTINATION ${CONF_INSTALL_DIR}) + + install(FILES ${PROJECT_SOURCE_DIR}/data/ukey-manager.conf +- DESTINATION ${SYSCONFDIR}/${PROJECT_NAME}) ++ DESTINATION ${CONF_INSTALL_DIR}) + +-set(KAD_INSTALL_INCLUDE ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) ++set(DRIVER_CONF_PATH ${CONF_INSTALL_DIR}/driver.conf) ++set(DEVICE_CONF_PATH ${CONF_INSTALL_DIR}/device.conf) ++set(UKEY_MANAGER_CONF_PATH ${CONF_INSTALL_DIR}/ukey-manager.conf) + +-install(FILES ${PROJECT_SOURCE_DIR}/include/kiran-auth-device-i.h +- DESTINATION ${KAD_INSTALL_INCLUDE}/) +\ No newline at end of file ++configure_file(${CMAKE_SOURCE_DIR}/data/config.h.in ${CMAKE_BINARY_DIR}/config.h) +\ No newline at end of file +diff --git a/data/config.h.in b/data/config.h.in +index d0b327a..fb1f582 100644 +--- a/data/config.h.in ++++ b/data/config.h.in +@@ -1,3 +1,6 @@ + #pragma once + +-#define TRANSLATE_PREFIX "@TRANSLATION_INSTALL_DIR@" ++#define TRANSLATE_PREFIX "@TRANSLATION_INSTALL_DIR@" ++#define DEVICE_CONF "@DEVICE_CONF_PATH@" ++#define DRIVER_CONF "@DRIVER_CONF_PATH@" ++#define UKEY_MANAGER_CONF "@UKEY_MANAGER_CONF_PATH@" +\ No newline at end of file +diff --git a/data/device.conf b/data/device.conf +index 9a367bf..6d7d83b 100644 +--- a/data/device.conf ++++ b/data/device.conf +@@ -3,50 +3,40 @@ + #Name= + #设备类型 + #Type= +-#设备的标识VID,PID.通过标识可找到该设备属于哪种类型的设备 +-#Vid= ++#设备Id,由设备vid和pid组成,以,分隔组成列表。通过标识可找到该设备属于哪种类型的设备 ++#Id=vid1:pid1,vid2:pid2 + #Pid= + #驱动名,与driver.conf中的相对应 + #Driver= +-#对于UKey设备必填,其他类型设备选填:指定加载so的绝对路径;一般不用填,不填则加载默认so; +-#LibPath= + + [ZKFingerpint] + Name= ZKFingerpint + # 设备类型 + Type=0 + # 设备的标识VID,PID.通过标识可找到该设备属于哪种类型的设备 +-Vid=1b55 +-Pid=0120 ++Id=1b55:0120 + Driver= zkfp + + [sd] + Name=saintdeem + Type=2 +-Vid=05e3 +-Pid=0608 ++Id=05e3:0608 + Driver=sdfv + + [iristar] + Name=iristar + Type=1,3 +-Vid=04b4 +-Pid=00f3 ++Id=04b4:00f3 + Driver=irs_sdk2 + + [ft-skf] + Name=Feitian UKey + Type=5 +-Vid=096e +-Pid=0309 ++Id=096e:0309 + Driver=ukey-skf-ft +-LibPath=/usr/lib64/kiran-authentication-devices-sdk/ukey/skf/libes_3000gm.so + + [fish-skf] + Name=YuWeng UKey + Type=5 +-Vid=4612 +-Pid=04b4 +-Driver=ukey-skf-fish +-#对于UKey设备必填,其他类型设备选填:指定加载so的绝对路径;一般不用填,不填则加载默认so; +-LibPath=/usr/lib64/kiran-authentication-devices-sdk/ukey/skf/libGDBapi.so +\ No newline at end of file ++Id=4612:04b4 ++Driver=ukey-skf-fish +\ No newline at end of file +diff --git a/data/driver.conf b/data/driver.conf +index 917c9ab..135d592 100644 +--- a/data/driver.conf ++++ b/data/driver.conf +@@ -2,6 +2,7 @@ + #[DriverName] #驱动名,必填,与实际so对应 + #Enable #是否开启,必填,不填写则默认禁用 + #Type #设备类型,必填; 指纹-0;Refer to enum DeviceType in file /usr/include/kiran-authentication-device/kiran-auth-device-i.h ++#LibPath #对于UKey设备必填,其他类型设备选填:指定加载so的绝对路径;一般不用填,不填则加载默认so; + [zkfp] + Enable=true + Type=0 +@@ -20,7 +21,9 @@ Type=1,3 + [ukey-skf-ft] + Enable=true + Type=5 ++LibPath=/usr/lib64/kiran-authentication-devices-sdk/ukey/skf/libes_3000gm.so + + [ukey-skf-fish] + Enable=true +-Type=5 +\ No newline at end of file ++Type=5 ++LibPath=/usr/lib64/kiran-authentication-devices-sdk/ukey/skf/libGDBapi.so +\ No newline at end of file +diff --git a/include/auth-enum.h b/include/auth-enum.h +index 28d8853..b9e9e49 100644 +--- a/include/auth-enum.h ++++ b/include/auth-enum.h +@@ -19,11 +19,6 @@ namespace Kiran + { + #define DATABASE_DIR "/usr/share/kiran-authentication-devices" + +-#define DRIVER_BLACK_LIST_CONF "/etc/kiran-authentication-device/driver-blacklist.conf" +-#define DEVICE_CONF "/etc/kiran-authentication-devices/device.conf" +-#define DRIVER_CONF "/etc/kiran-authentication-devices/driver.conf" +-#define UKEY_MANAGER_CONF "/etc/kiran-authentication-devices/ukey-manager.conf" +- + #define AUTH_USER_ADMIN "com.kylinsec.kiran.authentication.user-administration" + + #define FT_UKEY_DRIVER_LIB "libes_3000gm.so" +diff --git a/src/auth-device-manager.cpp b/src/auth-device-manager.cpp +index 7cff6a6..a9f5fb0 100644 +--- a/src/auth-device-manager.cpp ++++ b/src/auth-device-manager.cpp +@@ -20,6 +20,7 @@ + #include + #include "auth_device_manager_adaptor.h" + #include "config-helper.h" ++#include "config.h" + #include "device/auth-device.h" + #include "device/device-creator.h" + #include "device/ukey/ukey-skf-device.h" +@@ -31,6 +32,9 @@ + + namespace Kiran + { ++ ++#define MAX_RETREY_CREATE_COUNT 2 ++ + AuthDeviceManager::AuthDeviceManager(QObject* parent) : QObject(parent) + { + } +@@ -180,15 +184,24 @@ void AuthDeviceManager::onRemove(const QDBusMessage& message, const QString& fea + void AuthDeviceManager::onSetEnableDriver(const QDBusMessage& message, const QString& driver_name, bool enable) + { + QStringList driverList = ConfigHelper::getDriverList(); +- if (!driverList.contains(driver_name)) +- { +- goto end; +- } +- ConfigHelper::setDriverEnabled(driver_name, enable); ++ QDBusMessage replyMessage; + +- // 驱动被禁用,将当前正在使用的设备释放掉 +- if (!enable) ++ do + { ++ if (!driverList.contains(driver_name)) ++ { ++ replyMessage = message.createErrorReply(QDBusError::Failed, "No driver with the corresponding name was found."); ++ break; ++ } ++ ConfigHelper::setDriverEnabled(driver_name, enable); ++ replyMessage = message.createReply(); ++ ++ if (enable) ++ { ++ break; ++ } ++ ++ // 驱动被禁用,将当前正在使用的设备释放掉 + auto devices = m_deviceMap.values(); + Q_FOREACH (AuthDevicePtr device, devices) + { +@@ -204,19 +217,55 @@ void AuthDeviceManager::onSetEnableDriver(const QDBusMessage& message, const QSt + Q_EMIT m_dbusAdaptor->DeviceDeleted(deviceType, deviceID); + KLOG_INFO() << QString("destroyed deviceType: %1, deviceID:%2").arg(deviceType).arg(deviceID); + } +- } +-end: +- auto replyMessage = message.createReply(); ++ } while (false); ++ + QDBusConnection::systemBus().send(replyMessage); + } + ++AuthDeviceList AuthDeviceManager::createDevices(const DeviceInfo& deviceInfo) ++{ ++ // TODO:先从内置默认支持的设备开始搜索,最后才搜索第三方设备 ++ QString vid = deviceInfo.idVendor; ++ QString pid = deviceInfo.idProduct; ++ if (!ConfigHelper::isDeviceSupported(vid, pid)) ++ { ++ KLOG_DEBUG() << "no auth device!" ++ << "idVendor:" << vid ++ << "idProduct:" << pid; ++ return AuthDeviceList(); ++ } ++ ++ DeviceConf deviceConf = ConfigHelper::getDeviceConf(vid, pid); ++ if (!ConfigHelper::driverEnabled(vid, pid)) ++ { ++ KLOG_INFO() << QString("driver:%1 is disabled, auth device: %2 can't be used") ++ .arg(deviceConf.driver) ++ .arg(deviceConf.deviceName) ++ << " vid:" << vid << " pid:" << pid; ++ return AuthDeviceList(); ++ } ++ ++ QString libPath = ConfigHelper::getLibPath(vid, pid); ++ DriverPtr driverPtr = DriverFactory::getInstance()->getDriver(deviceConf.driver, libPath); ++ ++ if (driverPtr.isNull()) ++ { ++ KLOG_ERROR() << QString("get driver: %1 failed!").arg(deviceConf.driver); ++ return AuthDeviceList(); ++ } ++ ++ AuthDeviceList deviceList = DeviceCereator::getInstance()->createDevices(vid, pid, driverPtr); ++ return deviceList; ++} ++ + CHECK_AUTH_WITH_1ARGS(AuthDeviceManager, Remove, onRemove, AUTH_USER_ADMIN, const QString&) + CHECK_AUTH_WITH_2ARGS(AuthDeviceManager, SetEnableDriver, onSetEnableDriver, AUTH_USER_ADMIN, const QString&, bool) + + void AuthDeviceManager::init() + { + m_dbusAdaptor = QSharedPointer(new AuthDeviceManagerAdaptor(this)); +- connect(&m_timer, &QTimer::timeout, this, &AuthDeviceManager::handleDeviceReCreate); ++ m_ReCreateTimer.setInterval(1000); ++ connect(&m_ReCreateTimer, &QTimer::timeout, this, &AuthDeviceManager::handleDeviceReCreate); + + QDBusConnection dbusConnection = QDBusConnection::systemBus(); + if (!dbusConnection.registerService(AUTH_DEVICE_DBUS_NAME)) +@@ -249,37 +298,7 @@ void AuthDeviceManager::init() + + void AuthDeviceManager::handleDeviceAdded(const DeviceInfo& deviceInfo) + { +- // TODO:先从内置默认支持的设备开始搜索,最后才搜索第三方设备 +- QString vid = deviceInfo.idVendor; +- QString pid = deviceInfo.idProduct; +- if (!ConfigHelper::isDeviceSupported(vid, pid)) +- { +- KLOG_DEBUG() << "no auth device!" +- << "idVendor:" << vid +- << "idProduct:" << pid; +- return; +- } +- +- DeviceConf deviceConf = ConfigHelper::getDeviceConf(vid, pid); +- if (!ConfigHelper::driverEnabled(vid, pid)) +- { +- KLOG_INFO() << QString("driver:%1 is disabled, auth device: %2 can't be used") +- .arg(deviceConf.driver) +- .arg(deviceConf.deviceName) +- << " vid:" << vid << " pid:" << pid; +- return; +- } +- +- QString libPath = ConfigHelper::getLibPath(vid, pid); +- DriverPtr driverPtr = DriverFactory::getInstance()->getDriver(deviceConf.driver, libPath); +- +- if (driverPtr.isNull()) +- { +- KLOG_ERROR() << QString("get driver: %1 failed!").arg(deviceConf.driver); +- return; +- } +- +- AuthDeviceList deviceList = DeviceCereator::getInstance()->getDevices(vid, pid, driverPtr); ++ AuthDeviceList deviceList = createDevices(deviceInfo); + if (deviceList.count() == 0) + { + handleDeviceCreateFail(deviceInfo); +@@ -289,7 +308,6 @@ void AuthDeviceManager::handleDeviceAdded(const DeviceInfo& deviceInfo) + Q_FOREACH (auto device, deviceList) + { + m_deviceMap.insert(deviceInfo.busPath, device); +- Q_EMIT this->DeviceAdded(device->deviceType(), device->deviceID()); + Q_EMIT m_dbusAdaptor->DeviceAdded(device->deviceType(), device->deviceID()); + + KLOG_DEBUG() << "auth device added" +@@ -304,9 +322,9 @@ void AuthDeviceManager::handleDeviceCreateFail(DeviceInfo deviceInfo) + m_retreyCreateDeviceMap.insert(deviceInfo, 0); + if (m_retreyCreateDeviceMap.count() != 0) + { +- if (!m_timer.isActive()) ++ if (!m_ReCreateTimer.isActive()) + { +- m_timer.start(1000); ++ m_ReCreateTimer.start(); + } + } + } +@@ -334,7 +352,7 @@ void AuthDeviceManager::handleDeviceDeleted() + deviceID = oldAuthDevice->deviceID(); + deviceType = oldAuthDevice->deviceType(); + int removeCount = m_deviceMap.remove(busPath); +- oldAuthDevice.clear(); ++ + Q_EMIT m_dbusAdaptor->DeviceDeleted(deviceType, deviceID); + + QMapIterator i(m_retreyCreateDeviceMap); +@@ -355,7 +373,7 @@ void AuthDeviceManager::handleDeviceReCreate() + { + if (m_retreyCreateDeviceMap.count() == 0) + { +- m_timer.stop(); ++ m_ReCreateTimer.stop(); + return; + } + +@@ -363,28 +381,15 @@ void AuthDeviceManager::handleDeviceReCreate() + while (i.hasNext()) + { + i.next(); +- if (i.value() >= 2) ++ if (i.value() >= MAX_RETREY_CREATE_COUNT) + { + m_retreyCreateDeviceMap.remove(i.key()); + continue; + } + + auto deviceInfo = i.key(); +- QString vid = deviceInfo.idVendor; +- QString pid = deviceInfo.idProduct; +- +- DeviceConf deviceConf = ConfigHelper::getDeviceConf(vid, pid); +- DriverPtr driverPtr = DriverFactory::getInstance()->getDriver(deviceConf.driver); +- if (!driverPtr.isNull()) +- { +- if (!driverPtr->initDriver()) +- { +- KLOG_ERROR() << QString("init driver %1 failed").arg(deviceConf.driver); +- continue; +- } +- } + +- AuthDeviceList deviceList = DeviceCereator::getInstance()->getDevices(vid, pid, driverPtr); ++ AuthDeviceList deviceList = createDevices(deviceInfo); + if (deviceList.count() == 0) + { + m_retreyCreateDeviceMap.insert(i.key(), i.value() + 1); +@@ -394,7 +399,6 @@ void AuthDeviceManager::handleDeviceReCreate() + Q_FOREACH (auto device, deviceList) + { + m_deviceMap.insert(deviceInfo.busPath, device); +- Q_EMIT this->DeviceAdded(device->deviceType(), device->deviceID()); + Q_EMIT m_dbusAdaptor->DeviceAdded(device->deviceType(), device->deviceID()); + + KLOG_DEBUG() << "device added" +diff --git a/src/auth-device-manager.h b/src/auth-device-manager.h +index 2253d50..95e68e9 100644 +--- a/src/auth-device-manager.h ++++ b/src/auth-device-manager.h +@@ -29,7 +29,6 @@ class AuthDeviceManagerAdaptor; + namespace Kiran + { + class AuthDevice; +-class ContextFactory; + + class AuthDeviceManager : public QObject, protected QDBusContext + { +@@ -53,7 +52,7 @@ public Q_SLOTS: + void Remove(const QString &feature_id); + + private Q_SLOTS: +- void handleDeviceAdded(const DeviceInfo &usbInfo); ++ void handleDeviceAdded(const DeviceInfo &deviceInfo); + void handleDeviceDeleted(); + void handleDeviceReCreate(); + void handleDeviceCreateFail(DeviceInfo deviceInfo); +@@ -62,10 +61,7 @@ private: + void init(); + void onRemove(const QDBusMessage &message, const QString &feature_id); + void onSetEnableDriver(const QDBusMessage &message, const QString &driver_name, bool enable); +- +-Q_SIGNALS: +- void DeviceAdded(int device_type, const QString &device_id); +- void DeviceDeleted(int device_type, const QString &device_id); ++ QList> createDevices(const DeviceInfo &deviceInfo); + + private: + static AuthDeviceManager *m_instance; +@@ -73,7 +69,7 @@ private: + QSharedPointer m_dbusAdaptor; + // 总线 -- AuthDevice对象对应 + QMultiMap> m_deviceMap; +- QTimer m_timer; ++ QTimer m_ReCreateTimer; + + // 设备信息-重试次数 + QMap m_retreyCreateDeviceMap; +diff --git a/src/config-helper.cpp b/src/config-helper.cpp +index 31287e4..8fc5a47 100644 +--- a/src/config-helper.cpp ++++ b/src/config-helper.cpp +@@ -16,6 +16,7 @@ + #include + #include + #include "auth-enum.h" ++#include "config.h" + + namespace Kiran + { +@@ -27,25 +28,46 @@ DeviceConf ConfigHelper::getDeviceConf(const QString &vid, const QString &pid) + Q_FOREACH (auto deviceConf, deviceConfList) + { + confSettings.beginGroup(deviceConf); +- if ((confSettings.value("Vid").toString() == vid) && +- (confSettings.value("Pid").toString() == pid)) ++ ++ QStringList idList = confSettings.value("Id").toStringList(); ++ for (const QString &id : idList) + { +- DeviceConf conf; +- conf.deviceName = confSettings.value("Name").toString(); +- conf.type = confSettings.value("Type").toInt(); +- conf.vid = confSettings.value("Vid").toString(); +- conf.pid = confSettings.value("Pid").toString(); +- conf.driver = confSettings.value("Driver").toString(); +- conf.libPath = confSettings.value("LibPath").toString(); +- +- return conf; ++ if (id == QString("%1:%2").arg(vid).arg(pid)) ++ { ++ DeviceConf conf; ++ conf.deviceName = confSettings.value("Name").toString(); ++ conf.type = confSettings.value("Type").toInt(); ++ conf.vid = vid; ++ conf.pid = pid; ++ conf.driver = confSettings.value("Driver").toString(); ++ return conf; ++ } + } ++ + confSettings.endGroup(); + } + + return DeviceConf(); + } + ++DriverConf ConfigHelper::getDriverConf(const QString &vid, const QString &pid) ++{ ++ QString driverName = getDeviceConf(vid, pid).driver; ++ ++ DriverConf driverConf; ++ QSettings confSettings(DRIVER_CONF, QSettings::NativeFormat); ++ confSettings.beginGroup(driverName); ++ ++ driverConf.driverName = driverName; ++ driverConf.enable = confSettings.value("Enable").toBool(); ++ driverConf.type = confSettings.value("Type").toInt(); ++ driverConf.libPath = confSettings.value("LibPath").toString(); ++ ++ confSettings.endGroup(); ++ ++ return driverConf; ++} ++ + QString ConfigHelper::getDriverName(const QString &vid, const QString &pid) + { + DeviceConf conf = getDeviceConf(vid, pid); +@@ -60,8 +82,8 @@ QString ConfigHelper::getDeviceName(const QString &vid, const QString &pid) + + QString ConfigHelper::getLibPath(const QString &vid, const QString &pid) + { +- DeviceConf conf = getDeviceConf(vid, pid); +- return conf.libPath; ++ DriverConf driverConf = getDriverConf(vid, pid); ++ return driverConf.libPath; + } + + int ConfigHelper::getDeviceType(const QString &vid, const QString &pid) +@@ -91,16 +113,14 @@ bool ConfigHelper::driverEnabled(const QString &vid, const QString &pid) + return enable; + } + +-void ConfigHelper::setDriverEnabled(const QString& driverName, bool enable) ++void ConfigHelper::setDriverEnabled(const QString &driverName, bool enable) + { + QSettings confSettings(DRIVER_CONF, QSettings::NativeFormat); + QStringList driverList = confSettings.childGroups(); +- QString enableStr; + if (driverList.contains(driverName)) + { +- enableStr = enable ? QString("true") : QString("false"); +- confSettings.setValue(QString("%1/Enable").arg(driverName), QVariant(enableStr)); +- KLOG_INFO() << QString("driver: %1 %2").arg(driverName).arg((enable == true) ? "enable":"disable"); ++ confSettings.setValue(QString("%1/Enable").arg(driverName), QVariant(enable)); ++ KLOG_INFO() << QString("driver: %1 %2").arg(driverName).arg(enable ? "enable" : "disable"); + } + } + +@@ -112,11 +132,16 @@ bool ConfigHelper::isDeviceSupported(const QString &vid, const QString &pid) + Q_FOREACH (auto deviceConf, deviceConfList) + { + confSettings.beginGroup(deviceConf); +- if ((confSettings.value("Vid").toString() == vid) && +- (confSettings.value("Pid").toString() == pid)) ++ ++ QStringList idList = confSettings.value("Id").toStringList(); ++ for (const QString &id : idList) + { +- return true; ++ if (id == QString("%1:%2").arg(vid).arg(pid)) ++ { ++ return true; ++ } + } ++ + confSettings.endGroup(); + } + return false; +diff --git a/src/config-helper.h b/src/config-helper.h +index 1d0d677..91cf895 100644 +--- a/src/config-helper.h ++++ b/src/config-helper.h +@@ -12,7 +12,7 @@ + * Author: luoqing + */ + #pragma once +-#include ++#include + + namespace Kiran + { +@@ -24,16 +24,25 @@ struct DeviceConf + QString vid; + QString pid; + QString driver; ++}; ++ ++struct DriverConf ++{ ++ QString driverName; ++ bool enable; ++ int type; + QString libPath; + }; + +-class ConfigHelper : public QObject ++class ConfigHelper + { + public: +- ConfigHelper(QObject *parent = nullptr) : QObject(parent){}; ++ ConfigHelper() {}; + ~ConfigHelper(){}; + + static DeviceConf getDeviceConf(const QString &vid, const QString &pid); ++ static DriverConf getDriverConf(const QString &vid, const QString &pid); ++ + static QString getDriverName(const QString &vid, const QString &pid); + static QString getDeviceName(const QString &vid, const QString &pid); + static QString getLibPath(const QString &vid, const QString &pid); +diff --git a/src/device/auth-device.cpp b/src/device/auth-device.cpp +index 7111ff6..aef4b85 100644 +--- a/src/device/auth-device.cpp ++++ b/src/device/auth-device.cpp +@@ -18,11 +18,11 @@ + #include + #include + #include "auth_device_adaptor.h" ++#include "config-helper.h" + #include "feature-db.h" + #include "kiran-auth-device-i.h" + #include "polkit-proxy.h" + #include "utils.h" +-#include "config-helper.h" + + namespace Kiran + { +@@ -38,7 +38,7 @@ AuthDevice::~AuthDevice(){}; + + bool AuthDevice::init() + { +- if(!initDevice()) ++ if (!initDevice()) + { + return false; + } +@@ -96,15 +96,6 @@ void AuthDevice::onNameLost(const QString& serviceName) + } + } + +-void AuthDevice::clearWatchedServices() +-{ +- QStringList watchedServices = m_serviceWatcher->watchedServices(); +- Q_FOREACH (auto service, watchedServices) +- { +- m_serviceWatcher->removeWatchedService(service); +- } +-} +- + DeviceInfo AuthDevice::deviceInfo() + { + DeviceInfo deviceInfo; +@@ -120,6 +111,55 @@ void AuthDevice::setDeviceInfo(const QString& idVendor, const QString& idProduct + m_idProduct = idProduct; + } + ++void AuthDevice::clearWatchedServices() ++{ ++ QStringList watchedServices = m_serviceWatcher->watchedServices(); ++ Q_FOREACH (auto service, watchedServices) ++ { ++ m_serviceWatcher->removeWatchedService(service); ++ } ++} ++ ++void AuthDevice::internalStopEnroll() ++{ ++ if (deviceStatus() == DEVICE_STATUS_DOING_ENROLL) ++ { ++ deviceStopEnroll(); ++ setDeviceStatus(DEVICE_STATUS_IDLE); ++ clearWatchedServices(); ++ KLOG_DEBUG() << QString("enroll stop, device type:%1,name:%2 ,id:%3") ++ .arg(deviceType()) ++ .arg(deviceName()) ++ .arg(deviceID()); ++ } ++} ++ ++void AuthDevice::internalStopIdentify() ++{ ++ if (deviceStatus() == DEVICE_STATUS_DOING_IDENTIFY) ++ { ++ deviceStopIdentify(); ++ m_featuresThatNeedToIdentify.clear(); ++ setDeviceStatus(DEVICE_STATUS_IDLE); ++ clearWatchedServices(); ++ KLOG_DEBUG() << QString("identify stop, device type:%1,name:%2 ,id:%3") ++ .arg(deviceType()) ++ .arg(deviceName()) ++ .arg(deviceID()); ++ } ++} ++ ++QList AuthDevice::findFeaturesByFeatureIDs(const QStringList& featureIDs) ++{ ++ QList saveList; ++ Q_FOREACH (auto id, featureIDs) ++ { ++ QByteArray feature = FeatureDB::getInstance()->getFeature(id); ++ saveList << feature; ++ } ++ return saveList; ++} ++ + void AuthDevice::onEnrollStart(const QDBusMessage& dbusMessage, const QString& extraInfo) + { + QString message; +@@ -147,25 +187,41 @@ void AuthDevice::onEnrollStop(const QDBusMessage& dbusMessage) + + void AuthDevice::onIdentifyStart(const QDBusMessage& dbusMessage, const QString& value) + { +- QString message; + if (deviceStatus() != DEVICE_STATUS_IDLE) + { +- message = tr("Device Busy"); ++ QString message = tr("Device Busy"); + Q_EMIT m_dbusAdaptor->IdentifyStatus("", IDENTIFY_STATUS_NOT_MATCH, message); +- KLOG_DEBUG() << QString("%1, deviceID:%2").arg(message).arg(deviceID()); ++ KLOG_DEBUG() << QString("%1, deviceID:%2").arg("Device Busy").arg(deviceID()); + return; + } + ++ QStringList featureIDs; + QJsonArray jsonArray = Utils::getValueFromJsonString(value, AUTH_DEVICE_JSON_KEY_FEATURE_IDS).toArray(); + if (!jsonArray.isEmpty()) + { + QVariantList varList = jsonArray.toVariantList(); + Q_FOREACH (auto var, varList) + { +- m_identifyIDs << var.toString(); ++ featureIDs << var.toString(); + } + } + ++ if (featureIDs.isEmpty()) ++ { ++ m_featuresThatNeedToIdentify = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber()); ++ } ++ else ++ { ++ m_featuresThatNeedToIdentify = findFeaturesByFeatureIDs(featureIDs); ++ } ++ ++ if (m_featuresThatNeedToIdentify.count() == 0) ++ { ++ KLOG_DEBUG() << "no found feature id"; ++ Q_EMIT m_dbusAdaptor->IdentifyStatus("", IDENTIFY_STATUS_NOT_MATCH, tr("identify fail!")); ++ return; ++ } ++ + setDeviceStatus(DEVICE_STATUS_DOING_IDENTIFY); + m_serviceWatcher->addWatchedService(dbusMessage.service()); + auto replyMessage = dbusMessage.createReply(); +diff --git a/src/device/auth-device.h b/src/device/auth-device.h +index 581998e..7209781 100644 +--- a/src/device/auth-device.h ++++ b/src/device/auth-device.h +@@ -23,13 +23,13 @@ + #include "auth-enum.h" + #include "driver/driver.h" + #include "kiran-auth-device-i.h" ++#include "device-creator.h" + + class AuthDeviceAdaptor; + + namespace Kiran + { + typedef void *Handle; +-class BDriver; + + class AuthDevice : public QObject, protected QDBusContext + { +@@ -43,10 +43,8 @@ public: + explicit AuthDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent = nullptr); + virtual ~AuthDevice(); + bool init(); +- virtual bool initDevice() = 0; + + QDBusObjectPath getObjectPath() { return m_objectPath; }; +- void setDeviceType(DeviceType deviceType) { m_deviceType = deviceType; }; + + DeviceType deviceType() { return m_deviceType; }; + DeviceStatus deviceStatus() { return m_deviceStatus; }; +@@ -57,6 +55,10 @@ public: + + QString driverName() { return m_driverName; }; + ++private: ++ virtual bool initDevice() = 0; ++ friend AuthDeviceList DeviceCereator::createDevices(const QString &vid, const QString &pid, DriverPtr driver); ++ + public Q_SLOTS: + virtual void EnrollStart(const QString &extraInfo); + virtual void EnrollStop(); +@@ -65,6 +67,7 @@ public Q_SLOTS: + virtual QStringList GetFeatureIDList(); + + protected: ++ void setDeviceType(DeviceType deviceType) { m_deviceType = deviceType; }; + void setDeviceStatus(DeviceStatus deviceStatus) { m_deviceStatus = deviceStatus; }; + void setDeviceName(const QString &deviceName) { m_deviceName = deviceName; }; + void setDeviceInfo(const QString &idVendor, const QString &idProduct); +@@ -73,8 +76,13 @@ protected: + void setDriverName(const QString &driverName) { m_driverName = driverName; }; + + void clearWatchedServices(); +- virtual void internalStopEnroll() = 0; +- virtual void internalStopIdentify() = 0; ++ void internalStopEnroll(); ++ void internalStopIdentify(); ++ ++ virtual void deviceStopEnroll() = 0; ++ virtual void deviceStopIdentify() = 0; ++ ++ QList getFeaturesThatNeedToIdentify() {return m_featuresThatNeedToIdentify;}; + + private: + void onEnrollStart(const QDBusMessage &message, const QString &extraInfo); +@@ -85,21 +93,23 @@ private: + virtual void doingEnrollStart(const QString &extraInfo) = 0; + virtual void doingIdentifyStart(const QString &value) = 0; + +-private Q_SLOTS: +- void onNameLost(const QString &serviceName); +- +-private: + void registerDBusObject(); + void initServiceWatcher(); + ++ QList findFeaturesByFeatureIDs(const QStringList &featureIDs); ++ ++private Q_SLOTS: ++ void onNameLost(const QString &serviceName); ++ + Q_SIGNALS: + void retry(); + + protected: + QSharedPointer m_dbusAdaptor; +- QStringList m_identifyIDs; + + private: ++ QList m_featuresThatNeedToIdentify; ++ + QString m_driverName; + QString m_deviceID; + +diff --git a/src/device/bio-device.cpp b/src/device/bio-device.cpp +index 8d73cd5..841d48c 100644 +--- a/src/device/bio-device.cpp ++++ b/src/device/bio-device.cpp +@@ -22,8 +22,8 @@ namespace Kiran + { + #define TEMPLATE_MAX_NUMBER 1000 + +-BioDevice::BioDevice(const QString &vid, const QString &pid, DriverPtr driver,QObject *parent) : AuthDevice{vid,pid,driver,parent}, +- m_futureWatcher(nullptr) ++BioDevice::BioDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent) : AuthDevice{vid, pid, driver, parent}, ++ m_futureWatcher(nullptr) + { + initFutureWatcher(); + } +@@ -36,7 +36,7 @@ void BioDevice::doingEnrollStart(const QString &extraInfo) + { + KLOG_DEBUG() << "biological information enroll start"; + // 获取当前保存的特征模板,判断是否达到最大数目 +- QByteArrayList saveList = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(),deviceSerialNumber()); ++ QByteArrayList saveList = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber()); + if (saveList.count() == TEMPLATE_MAX_NUMBER) + { + QString message = tr("feature has reached the upper limit of %1").arg(TEMPLATE_MAX_NUMBER); +@@ -87,30 +87,6 @@ void BioDevice::doingIdentifyStart(const QString &value) + m_dbusAdaptor->IdentifyStatus("", ENROLL_STATUS_NORMAL, message); + } + +-void BioDevice::internalStopEnroll() +-{ +- if (deviceStatus() == DEVICE_STATUS_DOING_ENROLL) +- { +- acquireFeatureStop(); +- m_enrollTemplates.clear(); +- setDeviceStatus(DEVICE_STATUS_IDLE); +- clearWatchedServices(); +- KLOG_DEBUG() << QString("device type:%1,internal enroll stop").arg(deviceType()); +- } +-} +- +-void BioDevice::internalStopIdentify() +-{ +- if (deviceStatus() == DEVICE_STATUS_DOING_IDENTIFY) +- { +- acquireFeatureStop(); +- m_identifyIDs.clear(); +- setDeviceStatus(DEVICE_STATUS_IDLE); +- clearWatchedServices(); +- KLOG_DEBUG() << QString("device type:%1,internal identify stop").arg(deviceType()); +- } +-} +- + void BioDevice::doingEnrollProcess(QByteArray feature) + { + int templatesCount = enrollTemplatesFromCache().count(); +@@ -146,12 +122,13 @@ void BioDevice::doingEnrollProcess(QByteArray feature) + else if (enrollTemplatesFromCache().count() == mergeTemplateCount()) + { + enrollTemplateMerge(); ++ internalStopEnroll(); + } + } + + void BioDevice::doingIdentifyProcess(QByteArray feature) + { +- QString featureID = identifyFeature(feature, m_identifyIDs); ++ QString featureID = identifyFeature(feature, getFeaturesThatNeedToIdentify()); + if (!featureID.isEmpty()) + { + notifyIdentifyProcess(IDENTIFY_PROCESS_MACTCH, featureID); +@@ -208,6 +185,17 @@ void BioDevice::saveEnrollTemplateToCache(QByteArray enrollTemplate) + } + } + ++void BioDevice::deviceStopEnroll() ++{ ++ acquireFeatureStop(); ++ m_enrollTemplates.clear(); ++} ++ ++void BioDevice::deviceStopIdentify() ++{ ++ acquireFeatureStop(); ++} ++ + void BioDevice::enrollProcessRetry() + { + Q_EMIT this->retry(); +@@ -215,7 +203,8 @@ void BioDevice::enrollProcessRetry() + + QString BioDevice::isFeatureEnrolled(QByteArray fpTemplate) + { +- return identifyFeature(fpTemplate, QStringList()); ++ QList features = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber()); ++ return identifyFeature(fpTemplate, features); + } + + void BioDevice::initFutureWatcher() +diff --git a/src/device/bio-device.h b/src/device/bio-device.h +index 643acf1..4c05923 100644 +--- a/src/device/bio-device.h ++++ b/src/device/bio-device.h +@@ -20,7 +20,7 @@ class BioDevice : public AuthDevice + { + Q_OBJECT + public: +- explicit BioDevice(const QString &vid, const QString &pid, DriverPtr driver,QObject *parent = nullptr); ++ explicit BioDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent = nullptr); + ~BioDevice(); + int mergeTemplateCount() { return m_mergeTemplateCount; }; + void setMergeTemplateCount(int count) { m_mergeTemplateCount = count; }; +@@ -29,16 +29,16 @@ protected: + virtual QByteArray acquireFeature() = 0; + virtual void acquireFeatureStop() = 0; + virtual void acquireFeatureFail() = 0; +- virtual QString identifyFeature(QByteArray feature, QStringList featureIDs) = 0; +- +- virtual void enrollTemplateMerge() {}; +- virtual int enrollTemplateMatch(QByteArray fpTemplate1, QByteArray fpTemplate2) {return GENERAL_RESULT_OK;}; +- +- void internalStopEnroll() override; +- void internalStopIdentify() override; ++ virtual QString identifyFeature(QByteArray feature, QList existedfeatures) = 0; ++ ++ virtual void enrollTemplateMerge(){}; ++ virtual int enrollTemplateMatch(QByteArray fpTemplate1, QByteArray fpTemplate2) { return GENERAL_RESULT_OK; }; ++ ++ virtual void deviceStopEnroll() override; ++ virtual void deviceStopIdentify() override; + + virtual void enrollProcessRetry(); +- //TODO:优化通知 ++ // TODO:优化通知 + virtual void notifyEnrollProcess(EnrollProcess process, const QString &featureID = QString()) = 0; + virtual void notifyIdentifyProcess(IdentifyProcess process, const QString &featureID = QString()) = 0; + +diff --git a/src/device/device-creator.cpp b/src/device/device-creator.cpp +index d7cd926..1fb760f 100644 +--- a/src/device/device-creator.cpp ++++ b/src/device/device-creator.cpp +@@ -45,7 +45,7 @@ DeviceCereator::~DeviceCereator() + { + } + +-AuthDeviceList DeviceCereator::getDevices(const QString &vid, const QString &pid, DriverPtr driver) ++AuthDeviceList DeviceCereator::createDevices(const QString &vid, const QString &pid, DriverPtr driver) + { + AuthDeviceList deviceList; + QStringList driverNameList = m_deviceFuncMap.keys(); +@@ -72,12 +72,7 @@ AuthDeviceList DeviceCereator::getDevices(const QString &vid, const QString &pid + (irisDevicePtr->init())) + { + deviceList << faceDevicePtr << irisDevicePtr; +- } +- else +- { +- KLOG_ERROR() << QString("device %1:%2 init failed!").arg(vid).arg(pid); +- faceDevicePtr.clear(); +- irisDevicePtr.clear(); ++ return deviceList; + } + } + else +@@ -87,14 +82,12 @@ AuthDeviceList DeviceCereator::getDevices(const QString &vid, const QString &pid + if (devicePtr->init()) + { + deviceList << devicePtr; +- } +- else +- { +- KLOG_ERROR() << QString("device %1:%2 init failed!").arg(vid).arg(pid); +- devicePtr.clear(); ++ return deviceList; + } + } +- return deviceList; ++ ++ KLOG_ERROR() << QString("device %1:%2 init failed!").arg(vid).arg(pid); ++ return AuthDeviceList(); + } + + void DeviceCereator::registerDevice(QString driverName, std::function func) +diff --git a/src/device/device-creator.h b/src/device/device-creator.h +index be074cb..9b3db32 100644 +--- a/src/device/device-creator.h ++++ b/src/device/device-creator.h +@@ -36,7 +36,7 @@ public: + static DeviceCereator *getInstance(); + ~DeviceCereator(); + +- AuthDeviceList getDevices(const QString &vid, const QString &pid, DriverPtr driver); ++ AuthDeviceList createDevices(const QString &vid, const QString &pid, DriverPtr driver); + + void registerDevice(QString driverName, + std::function func); +diff --git a/src/device/finger-vein/fv-sd-device.cpp b/src/device/finger-vein/fv-sd-device.cpp +index 67dcab8..442f227 100644 +--- a/src/device/finger-vein/fv-sd-device.cpp ++++ b/src/device/finger-vein/fv-sd-device.cpp +@@ -240,42 +240,21 @@ void FVSDDevice::enrollTemplateMerge() + KLOG_DEBUG() << "Finger vein template fusion failed:" << ret; + notifyEnrollProcess(ENROLL_PROCESS_MEGER_FAIL); + } +- internalStopEnroll(); + } + + QString FVSDDevice::isFeatureEnrolled(QByteArray fpTemplate) + { + QByteArray featureForVerify = getFeatureFromImage(fpTemplate, EXTRACT_FEATURE_VERIFY); +- QString featureID = identifyFeature(featureForVerify, QStringList()); ++ QList features = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber()); ++ QString featureID = identifyFeature(featureForVerify, features); + return featureID; + } + +-QString FVSDDevice::identifyFeature(QByteArray feature, QStringList featureIDs) ++QString FVSDDevice::identifyFeature(QByteArray feature, QList existedfeatures) + { +- QList saveList; + QString featureID; +- DeviceInfo deviceInfo = this->deviceInfo(); +- if (featureIDs.isEmpty()) +- { +- saveList = FeatureDB::getInstance()->getFeatures(deviceInfo.idVendor, deviceInfo.idProduct, deviceType(), deviceSerialNumber()); +- } +- else +- { +- Q_FOREACH (auto id, featureIDs) +- { +- QByteArray feature = FeatureDB::getInstance()->getFeature(id); +- if (!feature.isEmpty()) +- saveList << feature; +- } +- } +- +- if (saveList.count() == 0) +- { +- return QString(); +- } +- + QByteArray saveTempl; +- Q_FOREACH (auto saveFeature, saveList) ++ Q_FOREACH (auto saveFeature, existedfeatures) + { + saveTempl.append(saveFeature); + } +@@ -283,11 +262,10 @@ QString FVSDDevice::identifyFeature(QByteArray feature, QStringList featureIDs) + int matchIndex = 0; + int matchScore = 0; + unsigned char updateTmpl[TEMPLATE_SIZE] = {0}; // 自我学习后的新模板 +- KLOG_DEBUG() << "saveList.count():" << saveList.count(); + + int matchResult = m_driver->TGFeatureMatchTmpl1N((unsigned char *)feature.data(), + (unsigned char *)saveTempl.data(), +- saveList.count(), ++ existedfeatures.count(), + &matchIndex, + &matchScore, + updateTmpl); +diff --git a/src/device/finger-vein/fv-sd-device.h b/src/device/finger-vein/fv-sd-device.h +index 0a4f5a4..0a82055 100644 +--- a/src/device/finger-vein/fv-sd-device.h ++++ b/src/device/finger-vein/fv-sd-device.h +@@ -33,9 +33,9 @@ class FVSDDevice : public BioDevice + public: + explicit FVSDDevice(const QString &vid, const QString &pid, DriverPtr driver,QObject *parent = nullptr); + ~FVSDDevice(); +- bool initDevice() override; + + private: ++ bool initDevice() override; + QByteArray acquireFeature() override; + void acquireFeatureStop() override; + void acquireFeatureFail() override; +@@ -46,7 +46,7 @@ private: + void enrollProcessRetry() override; + + QString isFeatureEnrolled(QByteArray fpTemplate) override; +- QString identifyFeature(QByteArray feature, QStringList featureIDs) override; ++ QString identifyFeature(QByteArray feature, QList existedfeatures) override; + + void notifyEnrollProcess(EnrollProcess process, const QString &featureID = QString()) override; + void notifyIdentifyProcess(IdentifyProcess process, const QString &featureID = QString()) override; +diff --git a/src/device/fingerprint/fp-zk-device.cpp b/src/device/fingerprint/fp-zk-device.cpp +index 3a26cf5..3a818f3 100644 +--- a/src/device/fingerprint/fp-zk-device.cpp ++++ b/src/device/fingerprint/fp-zk-device.cpp +@@ -233,34 +233,12 @@ int FPZKDevice::enrollTemplateMatch(QByteArray fpTemplate1, QByteArray fpTemplat + return score > 0 ? GENERAL_RESULT_OK : GENERAL_RESULT_FAIL; + } + +-QString FPZKDevice::identifyFeature(QByteArray fpTemplate, QStringList featureIDs) ++QString FPZKDevice::identifyFeature(QByteArray fpTemplate, QList existedfeatures) + { +- QList saveList; + QString featureID; +- DeviceInfo info = this->deviceInfo(); +- if (featureIDs.isEmpty()) ++ for (int j = 0; j < existedfeatures.count(); j++) + { +- saveList = FeatureDB::getInstance()->getFeatures(info.idVendor, info.idProduct, deviceType(), deviceSerialNumber()); +- } +- else +- { +- Q_FOREACH (auto id, featureIDs) +- { +- QByteArray feature = FeatureDB::getInstance()->getFeature(id); +- if (!feature.isEmpty()) +- saveList << feature; +- } +- } +- +- if (saveList.count() == 0) +- { +- KLOG_DEBUG() << "no found feature"; +- return QString(); +- } +- +- for (int j = 0; j < saveList.count(); j++) +- { +- auto saveTemplate = saveList.value(j); ++ auto saveTemplate = existedfeatures.value(j); + int ret = enrollTemplateMatch(fpTemplate, saveTemplate); + // 指纹已经存在,直接返回该指纹 + if (ret == GENERAL_RESULT_OK) +@@ -294,7 +272,6 @@ void FPZKDevice::enrollTemplateMerge() + { + // 三个模板merge失败,判定为录入失败,需要重新录入 + notifyEnrollProcess(ENROLL_PROCESS_MEGER_FAIL); +- internalStopEnroll(); + return; + } + +@@ -318,7 +295,6 @@ void FPZKDevice::enrollTemplateMerge() + // 如果合成后的指纹与先前录入的指纹不匹配,判定为录入失败,需要重新录入 + notifyEnrollProcess(ENROLL_PROCESS_INCONSISTENT_FEATURE_AFTER_MERGED); + } +- internalStopEnroll(); + } + + void FPZKDevice::notifyEnrollProcess(EnrollProcess process, const QString& featureID) +diff --git a/src/device/fingerprint/fp-zk-device.h b/src/device/fingerprint/fp-zk-device.h +index 083a6b8..d9a6b2c 100644 +--- a/src/device/fingerprint/fp-zk-device.h ++++ b/src/device/fingerprint/fp-zk-device.h +@@ -30,9 +30,9 @@ public: + explicit FPZKDevice(const QString &vid, const QString &pid, DriverPtr driver,QObject* parent = nullptr); + ~FPZKDevice(); + +- bool initDevice() override; + + private: ++ bool initDevice() override; + QByteArray acquireFeature() override; + // 停止采集指纹模板 + void acquireFeatureStop() override; +@@ -52,7 +52,7 @@ private: + // 对比两枚指纹是否匹配 + int enrollTemplateMatch(QByteArray fpTemplate1, QByteArray fpTemplate2) override; + +- QString identifyFeature(QByteArray fpTemplate, QStringList featureIDs) override; ++ QString identifyFeature(QByteArray fpTemplate, QList existedfeatures) override; + + bool saveFPrintTemplate(QByteArray fpTemplate, const QString& featureID); + +diff --git a/src/device/multi-function/mf-iristar-device.cpp b/src/device/multi-function/mf-iristar-device.cpp +index 7a0ce84..27e1809 100644 +--- a/src/device/multi-function/mf-iristar-device.cpp ++++ b/src/device/multi-function/mf-iristar-device.cpp +@@ -19,6 +19,7 @@ + #include "utils.h" + #include "device/device-creator.h" + #include "config-helper.h" ++#include "feature-db.h" + + namespace Kiran + { +@@ -29,8 +30,6 @@ REGISTER_DEVICE(IRISTAR_DRIVER_NAME,MFIriStarDevice); + MFIriStarDevice::MFIriStarDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent) : + AuthDevice(vid, pid, driver, parent) + { +- setDeviceName(ConfigHelper::getDriverName(vid,pid)); +- + m_driver = driver.dynamicCast(); + m_driver->ref(); + m_driver->setDeviceInfo(vid,pid); +@@ -63,8 +62,10 @@ bool MFIriStarDevice::initDevice() + } + + void MFIriStarDevice::doingEnrollStart(const QString &extraInfo) +-{ +- m_driver->doingEnrollStart(deviceType()); ++{ ++ QList features = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber()); ++ // 注册前需要传入已经存在的特征,判断之前是否注册过 ++ m_driver->doingEnrollStart(deviceType(),features); + QString message; + if (deviceType() == DEVICE_TYPE_Iris) + { +@@ -79,7 +80,7 @@ void MFIriStarDevice::doingEnrollStart(const QString &extraInfo) + + void MFIriStarDevice::doingIdentifyStart(const QString &value) + { +- m_driver->doingIdentifyStart(deviceType(), m_identifyIDs); ++ m_driver->doingIdentifyStart(deviceType(), getFeaturesThatNeedToIdentify()); + QString message; + if (deviceType() == DEVICE_TYPE_Iris) + { +@@ -92,27 +93,14 @@ void MFIriStarDevice::doingIdentifyStart(const QString &value) + m_dbusAdaptor->IdentifyStatus("", ENROLL_STATUS_NORMAL, message); + } + +-void MFIriStarDevice::internalStopEnroll() ++void MFIriStarDevice::deviceStopEnroll() + { +- if (deviceStatus() == DEVICE_STATUS_DOING_ENROLL) +- { +- m_driver->stop(); +- setDeviceStatus(DEVICE_STATUS_IDLE); +- clearWatchedServices(); +- KLOG_DEBUG() << "stop Enroll"; +- } ++ m_driver->stop(); + } + +-void MFIriStarDevice::internalStopIdentify() ++void MFIriStarDevice::deviceStopIdentify() + { +- if (deviceStatus() == DEVICE_STATUS_DOING_IDENTIFY) +- { +- m_driver->stop(); +- m_identifyIDs.clear(); +- setDeviceStatus(DEVICE_STATUS_IDLE); +- clearWatchedServices(); +- KLOG_DEBUG() << "stop Identify"; +- } ++ m_driver->stop(); + } + + void MFIriStarDevice::onEnrollProcess(EnrollProcess process, DeviceType type, const QString &featureID) +diff --git a/src/device/multi-function/mf-iristar-device.h b/src/device/multi-function/mf-iristar-device.h +index c204607..4e04b1c 100644 +--- a/src/device/multi-function/mf-iristar-device.h ++++ b/src/device/multi-function/mf-iristar-device.h +@@ -26,13 +26,12 @@ public: + explicit MFIriStarDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent = nullptr); + ~MFIriStarDevice(); + +- bool initDevice() override; +- + private: ++ bool initDevice() override; + void doingEnrollStart(const QString &extraInfo) override; + void doingIdentifyStart(const QString &value) override; +- void internalStopEnroll() override; +- void internalStopIdentify() override; ++ void deviceStopEnroll() override; ++ void deviceStopIdentify() override; + + void notifyEnrollProcess(EnrollProcess process, const QString &featureID = QString()); + void notifyIdentifyProcess(IdentifyProcess process, const QString &featureID = QString()); +diff --git a/src/device/ukey/ukey-skf-device.cpp b/src/device/ukey/ukey-skf-device.cpp +index 2d7f03d..82bd13d 100644 +--- a/src/device/ukey/ukey-skf-device.cpp ++++ b/src/device/ukey/ukey-skf-device.cpp +@@ -16,27 +16,27 @@ + #include + #include + #include ++#include + #include "auth-enum.h" + #include "auth_device_adaptor.h" ++#include "config-helper.h" ++#include "device/device-creator.h" + #include "feature-db.h" + #include "utils.h" +-#include "device/device-creator.h" +-#include +-#include "config-helper.h" + + namespace Kiran + { +-REGISTER_DEVICE(UKEY_SKF_DRIVER_NAME,UKeySKFDevice); ++REGISTER_DEVICE(UKEY_SKF_DRIVER_NAME, UKeySKFDevice); + + QStringList UKeySKFDevice::m_existingSerialNumber; + + UKeySKFDevice::UKeySKFDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent) : AuthDevice{vid, pid, driver, parent} + { +- //NOTE:并未使用传递进来的DriverPtr ++ // NOTE:并未使用传递进来的DriverPtr + setDeviceType(DEVICE_TYPE_UKey); +- setDriverName(ConfigHelper::getDriverName(vid,pid)); +- m_driverLibPath = ConfigHelper::getLibPath(vid,pid); +- ++ setDriverName(ConfigHelper::getDriverName(vid, pid)); ++ m_driverLibPath = ConfigHelper::getLibPath(vid, pid); ++ + /** + * NOTE: + * UKey设备插入时,设备可能处在未准备好的状态,无法获取到serialNumber +@@ -167,7 +167,7 @@ void UKeySKFDevice::bindingUKey(DEVHANDLE devHandle, const QString &pin) + * 不用保存PublicKey和systemUser的关系,目前只有一个用户 + */ + QByteArray keyFeature; +- keyFeature.append((char *)&publicKey,sizeof(publicKey)); ++ keyFeature.append((char *)&publicKey, sizeof(publicKey)); + KLOG_DEBUG() << "keyFeature:" << keyFeature; + + QString featureID = QCryptographicHash::hash(keyFeature, QCryptographicHash::Md5).toHex(); +@@ -248,30 +248,7 @@ void UKeySKFDevice::doingIdentifyStart(const QString &value) + { + QString message = tr("The pin code cannot be empty!"); + Q_EMIT m_dbusAdaptor->IdentifyStatus("", IDENTIFY_STATUS_NOT_MATCH, message); +- KLOG_ERROR() << message; +- internalStopIdentify(); +- return; +- } +- +- QList saveList; +- DeviceInfo deviceInfo = this->deviceInfo(); +- if (m_identifyIDs.isEmpty()) +- { +- saveList = FeatureDB::getInstance()->getFeatures(deviceInfo.idVendor, deviceInfo.idProduct, deviceType(), deviceSerialNumber()); +- } +- else +- { +- Q_FOREACH (auto id, m_identifyIDs) +- { +- QByteArray feature = FeatureDB::getInstance()->getFeature(id); +- saveList << feature; +- } +- } +- +- if (saveList.count() == 0) +- { +- KLOG_DEBUG() << "no found feature id"; +- notifyUKeyIdentifyProcess(IDENTIFY_PROCESS_NO_MATCH); ++ KLOG_ERROR() << "The pin code cannot be empty!"; + internalStopIdentify(); + return; + } +@@ -284,7 +261,8 @@ void UKeySKFDevice::doingIdentifyStart(const QString &value) + internalStopIdentify(); + return; + } +- ++ ++ QList saveList = getFeaturesThatNeedToIdentify(); + for (int j = 0; j < saveList.count(); j++) + { + auto savedKey = saveList.value(j); +@@ -294,35 +272,22 @@ void UKeySKFDevice::doingIdentifyStart(const QString &value) + internalStopIdentify(); + } + +-void UKeySKFDevice::internalStopEnroll() ++void UKeySKFDevice::deviceStopEnroll() + { +- if (deviceStatus() == DEVICE_STATUS_DOING_ENROLL) ++ if (m_driver) + { +- setDeviceStatus(DEVICE_STATUS_IDLE); +- clearWatchedServices(); +- if (m_driver) +- { +- KLOG_DEBUG() << "delete driver"; +- delete m_driver; +- m_driver = nullptr; +- } +- KLOG_DEBUG() << "stop Enroll"; ++ KLOG_DEBUG() << "delete driver"; ++ delete m_driver; ++ m_driver = nullptr; + } + } + +-void UKeySKFDevice::internalStopIdentify() ++void UKeySKFDevice::deviceStopIdentify() + { +- if (deviceStatus() == DEVICE_STATUS_DOING_IDENTIFY) ++ if (m_driver) + { +- m_identifyIDs.clear(); +- setDeviceStatus(DEVICE_STATUS_IDLE); +- clearWatchedServices(); +- if (m_driver) +- { +- delete m_driver; +- m_driver = nullptr; +- } +- KLOG_DEBUG() << "stopIdentify"; ++ delete m_driver; ++ m_driver = nullptr; + } + } + +diff --git a/src/device/ukey/ukey-skf-device.h b/src/device/ukey/ukey-skf-device.h +index 73d1092..b9628ca 100644 +--- a/src/device/ukey/ukey-skf-device.h ++++ b/src/device/ukey/ukey-skf-device.h +@@ -29,18 +29,18 @@ public: + explicit UKeySKFDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent = nullptr); + ~UKeySKFDevice(); + +- bool initDevice() override; + void resetUkey(); + + private Q_SLOTS: + bool initSerialNumber(); + + private: ++ bool initDevice() override; + void doingEnrollStart(const QString &extraInfo) override; + void doingIdentifyStart(const QString &value) override; + +- void internalStopEnroll() override; +- void internalStopIdentify() override; ++ void deviceStopEnroll() override; ++ void deviceStopIdentify() override; + + void identifyKeyFeature(const QString &pin, QByteArray keyFeature); + +diff --git a/src/driver/multi-function/mf-iristar-driver.cpp b/src/driver/multi-function/mf-iristar-driver.cpp +index b2153a6..7c11d43 100644 +--- a/src/driver/multi-function/mf-iristar-driver.cpp ++++ b/src/driver/multi-function/mf-iristar-driver.cpp +@@ -264,11 +264,13 @@ void MFIriStarDriver::reset() + } + + /** ++ * 开启注册流程,用于获取人脸/虹膜注册特征信息和图像,非阻塞调用。结果数据通过结果回调函数irsResultCallback返回 ++ * 采集数据的特征类型,只支持I/F,其中I表示虹膜,F表示人脸 + * 注册模式:F-人脸 I-双眼 l-单左眼 r-单右眼 + * 识别模式:F-人脸 I-双眼 + * 识别虹膜时不区分单双眼,只传双眼即可;只有W200设备支持注册时选择单双眼,其他设备全部是双眼 + */ +-void MFIriStarDriver::doingEnrollStart(DeviceType deviceType) ++void MFIriStarDriver::doingEnrollStart(DeviceType deviceType, QList existedfeatures) + { + if (deviceType == DEVICE_TYPE_Iris) + { +@@ -283,12 +285,22 @@ void MFIriStarDriver::doingEnrollStart(DeviceType deviceType) + setVideoStream(m_algorithmType.c_str()); + setDeviceStatus(DEVICE_STATUS_DOING_ENROLL); + +- // 开启注册流程,用于获取人脸/虹膜注册特征信息和图像,非阻塞调用。结果数据通过结果回调函数irsResultCallback返回 +- // 采集数据的特征类型,只支持I/F,其中I表示虹膜,F表示人脸 +- int retVal = prepareEnroll(m_algorithmType.c_str()); ++ // 已经存在的特征为空,说明未录入过 ++ if (existedfeatures.count() == 0) ++ { ++ Q_EMIT addFeature(); ++ return; ++ } ++ // 注册前需要开启识别流程判断之前是否注册过 ++ int retVal = startIdentify(existedfeatures); ++ if (retVal == -1) ++ { ++ Q_EMIT addFeature(); ++ return; ++ } + } + +-void MFIriStarDriver::doingIdentifyStart(DeviceType deviceType, QStringList featureIDs) ++void MFIriStarDriver::doingIdentifyStart(DeviceType deviceType, QList features) + { + if (deviceType == DEVICE_TYPE_Iris) + { +@@ -303,7 +315,7 @@ void MFIriStarDriver::doingIdentifyStart(DeviceType deviceType, QStringList feat + setVideoStream(m_algorithmType.c_str()); + setDeviceStatus(DEVICE_STATUS_DOING_IDENTIFY); + +- int retVal = startIdentify(featureIDs); ++ int retVal = startIdentify(features); + + if (retVal != GENERAL_RESULT_OK) + { +@@ -346,56 +358,18 @@ bool MFIriStarDriver::isLoaded() + return m_driverLib->isLoaded; + } + +-int MFIriStarDriver::prepareEnroll(const char *objectType) ++int MFIriStarDriver::startIdentify(QList features) + { +- KLOG_DEBUG() << "prepareEnroll"; +- // 注册前需要开启识别流程判断之前是否注册过 +- int retVal = startIdentify(QStringList()); +- if (retVal == -1) +- { +- KLOG_DEBUG() << "add Feature"; +- Q_EMIT addFeature(); +- } +- return retVal; +-} +- +-int MFIriStarDriver::startIdentify(QStringList featureIDs) +-{ +- KLOG_DEBUG() << "startIdentify"; +- // TODO:这段代码有多处使用,可以提炼复用 +- QList saveList; +- QString featureID; +- +- if (featureIDs.isEmpty()) +- { +- saveList = FeatureDB::getInstance()->getFeatures(m_idVendor, m_idProduct, (DeviceType)m_currentDeviceType, QString()); +- } +- else +- { +- Q_FOREACH (auto id, featureIDs) +- { +- QByteArray feature = FeatureDB::getInstance()->getFeature(id); +- if (!feature.isEmpty()) +- saveList << feature; +- } +- } +- +- if (saveList.count() == 0) +- { +- KLOG_DEBUG() << " no features in the database"; +- return -1; +- } +- + int retVal = 0; +- m_identifyFeatureCache = saveList; ++ m_identifyFeatureCache = features; + // 识别类型,只支持I/F,其中I表示虹膜,F表示人脸 + if (m_algorithmType == ALGORITHM_TYPE_IRIS) + { +- retVal = identifyIris(saveList); ++ retVal = identifyIris(features); + } + else if (m_algorithmType == ALGORITHM_TYPE_FACE) + { +- retVal = identifyFace(saveList); ++ retVal = identifyFace(features); + } + + return retVal; +@@ -480,7 +454,6 @@ void MFIriStarDriver::onStartEnroll() + } + + retVal = m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_START_ENROLL, (void *)m_algorithmType.c_str(), strlen(m_algorithmType.c_str())); +- KLOG_DEBUG() << "IRS_CONTROL_START_ENROLL:" << retVal; + if (retVal != GENERAL_RESULT_OK) + { + KLOG_ERROR() << "start enroll failed:" << retVal; +diff --git a/src/driver/multi-function/mf-iristar-driver.h b/src/driver/multi-function/mf-iristar-driver.h +index 9c7864c..f03035a 100644 +--- a/src/driver/multi-function/mf-iristar-driver.h ++++ b/src/driver/multi-function/mf-iristar-driver.h +@@ -43,8 +43,8 @@ public: + bool initDriver(const QString &libPath = QString()) override; + bool isInitialized() { return m_isInitialized; }; + +- void doingEnrollStart(DeviceType deviceType); +- void doingIdentifyStart(DeviceType deviceType, QStringList featureIDs); ++ void doingEnrollStart(DeviceType deviceType, QList existedfeatures); ++ void doingIdentifyStart(DeviceType deviceType, QList features); + + void stop(); + void setDeviceInfo(const QString &idVendor, const QString &idProduct); +@@ -76,9 +76,7 @@ private: + void handleRecognized(IRS_Results *results); + void handleRecognizingFailed(IRS_Results *results); + +- int prepareEnroll(const char *object); +- +- int startIdentify(QStringList featureIDs); ++ int startIdentify(QList features); + int identifyIris(QList features); + int identifyFace(QList features); + +diff --git a/src/feature-db.cpp b/src/feature-db.cpp +index 6cf8735..fee5aee 100644 +--- a/src/feature-db.cpp ++++ b/src/feature-db.cpp +@@ -77,7 +77,7 @@ bool FeatureDB::createDBConnection() + + if (!query.exec(createTable)) + { +- KLOG_DEBUG() << "query.lastError():" << query.lastError(); ++ KLOG_DEBUG() << "failed to create table in the database:" << query.lastError(); + } + } + return true; +diff --git a/src/utils.cpp b/src/utils.cpp +index 1735ea8..3061263 100644 +--- a/src/utils.cpp ++++ b/src/utils.cpp +@@ -18,7 +18,7 @@ + #include + #include + #include +- ++#include "config.h" + + namespace Kiran + { +@@ -101,32 +101,5 @@ QJsonValue getValueFromJsonString(const QString& json, const QString& key) + return jsonObject.value(key); + } + +-QStringList getDriverBlackList() +-{ +- QSettings confSettings(DRIVER_BLACK_LIST_CONF, QSettings::NativeFormat); +- return confSettings.value(CONF_FILE_DISABLE_DRIVER_NAME).toStringList(); +-} +- +-bool driverEnabled(const QString& driverName) +-{ +- QSettings confSettings(DRIVER_CONF, QSettings::NativeFormat); +- QVariant value = confSettings.value(QString("%1/Enable").arg(driverName)); +- if (value.isValid()) +- { +- if (value.toString() == "false") +- { +- return false; +- } +- else if (value.toString() == "true") +- { +- return true; +- } +- else +- return false; +- } +- else +- return false; +-} +- + } // namespace Utils + } // namespace Kiran +\ No newline at end of file +diff --git a/src/utils.h b/src/utils.h +index d80174b..1c28065 100644 +--- a/src/utils.h ++++ b/src/utils.h +@@ -28,8 +28,5 @@ QString getDeviceName(const QString& idVendor, const QString& idProduct); + + QJsonValue getValueFromJsonString(const QString& json, const QString& key); + +-QStringList getDriverBlackList(); +- +-bool driverEnabled(const QString& driverName); + } // namespace Utils + } // namespace Kiran +diff --git a/ukey-manager/ukey-manager.cpp b/ukey-manager/ukey-manager.cpp +index d815d72..8a4e86e 100644 +--- a/ukey-manager/ukey-manager.cpp ++++ b/ukey-manager/ukey-manager.cpp +@@ -4,6 +4,7 @@ + #include "ukey-skf-driver.h" + #include + #include "auth-enum.h" ++#include "config.h" + + #define DEFAULT_USER_PINCODE "12345678" + +-- +2.33.0 + diff --git a/0004-fix-mf-iristar-driver-when-the-iris-face-integrated-.patch b/0004-fix-mf-iristar-driver-when-the-iris-face-integrated-.patch new file mode 100644 index 0000000000000000000000000000000000000000..e089fe90644f9d577edbf504faedcfdb9bb37e9d --- /dev/null +++ b/0004-fix-mf-iristar-driver-when-the-iris-face-integrated-.patch @@ -0,0 +1,100 @@ +From 444f3d097fa42fbfde53004ffe0404bb31313bac Mon Sep 17 00:00:00 2001 +From: luoqing +Date: Tue, 16 Jan 2024 11:57:08 +0800 +Subject: [PATCH 4/6] fix(mf-iristar-driver):when the iris face integrated + device is removed, the memory cannot be released and the process is + blocked.When the face iris device object is removed, restart the service to + release resources +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 虹膜人脸一体设备在拔出时无法释放内存并且会阻塞进程,当释放人脸虹膜设备对象时,如果当前设备已经被拔出了,就重启服务,释放资源。 + +Related #25243 +--- + .../multi-function/mf-iristar-driver.cpp | 41 +++++++++++++++---- + 1 file changed, 34 insertions(+), 7 deletions(-) + +diff --git a/src/driver/multi-function/mf-iristar-driver.cpp b/src/driver/multi-function/mf-iristar-driver.cpp +index 7c11d43..f65af2d 100644 +--- a/src/driver/multi-function/mf-iristar-driver.cpp ++++ b/src/driver/multi-function/mf-iristar-driver.cpp +@@ -17,12 +17,14 @@ + #include + #include + #include ++#include + #include + #include + #include "auth-enum.h" + #include "auth_device_adaptor.h" + #include "driver/driver-factory.h" + #include "feature-db.h" ++#include "utils.h" + + namespace Kiran + { +@@ -46,6 +48,7 @@ std::function Callback::func; + + #define IRIS_IS_DRIVER_LIB "libirs_sdk2.so" + #define IRIS_IS_STARTUP_CONFIG_PATH "/etc/kiran-authentication-devices-sdk/iristar/config/sdkcfg.ini" ++#define SYSTEMCTL_RESTART_SERVICE "systemctl restart kiran-authentication-devices.service" + + #define IRIS_FEATURE_LEN 512 // 单个虹膜特征数据长度 + #define FACE_FEATURE_LEN 2048 // 单个人脸特征数据长度 +@@ -122,13 +125,18 @@ MFIriStarDriver::MFIriStarDriver(QObject *parent) : Driver{parent} + + MFIriStarDriver::~MFIriStarDriver() + { +- if (m_driverLib->isLoaded && m_irsHandle) +- { +- bool enable = false; +- m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_IRIS_LIGHT, &enable, sizeof(enable)); +- m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_CANCEL_OPR, NULL, 0); // 停止当前正在进行的流程 +- m_driverLib->IRS_releaseInstance(m_irsHandle); +- } ++ KLOG_DEBUG() << "destroy IriStar driver"; ++ /* ++ if (m_driverLib->isLoaded && m_irsHandle ) ++ { ++ KLOG_DEBUG() << "start release IriStar Instance"; ++ bool enable = false; ++ m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_IRIS_LIGHT, &enable, sizeof(enable)); ++ m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_CANCEL_OPR, NULL, 0); // 停止当前正在进行的流程 ++ m_driverLib->IRS_releaseInstance(m_irsHandle); ++ KLOG_DEBUG() << "release IriStar Instance end"; ++ } ++ */ + + if (m_libHandle) + { +@@ -137,6 +145,25 @@ MFIriStarDriver::~MFIriStarDriver() + } + + m_driverLib.clear(); ++ ++ /** ++ * FIXME: ++ * 1、IriStart 设备不支持热插拔 ++ * 当设备拔出后,调用SDK中的IRS_releaseInstance释放资源,IRS_releaseInstance会搜索设备,如果没有搜索到设备,将一直循环搜索设备,导致进程卡死 ++ * 如果设备突然被拔出,则IRS_releaseInstance函数无效且一直无法释放资源,造成内存泄漏 ++ * ++ * 2、注意,即使在设备存在的情况下,调用IRS_releaseInstance 释放资源,也会失败 ++ * 注意,即使在设备存在的情况下,调用IRS_releaseInstance 释放资源,也会失败,在IRS_releaseInstance函数中阻塞 ++ * 查看堆栈,调用关系为 IRS_releaseInstance -> pthread_cond_destroy ,发现最终阻塞在pthread_cond_destroy中 ++ * 查阅资料,pthread_cond_destroy 用来销毁条件变量,但是销毁其他线程正在等待的cond将导致不确定行为,并阻塞。 ++ * 该设备驱动在运行过程中会创建非常多的线程,由于设备SDK提供商对线程操作的不合理,导致了阻塞。 ++ * ++ * 由于不知道驱动SDK的源代码和具体线程操作逻辑,此问题无法修复,只能规避 ++ * 因此,在释放对象时,暂时重启设备管理服务,以释放资源,进行规避 ++ */ ++ KLOG_INFO() << "restart the service, because IriStart device cannot release resources"; ++ QProcess process; ++ process.startDetached(SYSTEMCTL_RESTART_SERVICE); + } + + bool MFIriStarDriver::initDriver(const QString &libPath) +-- +2.33.0 + diff --git a/0005-fix-When-the-driver-is-enabled-the-device-is-scanned.patch b/0005-fix-When-the-driver-is-enabled-the-device-is-scanned.patch new file mode 100644 index 0000000000000000000000000000000000000000..9d81dbb0010fbc777d1e373a6291171f6d89c3e4 --- /dev/null +++ b/0005-fix-When-the-driver-is-enabled-the-device-is-scanned.patch @@ -0,0 +1,386 @@ +From eb1053adb52785aa02992690d5444d4068e0e780 Mon Sep 17 00:00:00 2001 +From: luoqing +Date: Wed, 17 Jan 2024 16:32:34 +0800 +Subject: [PATCH 5/6] fix(*):When the driver is enabled, the device is scanned + and the corresponding device object is created.When the driver is + disabled,the corresponding device object is released. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 启用驱动时,扫描当前设备,创建对应的设备对象;禁用驱动时,释放当前对应的设备对象 + +Close #25387 +--- + include/auth-enum.h | 15 +++- + src/auth-device-manager.cpp | 69 +++++++++++++------ + src/auth-device-manager.h | 1 + + src/config-helper.cpp | 48 +++++++++++++ + src/config-helper.h | 6 +- + src/device/device-creator.cpp | 1 + + src/device/finger-vein/fv-sd-device.cpp | 1 + + src/device/fingerprint/fp-zk-device.cpp | 1 + + .../multi-function/mf-iristar-device.cpp | 2 + + src/device/ukey/ukey-skf-device.cpp | 1 + + src/utils.cpp | 24 +++++++ + src/utils.h | 4 ++ + 12 files changed, 149 insertions(+), 24 deletions(-) + +diff --git a/include/auth-enum.h b/include/auth-enum.h +index b9e9e49..1b663cd 100644 +--- a/include/auth-enum.h ++++ b/include/auth-enum.h +@@ -26,7 +26,7 @@ namespace Kiran + #define UKEY_CONTAINER_NAME "1003-3001" + + #define UKEY_SKF_DRIVER_NAME "ukey-skf" +-#define IRISTAR_DRIVER_NAME "irs_sdk2" ++#define IRISTAR_DRIVER_NAME "irs_sdk2" + #define FINGERPRINT_ZK_DRIVER_NAME "zkfp" + #define FINGER_VEIN_SD_DRIVER_NAME "sdfv" + +@@ -55,6 +55,19 @@ struct DeviceInfo + + return false; + }; ++ ++ bool operator==(const DeviceInfo& dev) const ++ { ++ if (this->idVendor == dev.idVendor && ++ this->idProduct == dev.idProduct) ++ { ++ return true; ++ } ++ else ++ { ++ return false; ++ } ++ } + }; + + enum GeneralResult +diff --git a/src/auth-device-manager.cpp b/src/auth-device-manager.cpp +index a9f5fb0..481caf3 100644 +--- a/src/auth-device-manager.cpp ++++ b/src/auth-device-manager.cpp +@@ -183,43 +183,53 @@ void AuthDeviceManager::onRemove(const QDBusMessage& message, const QString& fea + // TODO:是否需要监听配置文件的改变 + void AuthDeviceManager::onSetEnableDriver(const QDBusMessage& message, const QString& driver_name, bool enable) + { ++ KLOG_DEBUG() << "set driver name:" << driver_name << "enable:" << enable; + QStringList driverList = ConfigHelper::getDriverList(); + QDBusMessage replyMessage; + +- do ++ if (!driverList.contains(driver_name)) + { +- if (!driverList.contains(driver_name)) +- { +- replyMessage = message.createErrorReply(QDBusError::Failed, "No driver with the corresponding name was found."); +- break; +- } +- ConfigHelper::setDriverEnabled(driver_name, enable); +- replyMessage = message.createReply(); ++ replyMessage = message.createErrorReply(QDBusError::Failed, "No driver with the corresponding name was found."); ++ QDBusConnection::systemBus().send(replyMessage); ++ return; ++ } ++ ++ bool oldDriverStatus = ConfigHelper::driverEnabled(driver_name); + +- if (enable) ++ ConfigHelper::setDriverEnabled(driver_name, enable); ++ replyMessage = message.createReply(); ++ QDBusConnection::systemBus().send(replyMessage); ++ ++ // 若之前驱动已经关闭,启用驱动后,遍历设备,加载可用的设备 ++ if (enable && !oldDriverStatus) ++ { ++ //NOTE:注意,此处是从配置文件中读出所支持的Vid和Pid,获取不到所支持的设备的BusPath,因此这里返回的DeviceInfo的BusPath为空 ++ QList devices = ConfigHelper::getDeviceIDsSupportedByDriver(driver_name); ++ for (auto device : devices) + { +- break; ++ if(!Utils::isExistDevice(device.idVendor,device.idProduct)) ++ { ++ continue; ++ } ++ device.busPath = Utils::getBusPath(device.idVendor,device.idProduct); ++ handleDeviceAdded(device); + } ++ return; ++ } + +- // 驱动被禁用,将当前正在使用的设备释放掉 ++ // 若之前驱动开启,现在关闭驱动,将当前正在使用的设备释放掉 ++ if (!enable && oldDriverStatus) ++ { + auto devices = m_deviceMap.values(); +- Q_FOREACH (AuthDevicePtr device, devices) ++ for (AuthDevicePtr device : devices) + { + if (device->driverName() != driver_name) + { + continue; + } +- QString deviceID = device->deviceID(); +- int deviceType = device->deviceType(); +- device->deleteLater(); +- QString key = m_deviceMap.key(device); +- m_deviceMap.remove(key); +- Q_EMIT m_dbusAdaptor->DeviceDeleted(deviceType, deviceID); +- KLOG_INFO() << QString("destroyed deviceType: %1, deviceID:%2").arg(deviceType).arg(deviceID); ++ removeDevice(device); + } +- } while (false); +- +- QDBusConnection::systemBus().send(replyMessage); ++ } + } + + AuthDeviceList AuthDeviceManager::createDevices(const DeviceInfo& deviceInfo) +@@ -258,6 +268,21 @@ AuthDeviceList AuthDeviceManager::createDevices(const DeviceInfo& deviceInfo) + return deviceList; + } + ++void AuthDeviceManager::removeDevice(QSharedPointer device) ++{ ++ QString deviceID = device->deviceID(); ++ int deviceType = device->deviceType(); ++ QString deviceName = device->driverName(); ++ ++ QString key = m_deviceMap.key(device); ++ int count = m_deviceMap.remove(key); ++ KLOG_DEBUG() << "remove device count:" << count; ++ ++ device->deleteLater(); ++ Q_EMIT m_dbusAdaptor->DeviceDeleted(deviceType, deviceID); ++ KLOG_INFO() << QString("destroyed deviceName: %1 , bus path : %2 , deviceType: %3, deviceID:%4").arg(deviceName).arg(key).arg(deviceType).arg(deviceID); ++} ++ + CHECK_AUTH_WITH_1ARGS(AuthDeviceManager, Remove, onRemove, AUTH_USER_ADMIN, const QString&) + CHECK_AUTH_WITH_2ARGS(AuthDeviceManager, SetEnableDriver, onSetEnableDriver, AUTH_USER_ADMIN, const QString&, bool) + +diff --git a/src/auth-device-manager.h b/src/auth-device-manager.h +index 95e68e9..150a372 100644 +--- a/src/auth-device-manager.h ++++ b/src/auth-device-manager.h +@@ -62,6 +62,7 @@ private: + void onRemove(const QDBusMessage &message, const QString &feature_id); + void onSetEnableDriver(const QDBusMessage &message, const QString &driver_name, bool enable); + QList> createDevices(const DeviceInfo &deviceInfo); ++ void removeDevice(QSharedPointer device); + + private: + static AuthDeviceManager *m_instance; +diff --git a/src/config-helper.cpp b/src/config-helper.cpp +index 8fc5a47..880296b 100644 +--- a/src/config-helper.cpp ++++ b/src/config-helper.cpp +@@ -113,6 +113,18 @@ bool ConfigHelper::driverEnabled(const QString &vid, const QString &pid) + return enable; + } + ++bool ConfigHelper::driverEnabled(const QString &driverName) ++{ ++ bool enable = false; ++ QSettings confSettings(DRIVER_CONF, QSettings::NativeFormat); ++ QStringList driverList = confSettings.childGroups(); ++ if (driverList.contains(driverName)) ++ { ++ enable = confSettings.value(QString("%1/Enable").arg(driverName)).toBool(); ++ } ++ return enable; ++} ++ + void ConfigHelper::setDriverEnabled(const QString &driverName, bool enable) + { + QSettings confSettings(DRIVER_CONF, QSettings::NativeFormat); +@@ -147,4 +159,40 @@ bool ConfigHelper::isDeviceSupported(const QString &vid, const QString &pid) + return false; + } + ++QList ConfigHelper::getDeviceIDsSupportedByDriver(const QString &driverName) ++{ ++ QList deviceInfos; ++ ++ QSettings confSettings(DEVICE_CONF, QSettings::NativeFormat); ++ QStringList deviceList = confSettings.childGroups(); ++ for (auto deviceConf : deviceList) ++ { ++ confSettings.beginGroup(deviceConf); ++ if (confSettings.value("Driver").toString() != driverName) ++ { ++ confSettings.endGroup(); ++ continue; ++ } ++ ++ QStringList idList = confSettings.value("Id").toStringList(); ++ for (const QString &id : idList) ++ { ++ QStringList idItems = id.split(":"); ++ if (idItems.count() != 2) ++ { ++ continue; ++ } ++ ++ DeviceInfo deviceinfo; ++ deviceinfo.idVendor = idItems.value(0); ++ deviceinfo.idProduct = idItems.value(1); ++ ++ deviceInfos << deviceinfo; ++ } ++ confSettings.endGroup(); ++ } ++ ++ return deviceInfos; ++} ++ + } // namespace Kiran +\ No newline at end of file +diff --git a/src/config-helper.h b/src/config-helper.h +index 91cf895..0e1a5f5 100644 +--- a/src/config-helper.h ++++ b/src/config-helper.h +@@ -13,6 +13,7 @@ + */ + #pragma once + #include ++#include "auth-enum.h" + + namespace Kiran + { +@@ -50,9 +51,12 @@ public: + static QStringList getDriverList(); + + static bool driverEnabled(const QString &vid, const QString &pid); ++ static bool driverEnabled(const QString & driverName); ++ + static void setDriverEnabled(const QString& driverName, bool enable); + static bool isDeviceSupported(const QString &vid, const QString &pid); +- ++ ++ static QList getDeviceIDsSupportedByDriver(const QString& driverName); + private: + }; + +diff --git a/src/device/device-creator.cpp b/src/device/device-creator.cpp +index 1fb760f..90ea201 100644 +--- a/src/device/device-creator.cpp ++++ b/src/device/device-creator.cpp +@@ -45,6 +45,7 @@ DeviceCereator::~DeviceCereator() + { + } + ++//TODO:将设备的BusPath作为入參创建设备,处理存在多个一模一样(vid和pid相同)的设备同时存在的场景 + AuthDeviceList DeviceCereator::createDevices(const QString &vid, const QString &pid, DriverPtr driver) + { + AuthDeviceList deviceList; +diff --git a/src/device/finger-vein/fv-sd-device.cpp b/src/device/finger-vein/fv-sd-device.cpp +index 442f227..80ca4be 100644 +--- a/src/device/finger-vein/fv-sd-device.cpp ++++ b/src/device/finger-vein/fv-sd-device.cpp +@@ -42,6 +42,7 @@ FVSDDevice::FVSDDevice(const QString &vid, const QString &pid, DriverPtr driver, + + FVSDDevice::~FVSDDevice() + { ++ KLOG_DEBUG() << "destroy FVSD Device"; + if (m_driver->isLoaded()) + { + acquireFeatureStop(); +diff --git a/src/device/fingerprint/fp-zk-device.cpp b/src/device/fingerprint/fp-zk-device.cpp +index 3a818f3..659e9ab 100644 +--- a/src/device/fingerprint/fp-zk-device.cpp ++++ b/src/device/fingerprint/fp-zk-device.cpp +@@ -49,6 +49,7 @@ FPZKDevice::FPZKDevice(const QString& vid, const QString& pid, DriverPtr driver, + // 析构时对设备进行资源回收 + FPZKDevice::~FPZKDevice() + { ++ KLOG_DEBUG() << "destroy FPZK Device"; + acquireFeatureStop(); + + if (m_driver->isLoaded()) +diff --git a/src/device/multi-function/mf-iristar-device.cpp b/src/device/multi-function/mf-iristar-device.cpp +index 27e1809..58ed89c 100644 +--- a/src/device/multi-function/mf-iristar-device.cpp ++++ b/src/device/multi-function/mf-iristar-device.cpp +@@ -33,6 +33,7 @@ MFIriStarDevice::MFIriStarDevice(const QString &vid, const QString &pid, DriverP + m_driver = driver.dynamicCast(); + m_driver->ref(); + m_driver->setDeviceInfo(vid,pid); ++ setDriverName(IRISTAR_DRIVER_NAME); + + qRegisterMetaType("EnrollProcess"); + qRegisterMetaType("IdentifyProcess"); +@@ -44,6 +45,7 @@ MFIriStarDevice::MFIriStarDevice(const QString &vid, const QString &pid, DriverP + + MFIriStarDevice::~MFIriStarDevice() + { ++ KLOG_DEBUG() << "destroy MFIriStar Device"; + m_driver->unref(); + if (m_driver->refCount() <= 0) + { +diff --git a/src/device/ukey/ukey-skf-device.cpp b/src/device/ukey/ukey-skf-device.cpp +index 82bd13d..c8feb7b 100644 +--- a/src/device/ukey/ukey-skf-device.cpp ++++ b/src/device/ukey/ukey-skf-device.cpp +@@ -51,6 +51,7 @@ UKeySKFDevice::UKeySKFDevice(const QString &vid, const QString &pid, DriverPtr d + + UKeySKFDevice::~UKeySKFDevice() + { ++ KLOG_DEBUG() << "destroy UKey SKF Device"; + int index = m_existingSerialNumber.indexOf(deviceSerialNumber()); + m_existingSerialNumber.removeAt(index); + KLOG_DEBUG() << "destory device, serialNumber:" << deviceSerialNumber(); +diff --git a/src/utils.cpp b/src/utils.cpp +index 3061263..0e11b04 100644 +--- a/src/utils.cpp ++++ b/src/utils.cpp +@@ -101,5 +101,29 @@ QJsonValue getValueFromJsonString(const QString& json, const QString& key) + return jsonObject.value(key); + } + ++bool isExistDevice(const QString& idVendor, const QString& idProduct) ++{ ++ DeviceInfo deviceInfo; ++ deviceInfo.idVendor = idVendor; ++ deviceInfo.idProduct = idProduct; ++ deviceInfo.busPath = ""; ++ QList devices = enumerateDevices(); ++ return devices.contains(deviceInfo); ++} ++ ++QString getBusPath(const QString& idVendor, const QString& idProduct) ++{ ++ QList devices = enumerateDevices(); ++ for (auto device : devices) ++ { ++ if (device.idVendor == idVendor && ++ device.idProduct == idProduct) ++ { ++ return device.busPath; ++ } ++ } ++ return QString(); ++} ++ + } // namespace Utils + } // namespace Kiran +\ No newline at end of file +diff --git a/src/utils.h b/src/utils.h +index 1c28065..9ba5598 100644 +--- a/src/utils.h ++++ b/src/utils.h +@@ -28,5 +28,9 @@ QString getDeviceName(const QString& idVendor, const QString& idProduct); + + QJsonValue getValueFromJsonString(const QString& json, const QString& key); + ++bool isExistDevice(const QString& idVendor, const QString& idProduct); ++ ++QString getBusPath(const QString& idVendor, const QString& idProduct); ++ + } // namespace Utils + } // namespace Kiran +-- +2.33.0 + diff --git a/0006-fix-build-fix-file-install-path-error.patch b/0006-fix-build-fix-file-install-path-error.patch new file mode 100644 index 0000000000000000000000000000000000000000..06239dbc6651d520128003d2eabce587384d7a95 --- /dev/null +++ b/0006-fix-build-fix-file-install-path-error.patch @@ -0,0 +1,29 @@ +From a0488124de99b326d9abc38228251146ed6cdc6d Mon Sep 17 00:00:00 2001 +From: luoqing +Date: Thu, 18 Jan 2024 11:25:40 +0800 +Subject: [PATCH 6/6] fix(build):fix file install path error +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +- 修复文件安装路径错误 +--- + data/CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt +index 617cd14..a6ae20b 100644 +--- a/data/CMakeLists.txt ++++ b/data/CMakeLists.txt +@@ -11,7 +11,7 @@ endif() + file(GLOB CONF_FILES ${PROJECT_SOURCE_DIR}/data/com*.conf) + + foreach(CONF_FILE IN LISTS CONF_FILES) +- install(FILES ${CONF_FILE} DESTINATION ${SYSCONFDIR}/dbus-1/system.d) ++ install(FILES ${CONF_FILE} DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/dbus-1/system.d) + endforeach() + + configure_file(kiran-authentication-devices.service.in +-- +2.33.0 + diff --git a/kiran-authentication-devices.spec b/kiran-authentication-devices.spec index 7e7135d53c0a0726cfe4f0e15b9e2f67512c1405..627aa85fd80ad85757be8b690c8e0a95e07fa6b2 100644 --- a/kiran-authentication-devices.spec +++ b/kiran-authentication-devices.spec @@ -1,13 +1,18 @@ Name: kiran-authentication-devices Version: 2.5.2 -Release: 2 +Release: 3 Summary: Kiran Authentication Devices License: MulanPSL-2.0 Source0: %{name}-%{version}.tar.gz Patch0001: 0001-fix-kiran-authentication-devices-fix-QUuid-WithoutBr.patch +Patch0002: 0002-fix-ukey-manager-Fixed-a-crash-caused-by-repeatedly-.patch +Patch0003: 0003-refactor-Modify-the-code-according-to-the-https-gite.patch +Patch0004: 0004-fix-mf-iristar-driver-when-the-iris-face-integrated-.patch +Patch0005: 0005-fix-When-the-driver-is-enabled-the-device-is-scanned.patch +Patch0006: 0006-fix-build-fix-file-install-path-error.patch BuildRequires: cmake BuildRequires: gcc-c++ @@ -66,6 +71,13 @@ systemctl enable kiran-authentication-devices.service rm -rf ${buildroot} %changelog +* Thu Jan 18 2024 luoqing - 2.5.2-3 +- KYOS-B: Fixed a crash caused by repeatedly calling disConnectDev in resetUkey and destructor to release the same device handle +- KYOS-R: Modify the code according to the https://gitee.com/openeuler/kiran-authentication-devices/pulls/17 review opinions +- KYOS-B: when the iris face integrated device is removed, the memory cannot be released and the process is blocked.When the face iris device object is removed, restart the service to release resources (#25243) +- KYOS-B: When the driver is enabled, the device is scanned and the corresponding device object is created.When the driver is disabled,the corresponding device object is released. (#25387) +- KYOS-B: fix file install path error + * Thu Sep 7 2023 yinhongchang - 2.5.2-2 - KYOS-F: fix QUuid::WithoutBraces for qt low version