From c9dbf3793f4d45dc43ea5eef10d84113d85c348c Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 13 Apr 2026 17:23:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CanUds.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/CanUds.c b/CanUds.c index ecefb4c..96ae502 100644 --- a/CanUds.c +++ b/CanUds.c @@ -63,6 +63,46 @@ static void PrintfDebug(uint8_t *data, uint8_t dlc) { } +// Проверка валидности BCD +static bool is_valid_bcd(uint8_t value) { + return ((value & 0x0F) <= 9) && ((value >> 4) <= 9); +} + +// Проверка года +static bool is_valid_year(uint8_t year) { + return is_valid_bcd(year); // 0x00-0x99 +} + +// Проверка месяца +static bool is_valid_month(uint8_t month) { + if (!is_valid_bcd(month)) return false; + uint8_t m = ((month >> 4) * 10) + (month & 0x0F); + return (m >= 1 && m <= 12); +} + +// Проверка дня (с учетом месяца и года) +static bool is_valid_day(uint8_t year, uint8_t month, uint8_t day) { + if (!is_valid_bcd(day)) return false; + + uint8_t y = ((year >> 4) * 10) + (year & 0x0F); + uint8_t m = ((month >> 4) * 10) + (month & 0x0F); + uint8_t d = ((day >> 4) * 10) + (day & 0x0F); + + if (d < 1) return false; + + // Дни в месяцах + uint8_t days_in_month[] = {31, 28, 31, 30, 31, 30, + 31, 31, 30, 31, 30, 31}; + + // Проверка на високосный год + if (m == 2) { + bool is_leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0); + return d <= (is_leap ? 29 : 28); + } + + return d <= days_in_month[m - 1]; +} + static bool isSecurityAccessDenied(tCanUds *env, tPermissionSession isPermissionSession) { bool result = false; @@ -375,6 +415,17 @@ static uint16_t WriteDataByIdentifier_2E(tCanUds *env) { env->dataResponse[0] = UDS_WriteDataByIdentifier | 0b1000000; env->dataResponse[1] = dataIdentifier_hi; env->dataResponse[2] = dataIdentifier_lo; + + // CCU_Configuration + if (dataIdentifier_lo == 0) { + tStatus_CCU_Configuration *CCU_Configuration = (tStatus_CCU_Configuration *) &env->data.data[4]; + if ((CCU_Configuration->AromaConfiguration > 1) || (CCU_Configuration->AlgorithmConfiguration > 1) || + (CCU_Configuration->RearHVACConfiguration > 1)) { + return setResponseError(env, UDS_WriteDataByIdentifier, + UDS_error_requestOutOfRange); + } + } + memcpy(uds_WriteDataByIdentifier_2E_com_CF[dataIdentifier_lo].data, &env->data.data[3], size); SaveToStorageFromStatusData(env->deviceStorage, &statusData.ecu); @@ -407,6 +458,17 @@ static uint16_t WriteDataByIdentifier_2E(tCanUds *env) { env->dataResponse[0] = UDS_WriteDataByIdentifier | 0b1000000; env->dataResponse[1] = dataIdentifier_hi; env->dataResponse[2] = dataIdentifier_lo; + + + // Tester_Fingerprint + if (dataIdentifier_lo == 0x5A) { + tFingerprint *fingerprint = (tFingerprint *) &env->data.data[4]; + if (is_valid_day(fingerprint->year, fingerprint->month, fingerprint->day) == false) { + return setResponseError(env, UDS_WriteDataByIdentifier, + UDS_error_requestOutOfRange); + } + } + memcpy(uds_WriteDataByIdentifier_2E_com_F1[dataIdentifier_lo].data, &env->data.data[3], size); SaveToStorageFromStatusData(env->deviceStorage, &statusData.ecu);