| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "safety_declarations.h" | ||
| 4 | #include "safety_hyundai_common.h" | ||
| 5 | |||
| 6 | #define HYUNDAI_CANFD_CRUISE_BUTTON_TX_MSGS(bus) \ | ||
| 7 | {0x1CF, bus, 8}, /* CRUISE_BUTTON */ \ | ||
| 8 | |||
| 9 | #define HYUNDAI_CANFD_LKA_STEERING_COMMON_TX_MSGS(a_can, e_can) \ | ||
| 10 | HYUNDAI_CANFD_CRUISE_BUTTON_TX_MSGS(e_can) \ | ||
| 11 | {0x50, a_can, 16}, /* LKAS */ \ | ||
| 12 | {0x2A4, a_can, 24}, /* CAM_0x2A4 */ \ | ||
| 13 | |||
| 14 | #define HYUNDAI_CANFD_LKA_STEERING_ALT_COMMON_TX_MSGS(a_can, e_can) \ | ||
| 15 | HYUNDAI_CANFD_CRUISE_BUTTON_TX_MSGS(e_can) \ | ||
| 16 | {0x110, a_can, 32}, /* LKAS_ALT */ \ | ||
| 17 | {0x362, a_can, 32}, /* CAM_0x362 */ \ | ||
| 18 | |||
| 19 | #define HYUNDAI_CANFD_LFA_STEERING_COMMON_TX_MSGS(e_can) \ | ||
| 20 | {0x12A, e_can, 16}, /* LFA */ \ | ||
| 21 | {0x1E0, e_can, 16}, /* LFAHDA_CLUSTER */ \ | ||
| 22 | |||
| 23 | #define HYUNDAI_CANFD_SCC_CONTROL_COMMON_TX_MSGS(e_can) \ | ||
| 24 | {0x1A0, e_can, 32}, /* SCC_CONTROL */ \ | ||
| 25 | |||
| 26 | // *** Addresses checked in rx hook *** | ||
| 27 | // EV, ICE, HYBRID: ACCELERATOR (0x35), ACCELERATOR_BRAKE_ALT (0x100), ACCELERATOR_ALT (0x105) | ||
| 28 | #define HYUNDAI_CANFD_COMMON_RX_CHECKS(pt_bus) \ | ||
| 29 | {.msg = {{0x35, (pt_bus), 32, .check_checksum = true, .max_counter = 0xffU, .frequency = 100U}, \ | ||
| 30 | {0x100, (pt_bus), 32, .check_checksum = true, .max_counter = 0xffU, .frequency = 100U}, \ | ||
| 31 | {0x105, (pt_bus), 32, .check_checksum = true, .max_counter = 0xffU, .frequency = 100U}}}, \ | ||
| 32 | {.msg = {{0x175, (pt_bus), 24, .check_checksum = true, .max_counter = 0xffU, .frequency = 50U}, { 0 }, { 0 }}}, \ | ||
| 33 | {.msg = {{0xa0, (pt_bus), 24, .check_checksum = true, .max_counter = 0xffU, .frequency = 100U}, { 0 }, { 0 }}}, \ | ||
| 34 | {.msg = {{0xea, (pt_bus), 24, .check_checksum = true, .max_counter = 0xffU, .frequency = 100U}, { 0 }, { 0 }}}, \ | ||
| 35 | {.msg = {{0x1cf, (pt_bus), 8, .check_checksum = false, .max_counter = 0xfU, .frequency = 50U}, \ | ||
| 36 | {0x1aa, (pt_bus), 16, .check_checksum = false, .max_counter = 0xffU, .frequency = 50U}, { 0 }}}, \ | ||
| 37 | |||
| 38 | // SCC_CONTROL (from ADAS unit or camera) | ||
| 39 | #define HYUNDAI_CANFD_SCC_ADDR_CHECK(scc_bus) \ | ||
| 40 | {.msg = {{0x1a0, (scc_bus), 32, .check_checksum = true, .max_counter = 0xffU, .frequency = 50U}, { 0 }, { 0 }}}, \ | ||
| 41 | |||
| 42 | static bool hyundai_canfd_alt_buttons = false; | ||
| 43 | static bool hyundai_canfd_lka_steering_alt = false; | ||
| 44 | |||
| 45 | 184479 | static int hyundai_canfd_get_lka_addr(void) { | |
| 46 |
2/2✓ Branch 0 taken 57822 times.
✓ Branch 1 taken 126657 times.
|
184479 | return hyundai_canfd_lka_steering_alt ? 0x110 : 0x50; |
| 47 | } | ||
| 48 | |||
| 49 | 137013 | static uint8_t hyundai_canfd_get_counter(const CANPacket_t *to_push) { | |
| 50 | 137013 | uint8_t ret = 0; | |
| 51 |
2/2✓ Branch 0 taken 6692 times.
✓ Branch 1 taken 130321 times.
|
137013 | if (GET_LEN(to_push) == 8U) { |
| 52 | 6692 | ret = GET_BYTE(to_push, 1) >> 4; | |
| 53 | } else { | ||
| 54 | 130321 | ret = GET_BYTE(to_push, 2); | |
| 55 | } | ||
| 56 | 137013 | return ret; | |
| 57 | } | ||
| 58 | |||
| 59 | 129355 | static uint32_t hyundai_canfd_get_checksum(const CANPacket_t *to_push) { | |
| 60 | 129355 | uint32_t chksum = GET_BYTE(to_push, 0) | (GET_BYTE(to_push, 1) << 8); | |
| 61 | 129355 | return chksum; | |
| 62 | } | ||
| 63 | |||
| 64 | 314407 | static void hyundai_canfd_rx_hook(const CANPacket_t *to_push) { | |
| 65 | 314407 | int bus = GET_BUS(to_push); | |
| 66 | 314407 | int addr = GET_ADDR(to_push); | |
| 67 | |||
| 68 | 314407 | const int pt_bus = hyundai_canfd_lka_steering ? 1 : 0; | |
| 69 |
2/2✓ Branch 0 taken 134745 times.
✓ Branch 1 taken 179662 times.
|
314407 | const int scc_bus = hyundai_camera_scc ? 2 : pt_bus; |
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 195715 times.
✓ Branch 1 taken 118692 times.
|
314407 | if (bus == pt_bus) { |
| 72 | // driver torque | ||
| 73 |
2/2✓ Branch 0 taken 127785 times.
✓ Branch 1 taken 67930 times.
|
195715 | if (addr == 0xea) { |
| 74 | 127785 | int torque_driver_new = ((GET_BYTE(to_push, 11) & 0x1fU) << 8U) | GET_BYTE(to_push, 10); | |
| 75 | 127785 | torque_driver_new -= 4095; | |
| 76 | 127785 | update_sample(&torque_driver, torque_driver_new); | |
| 77 | } | ||
| 78 | |||
| 79 | // cruise buttons | ||
| 80 |
2/2✓ Branch 0 taken 54747 times.
✓ Branch 1 taken 140968 times.
|
195715 | const int button_addr = hyundai_canfd_alt_buttons ? 0x1aa : 0x1cf; |
| 81 |
2/2✓ Branch 0 taken 7658 times.
✓ Branch 1 taken 188057 times.
|
195715 | if (addr == button_addr) { |
| 82 | 7658 | bool main_button = false; | |
| 83 | 7658 | int cruise_button = 0; | |
| 84 |
2/2✓ Branch 0 taken 6686 times.
✓ Branch 1 taken 972 times.
|
7658 | if (addr == 0x1cf) { |
| 85 | 6686 | cruise_button = GET_BYTE(to_push, 2) & 0x7U; | |
| 86 | 6686 | main_button = GET_BIT(to_push, 19U); | |
| 87 | } else { | ||
| 88 | 972 | cruise_button = (GET_BYTE(to_push, 4) >> 4) & 0x7U; | |
| 89 | 972 | main_button = GET_BIT(to_push, 34U); | |
| 90 | } | ||
| 91 | 7658 | hyundai_common_cruise_buttons_check(cruise_button, main_button); | |
| 92 | } | ||
| 93 | |||
| 94 | // gas press, different for EV, hybrid, and ICE models | ||
| 95 |
4/4✓ Branch 0 taken 111 times.
✓ Branch 1 taken 195604 times.
✓ Branch 2 taken 99 times.
✓ Branch 3 taken 12 times.
|
195715 | if ((addr == 0x35) && hyundai_ev_gas_signal) { |
| 96 | 99 | gas_pressed = GET_BYTE(to_push, 5) != 0U; | |
| 97 |
4/4✓ Branch 0 taken 81 times.
✓ Branch 1 taken 195535 times.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 15 times.
|
195616 | } else if ((addr == 0x105) && hyundai_hybrid_gas_signal) { |
| 98 |
4/6✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 36 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 30 times.
|
66 | gas_pressed = GET_BIT(to_push, 103U) || (GET_BYTE(to_push, 13) != 0U) || GET_BIT(to_push, 112U); |
| 99 |
6/6✓ Branch 0 taken 81 times.
✓ Branch 1 taken 195469 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 66 times.
✓ Branch 5 taken 6 times.
|
195550 | } else if ((addr == 0x100) && !hyundai_ev_gas_signal && !hyundai_hybrid_gas_signal) { |
| 100 | 66 | gas_pressed = GET_BIT(to_push, 176U); | |
| 101 | } else { | ||
| 102 | } | ||
| 103 | |||
| 104 | // brake press | ||
| 105 |
2/2✓ Branch 0 taken 273 times.
✓ Branch 1 taken 195442 times.
|
195715 | if (addr == 0x175) { |
| 106 | 273 | brake_pressed = GET_BIT(to_push, 81U); | |
| 107 | } | ||
| 108 | |||
| 109 | // vehicle moving | ||
| 110 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 195547 times.
|
195715 | if (addr == 0xa0) { |
| 111 | 168 | uint32_t front_left_speed = GET_BYTES(to_push, 8, 2); | |
| 112 | 168 | uint32_t rear_right_speed = GET_BYTES(to_push, 14, 2); | |
| 113 |
3/4✓ Branch 0 taken 126 times.
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 126 times.
|
168 | vehicle_moving = (front_left_speed > HYUNDAI_STANDSTILL_THRSLD) || (rear_right_speed > HYUNDAI_STANDSTILL_THRSLD); |
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 |
2/2✓ Branch 0 taken 137842 times.
✓ Branch 1 taken 176565 times.
|
314407 | if (bus == scc_bus) { |
| 118 | // cruise state | ||
| 119 |
4/4✓ Branch 0 taken 1007 times.
✓ Branch 1 taken 136835 times.
✓ Branch 2 taken 996 times.
✓ Branch 3 taken 11 times.
|
137842 | if ((addr == 0x1a0) && !hyundai_longitudinal) { |
| 120 | // 1=enabled, 2=driver override | ||
| 121 | 996 | int cruise_status = ((GET_BYTE(to_push, 8) >> 4) & 0x7U); | |
| 122 |
3/4✓ Branch 0 taken 512 times.
✓ Branch 1 taken 484 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 512 times.
|
996 | bool cruise_engaged = (cruise_status == 1) || (cruise_status == 2); |
| 123 | 996 | hyundai_common_cruise_state_check(cruise_engaged); | |
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 |
2/2✓ Branch 0 taken 44917 times.
✓ Branch 1 taken 269490 times.
|
314407 | const int steer_addr = hyundai_canfd_lka_steering ? hyundai_canfd_get_lka_addr() : 0x12a; |
| 128 |
4/4✓ Branch 0 taken 63 times.
✓ Branch 1 taken 314344 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 42 times.
|
314407 | bool stock_ecu_detected = (addr == steer_addr) && (bus == 0); |
| 129 |
2/2✓ Branch 0 taken 107317 times.
✓ Branch 1 taken 207090 times.
|
314407 | if (hyundai_longitudinal) { |
| 130 | // on LKA steering cars, ensure ADRV ECU is still knocked out | ||
| 131 | // on others, ensure accel msg is blocked from camera | ||
| 132 |
6/6✓ Branch 0 taken 107310 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 107282 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 14 times.
|
107317 | stock_ecu_detected = stock_ecu_detected || ((addr == 0x1a0) && (bus == pt_bus)); |
| 133 | } | ||
| 134 | 314407 | generic_rx_checks(stock_ecu_detected); | |
| 135 | 314407 | } | |
| 136 | |||
| 137 | 848693 | static bool hyundai_canfd_tx_hook(const CANPacket_t *to_send) { | |
| 138 | const SteeringLimits HYUNDAI_CANFD_STEERING_LIMITS = { | ||
| 139 | .max_steer = 270, | ||
| 140 | .max_rt_delta = 112, | ||
| 141 | .max_rt_interval = 250000, | ||
| 142 | .max_rate_up = 2, | ||
| 143 | .max_rate_down = 3, | ||
| 144 | .driver_torque_allowance = 250, | ||
| 145 | .driver_torque_multiplier = 2, | ||
| 146 | .type = TorqueDriverLimited, | ||
| 147 | |||
| 148 | // the EPS faults when the steering angle is above a certain threshold for too long. to prevent this, | ||
| 149 | // we allow setting torque actuation bit to 0 while maintaining the requested torque value for two consecutive frames | ||
| 150 | .min_valid_request_frames = 89, | ||
| 151 | .max_invalid_request_frames = 2, | ||
| 152 | .min_valid_request_rt_interval = 810000, // 810ms; a ~10% buffer on cutting every 90 frames | ||
| 153 | .has_steer_req_tolerance = true, | ||
| 154 | }; | ||
| 155 | |||
| 156 | 848693 | bool tx = true; | |
| 157 | 848693 | int addr = GET_ADDR(to_send); | |
| 158 | |||
| 159 | // steering | ||
| 160 |
4/4✓ Branch 0 taken 121247 times.
✓ Branch 1 taken 727446 times.
✓ Branch 2 taken 80426 times.
✓ Branch 3 taken 40821 times.
|
848693 | const int steer_addr = (hyundai_canfd_lka_steering && !hyundai_longitudinal) ? hyundai_canfd_get_lka_addr() : 0x12a; |
| 161 |
2/2✓ Branch 0 taken 844326 times.
✓ Branch 1 taken 4367 times.
|
848693 | if (addr == steer_addr) { |
| 162 | 844326 | int desired_torque = (((GET_BYTE(to_send, 6) & 0xFU) << 7U) | (GET_BYTE(to_send, 5) >> 1U)) - 1024U; | |
| 163 | 844326 | bool steer_req = GET_BIT(to_send, 52U); | |
| 164 | |||
| 165 |
2/2✓ Branch 1 taken 445410 times.
✓ Branch 2 taken 398916 times.
|
844326 | if (steer_torque_cmd_checks(desired_torque, steer_req, HYUNDAI_CANFD_STEERING_LIMITS)) { |
| 166 | 445410 | tx = false; | |
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | // cruise buttons check | ||
| 171 |
2/2✓ Branch 0 taken 87 times.
✓ Branch 1 taken 848606 times.
|
848693 | if (addr == 0x1cf) { |
| 172 | 87 | int button = GET_BYTE(to_send, 2) & 0x7U; | |
| 173 | 87 | bool is_cancel = (button == HYUNDAI_BTN_CANCEL); | |
| 174 | 87 | bool is_resume = (button == HYUNDAI_BTN_RESUME); | |
| 175 | |||
| 176 |
8/8✓ Branch 0 taken 16 times.
✓ Branch 1 taken 71 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 63 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 8 times.
|
87 | bool allowed = (is_cancel && cruise_engaged_prev) || (is_resume && controls_allowed); |
| 177 |
2/2✓ Branch 0 taken 71 times.
✓ Branch 1 taken 16 times.
|
87 | if (!allowed) { |
| 178 | 71 | tx = false; | |
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | // UDS: only tester present ("\x02\x3E\x80\x00\x00\x00\x00\x00") allowed on diagnostics address | ||
| 183 |
6/8✓ Branch 0 taken 4 times.
✓ Branch 1 taken 848689 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 848671 times.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
|
848693 | if (((addr == 0x730) && hyundai_canfd_lka_steering) || ((addr == 0x7D0) && !hyundai_camera_scc)) { |
| 184 |
3/4✓ Branch 1 taken 4 times.
✓ Branch 2 taken 18 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
|
22 | if ((GET_BYTES(to_send, 0, 4) != 0x00803E02U) || (GET_BYTES(to_send, 4, 4) != 0x0U)) { |
| 185 | 18 | tx = false; | |
| 186 | } | ||
| 187 | } | ||
| 188 | |||
| 189 | // ACCEL: safety check | ||
| 190 |
2/2✓ Branch 0 taken 4256 times.
✓ Branch 1 taken 844437 times.
|
848693 | if (addr == 0x1a0) { |
| 191 | 4256 | int desired_accel_raw = (((GET_BYTE(to_send, 17) & 0x7U) << 8) | GET_BYTE(to_send, 16)) - 1023U; | |
| 192 | 4256 | int desired_accel_val = ((GET_BYTE(to_send, 18) << 4) | (GET_BYTE(to_send, 17) >> 4)) - 1023U; | |
| 193 | |||
| 194 | 4256 | bool violation = false; | |
| 195 | |||
| 196 |
1/2✓ Branch 0 taken 4256 times.
✗ Branch 1 not taken.
|
4256 | if (hyundai_longitudinal) { |
| 197 | 4256 | violation |= longitudinal_accel_checks(desired_accel_raw, HYUNDAI_LONG_LIMITS); | |
| 198 | 4256 | violation |= longitudinal_accel_checks(desired_accel_val, HYUNDAI_LONG_LIMITS); | |
| 199 | } else { | ||
| 200 | // only used to cancel on here | ||
| 201 | // GCOV_EXCL_START | ||
| 202 | // TODO: Cover this with tests. | ||
| 203 | − | if ((desired_accel_raw != 0) || (desired_accel_val != 0)) { | |
| 204 | − | violation = true; | |
| 205 | } | ||
| 206 | // GCOV_EXCL_STOP | ||
| 207 | } | ||
| 208 | |||
| 209 |
2/2✓ Branch 0 taken 2632 times.
✓ Branch 1 taken 1624 times.
|
4256 | if (violation) { |
| 210 | 2632 | tx = false; | |
| 211 | } | ||
| 212 | } | ||
| 213 | |||
| 214 | 848693 | return tx; | |
| 215 | } | ||
| 216 | |||
| 217 | 177408 | static int hyundai_canfd_fwd_hook(int bus_num, int addr) { | |
| 218 | 177408 | int bus_fwd = -1; | |
| 219 | |||
| 220 |
2/2✓ Branch 0 taken 59136 times.
✓ Branch 1 taken 118272 times.
|
177408 | if (bus_num == 0) { |
| 221 | 59136 | bus_fwd = 2; | |
| 222 | } | ||
| 223 |
2/2✓ Branch 0 taken 59136 times.
✓ Branch 1 taken 118272 times.
|
177408 | if (bus_num == 2) { |
| 224 | // LKAS for cars with LKAS and LFA messages, LFA for cars with no LKAS messages | ||
| 225 |
2/2✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 56320 times.
|
59136 | int lfa_block_addr = hyundai_canfd_lka_steering_alt ? 0x362 : 0x2a4; |
| 226 |
6/6✓ Branch 1 taken 59115 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 59094 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 36 times.
|
59136 | bool is_lka_msg = ((addr == hyundai_canfd_get_lka_addr()) || (addr == lfa_block_addr)) && hyundai_canfd_lka_steering; |
| 227 |
4/4✓ Branch 0 taken 21 times.
✓ Branch 1 taken 59115 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 3 times.
|
59136 | bool is_lfa_msg = ((addr == 0x12a) && !hyundai_canfd_lka_steering); |
| 228 | |||
| 229 | // HUD icons | ||
| 230 |
4/4✓ Branch 0 taken 21 times.
✓ Branch 1 taken 59115 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 3 times.
|
59136 | bool is_lfahda_msg = ((addr == 0x1e0) && !hyundai_canfd_lka_steering); |
| 231 | |||
| 232 | // SCC_CONTROL and ADRV_0x160 for camera SCC cars, we send our own longitudinal commands and to show FCA light | ||
| 233 |
8/8✓ Branch 0 taken 59115 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 59094 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 28 times.
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 2 times.
|
59136 | bool is_scc_msg = (((addr == 0x1a0) || (addr == 0x160)) && hyundai_longitudinal && !hyundai_canfd_lka_steering); |
| 234 | |||
| 235 |
8/8✓ Branch 0 taken 59130 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 59112 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 59094 times.
✓ Branch 5 taken 18 times.
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 59082 times.
|
59136 | bool block_msg = is_lka_msg || is_lfa_msg || is_lfahda_msg || is_scc_msg; |
| 236 |
2/2✓ Branch 0 taken 59082 times.
✓ Branch 1 taken 54 times.
|
59136 | if (!block_msg) { |
| 237 | 59082 | bus_fwd = 0; | |
| 238 | } | ||
| 239 | } | ||
| 240 | |||
| 241 | 177408 | return bus_fwd; | |
| 242 | } | ||
| 243 | |||
| 244 | 756 | static safety_config hyundai_canfd_init(uint16_t param) { | |
| 245 | 756 | const int HYUNDAI_PARAM_CANFD_LKA_STEERING_ALT = 128; | |
| 246 | 756 | const int HYUNDAI_PARAM_CANFD_ALT_BUTTONS = 32; | |
| 247 | |||
| 248 | static const CanMsg HYUNDAI_CANFD_LKA_STEERING_TX_MSGS[] = { | ||
| 249 | HYUNDAI_CANFD_LKA_STEERING_COMMON_TX_MSGS(0, 1) | ||
| 250 | }; | ||
| 251 | |||
| 252 | static const CanMsg HYUNDAI_CANFD_LKA_STEERING_ALT_TX_MSGS[] = { | ||
| 253 | HYUNDAI_CANFD_LKA_STEERING_ALT_COMMON_TX_MSGS(0, 1) | ||
| 254 | }; | ||
| 255 | |||
| 256 | static const CanMsg HYUNDAI_CANFD_LKA_STEERING_LONG_TX_MSGS[] = { | ||
| 257 | HYUNDAI_CANFD_LKA_STEERING_COMMON_TX_MSGS(0, 1) | ||
| 258 | HYUNDAI_CANFD_LFA_STEERING_COMMON_TX_MSGS(1) | ||
| 259 | HYUNDAI_CANFD_SCC_CONTROL_COMMON_TX_MSGS(1) | ||
| 260 | {0x51, 0, 32}, // ADRV_0x51 | ||
| 261 | {0x730, 1, 8}, // tester present for ADAS ECU disable | ||
| 262 | {0x160, 1, 16}, // ADRV_0x160 | ||
| 263 | {0x1EA, 1, 32}, // ADRV_0x1ea | ||
| 264 | {0x200, 1, 8}, // ADRV_0x200 | ||
| 265 | {0x345, 1, 8}, // ADRV_0x345 | ||
| 266 | {0x1DA, 1, 32}, // ADRV_0x1da | ||
| 267 | }; | ||
| 268 | |||
| 269 | static const CanMsg HYUNDAI_CANFD_LFA_STEERING_TX_MSGS[] = { | ||
| 270 | HYUNDAI_CANFD_CRUISE_BUTTON_TX_MSGS(2) | ||
| 271 | HYUNDAI_CANFD_LFA_STEERING_COMMON_TX_MSGS(0) | ||
| 272 | HYUNDAI_CANFD_SCC_CONTROL_COMMON_TX_MSGS(0) | ||
| 273 | }; | ||
| 274 | |||
| 275 | static const CanMsg HYUNDAI_CANFD_LFA_STEERING_LONG_TX_MSGS[] = { | ||
| 276 | HYUNDAI_CANFD_CRUISE_BUTTON_TX_MSGS(2) | ||
| 277 | HYUNDAI_CANFD_LFA_STEERING_COMMON_TX_MSGS(0) | ||
| 278 | HYUNDAI_CANFD_SCC_CONTROL_COMMON_TX_MSGS(0) | ||
| 279 | {0x160, 0, 16}, // ADRV_0x160 | ||
| 280 | {0x7D0, 0, 8}, // tester present for radar ECU disable | ||
| 281 | }; | ||
| 282 | |||
| 283 | static const CanMsg HYUNDAI_CANFD_LFA_STEERING_CAMERA_SCC_TX_MSGS[] = { | ||
| 284 | HYUNDAI_CANFD_CRUISE_BUTTON_TX_MSGS(2) | ||
| 285 | HYUNDAI_CANFD_LFA_STEERING_COMMON_TX_MSGS(0) | ||
| 286 | HYUNDAI_CANFD_SCC_CONTROL_COMMON_TX_MSGS(0) | ||
| 287 | {0x160, 0, 16}, // ADRV_0x160 | ||
| 288 | }; | ||
| 289 | |||
| 290 | 756 | hyundai_common_init(param); | |
| 291 | |||
| 292 | 756 | gen_crc_lookup_table_16(0x1021, hyundai_canfd_crc_lut); | |
| 293 | 756 | hyundai_canfd_alt_buttons = GET_FLAG(param, HYUNDAI_PARAM_CANFD_ALT_BUTTONS); | |
| 294 | 756 | hyundai_canfd_lka_steering_alt = GET_FLAG(param, HYUNDAI_PARAM_CANFD_LKA_STEERING_ALT); | |
| 295 | |||
| 296 | safety_config ret; | ||
| 297 |
2/2✓ Branch 0 taken 280 times.
✓ Branch 1 taken 476 times.
|
756 | if (hyundai_longitudinal) { |
| 298 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 240 times.
|
280 | if (hyundai_canfd_lka_steering) { |
| 299 | static RxCheck hyundai_canfd_lka_steering_long_rx_checks[] = { | ||
| 300 | HYUNDAI_CANFD_COMMON_RX_CHECKS(1) | ||
| 301 | }; | ||
| 302 | |||
| 303 | 40 | ret = BUILD_SAFETY_CFG(hyundai_canfd_lka_steering_long_rx_checks, HYUNDAI_CANFD_LKA_STEERING_LONG_TX_MSGS); | |
| 304 | } else { | ||
| 305 | // Longitudinal checks for LFA steering | ||
| 306 | static RxCheck hyundai_canfd_long_rx_checks[] = { | ||
| 307 | HYUNDAI_CANFD_COMMON_RX_CHECKS(0) | ||
| 308 | }; | ||
| 309 | |||
| 310 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 120 times.
|
240 | ret = hyundai_camera_scc ? BUILD_SAFETY_CFG(hyundai_canfd_long_rx_checks, HYUNDAI_CANFD_LFA_STEERING_CAMERA_SCC_TX_MSGS) : \ |
| 311 | BUILD_SAFETY_CFG(hyundai_canfd_long_rx_checks, HYUNDAI_CANFD_LFA_STEERING_LONG_TX_MSGS); | ||
| 312 | } | ||
| 313 | } else { | ||
| 314 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 408 times.
|
476 | if (hyundai_canfd_lka_steering) { |
| 315 | // *** LKA steering checks *** | ||
| 316 | // E-CAN is on bus 1, SCC messages are sent on cars with ADRV ECU. | ||
| 317 | // Does not use the alt buttons message | ||
| 318 | static RxCheck hyundai_canfd_lka_steering_rx_checks[] = { | ||
| 319 | HYUNDAI_CANFD_COMMON_RX_CHECKS(1) | ||
| 320 | HYUNDAI_CANFD_SCC_ADDR_CHECK(1) | ||
| 321 | }; | ||
| 322 | |||
| 323 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 34 times.
|
68 | ret = hyundai_canfd_lka_steering_alt ? BUILD_SAFETY_CFG(hyundai_canfd_lka_steering_rx_checks, HYUNDAI_CANFD_LKA_STEERING_ALT_TX_MSGS) : \ |
| 324 | BUILD_SAFETY_CFG(hyundai_canfd_lka_steering_rx_checks, HYUNDAI_CANFD_LKA_STEERING_TX_MSGS); | ||
| 325 |
2/2✓ Branch 0 taken 204 times.
✓ Branch 1 taken 204 times.
|
408 | } else if (!hyundai_camera_scc) { |
| 326 | // Radar sends SCC messages on these cars instead of camera | ||
| 327 | static RxCheck hyundai_canfd_radar_scc_rx_checks[] = { | ||
| 328 | HYUNDAI_CANFD_COMMON_RX_CHECKS(0) | ||
| 329 | HYUNDAI_CANFD_SCC_ADDR_CHECK(0) | ||
| 330 | }; | ||
| 331 | |||
| 332 | 204 | ret = BUILD_SAFETY_CFG(hyundai_canfd_radar_scc_rx_checks, HYUNDAI_CANFD_LFA_STEERING_TX_MSGS); | |
| 333 | } else { | ||
| 334 | // *** LFA steering checks *** | ||
| 335 | // Camera sends SCC messages on LFA steering cars. | ||
| 336 | // Both button messages exist on some platforms, so we ensure we track the correct one using flag | ||
| 337 | static RxCheck hyundai_canfd_rx_checks[] = { | ||
| 338 | HYUNDAI_CANFD_COMMON_RX_CHECKS(0) | ||
| 339 | HYUNDAI_CANFD_SCC_ADDR_CHECK(2) | ||
| 340 | }; | ||
| 341 | |||
| 342 | 204 | ret = BUILD_SAFETY_CFG(hyundai_canfd_rx_checks, HYUNDAI_CANFD_LFA_STEERING_CAMERA_SCC_TX_MSGS); | |
| 343 | } | ||
| 344 | } | ||
| 345 | |||
| 346 | 756 | return ret; | |
| 347 | } | ||
| 348 | |||
| 349 | const safety_hooks hyundai_canfd_hooks = { | ||
| 350 | .init = hyundai_canfd_init, | ||
| 351 | .rx = hyundai_canfd_rx_hook, | ||
| 352 | .tx = hyundai_canfd_tx_hook, | ||
| 353 | .fwd = hyundai_canfd_fwd_hook, | ||
| 354 | .get_counter = hyundai_canfd_get_counter, | ||
| 355 | .get_checksum = hyundai_canfd_get_checksum, | ||
| 356 | .compute_checksum = hyundai_common_canfd_compute_checksum, | ||
| 357 | }; | ||
| 358 |