diff --git a/board/main_comms.h b/board/main_comms.h index c821f4cfc..0ca3c76fc 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -59,7 +59,7 @@ int get_rtc_pkt(void *dat) { void comms_endpoint2_write(uint8_t *data, uint32_t len) { uart_ring *ur = get_ring_by_number(data[0]); if ((len != 0U) && (ur != NULL)) { - if ((data[0] < 2U) || (data[0] >= 4U) || safety_tx_lin_hook(data[0] - 2U, &data[1], len - 1U)) { + if ((data[0] < 2U) || (data[0] >= 4U)) { for (uint32_t i = 1; i < len; i++) { while (!putc(ur, data[i])) { // wait diff --git a/board/safety.h b/board/safety.h index 4ec9c73aa..abff1ada4 100644 --- a/board/safety.h +++ b/board/safety.h @@ -85,10 +85,6 @@ bool safety_tx_hook(CANPacket_t *to_send) { return !relay_malfunction && whitelisted && safety_allowed; } -bool safety_tx_lin_hook(int lin_num, uint8_t *data, int len) { - return current_hooks->tx_lin(lin_num, data, len); -} - int safety_fwd_hook(int bus_num, int addr) { return (relay_malfunction ? -1 : current_hooks->fwd(bus_num, addr)); } diff --git a/board/safety/safety_body.h b/board/safety/safety_body.h index 04e61bed5..61232a3bd 100644 --- a/board/safety/safety_body.h +++ b/board/safety/safety_body.h @@ -42,6 +42,5 @@ const safety_hooks body_hooks = { .init = body_init, .rx = body_rx_hook, .tx = body_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = default_fwd_hook, }; diff --git a/board/safety/safety_chrysler.h b/board/safety/safety_chrysler.h index 99bd52c9b..13ee47368 100644 --- a/board/safety/safety_chrysler.h +++ b/board/safety/safety_chrysler.h @@ -286,7 +286,6 @@ const safety_hooks chrysler_hooks = { .init = chrysler_init, .rx = chrysler_rx_hook, .tx = chrysler_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = chrysler_fwd_hook, .get_counter = chrysler_get_counter, .get_checksum = chrysler_get_checksum, diff --git a/board/safety/safety_defaults.h b/board/safety/safety_defaults.h index 9d3a4b779..1ce1ee2ed 100644 --- a/board/safety/safety_defaults.h +++ b/board/safety/safety_defaults.h @@ -14,13 +14,6 @@ static bool nooutput_tx_hook(CANPacket_t *to_send) { return false; } -static bool nooutput_tx_lin_hook(int lin_num, uint8_t *data, int len) { - UNUSED(lin_num); - UNUSED(data); - UNUSED(len); - return false; -} - static int default_fwd_hook(int bus_num, int addr) { UNUSED(bus_num); UNUSED(addr); @@ -31,7 +24,6 @@ const safety_hooks nooutput_hooks = { .init = nooutput_init, .rx = default_rx_hook, .tx = nooutput_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = default_fwd_hook, }; @@ -52,13 +44,6 @@ static bool alloutput_tx_hook(CANPacket_t *to_send) { return true; } -static bool alloutput_tx_lin_hook(int lin_num, uint8_t *data, int len) { - UNUSED(lin_num); - UNUSED(data); - UNUSED(len); - return true; -} - static int alloutput_fwd_hook(int bus_num, int addr) { int bus_fwd = -1; UNUSED(addr); @@ -79,6 +64,5 @@ const safety_hooks alloutput_hooks = { .init = alloutput_init, .rx = default_rx_hook, .tx = alloutput_tx_hook, - .tx_lin = alloutput_tx_lin_hook, .fwd = alloutput_fwd_hook, }; diff --git a/board/safety/safety_elm327.h b/board/safety/safety_elm327.h index 98aa759ac..0d520b17b 100644 --- a/board/safety/safety_elm327.h +++ b/board/safety/safety_elm327.h @@ -17,26 +17,10 @@ static bool elm327_tx_hook(CANPacket_t *to_send) { return tx; } -static bool elm327_tx_lin_hook(int lin_num, uint8_t *data, int len) { - int tx = 1; - if (lin_num != 0) { - tx = 0; // Only operate on LIN 0, aka serial 2 - } - if ((len < 5) || (len > 11)) { - tx = 0; // Valid KWP size - } - if (!(((data[0] & 0xF8U) == 0xC0U) && ((data[0] & 0x07U) != 0U) && - (data[1] == 0x33U) && (data[2] == 0xF1U))) { - tx = 0; // Bad msg - } - return tx; -} - // If current_board->has_obd and safety_param == 0, bus 1 is multiplexed to the OBD-II port const safety_hooks elm327_hooks = { .init = nooutput_init, .rx = default_rx_hook, .tx = elm327_tx_hook, - .tx_lin = elm327_tx_lin_hook, .fwd = default_fwd_hook, }; diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 6710c26dd..d7b157c48 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -417,7 +417,6 @@ const safety_hooks ford_hooks = { .init = ford_init, .rx = ford_rx_hook, .tx = ford_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = ford_fwd_hook, .get_counter = ford_get_counter, .get_checksum = ford_get_checksum, diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index d1963ae48..70dc4cfff 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -240,6 +240,5 @@ const safety_hooks gm_hooks = { .init = gm_init, .rx = gm_rx_hook, .tx = gm_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = gm_fwd_hook, }; diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index b6e9c06e0..0bc41dbb3 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -458,7 +458,6 @@ const safety_hooks honda_nidec_hooks = { .init = honda_nidec_init, .rx = honda_rx_hook, .tx = honda_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = honda_nidec_fwd_hook, .get_counter = honda_get_counter, .get_checksum = honda_get_checksum, @@ -469,7 +468,6 @@ const safety_hooks honda_bosch_hooks = { .init = honda_bosch_init, .rx = honda_rx_hook, .tx = honda_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = honda_bosch_fwd_hook, .get_counter = honda_get_counter, .get_checksum = honda_get_checksum, diff --git a/board/safety/safety_hyundai.h b/board/safety/safety_hyundai.h index 310c678eb..f196901ff 100644 --- a/board/safety/safety_hyundai.h +++ b/board/safety/safety_hyundai.h @@ -327,7 +327,6 @@ const safety_hooks hyundai_hooks = { .init = hyundai_init, .rx = hyundai_rx_hook, .tx = hyundai_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = hyundai_fwd_hook, .get_counter = hyundai_get_counter, .get_checksum = hyundai_get_checksum, @@ -338,7 +337,6 @@ const safety_hooks hyundai_legacy_hooks = { .init = hyundai_legacy_init, .rx = hyundai_rx_hook, .tx = hyundai_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = hyundai_fwd_hook, .get_counter = hyundai_get_counter, .get_checksum = hyundai_get_checksum, diff --git a/board/safety/safety_hyundai_canfd.h b/board/safety/safety_hyundai_canfd.h index b80c1914f..7818c8624 100644 --- a/board/safety/safety_hyundai_canfd.h +++ b/board/safety/safety_hyundai_canfd.h @@ -353,7 +353,6 @@ const safety_hooks hyundai_canfd_hooks = { .init = hyundai_canfd_init, .rx = hyundai_canfd_rx_hook, .tx = hyundai_canfd_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = hyundai_canfd_fwd_hook, .get_counter = hyundai_canfd_get_counter, .get_checksum = hyundai_canfd_get_checksum, diff --git a/board/safety/safety_mazda.h b/board/safety/safety_mazda.h index 2bb2fad83..82da5b0a3 100644 --- a/board/safety/safety_mazda.h +++ b/board/safety/safety_mazda.h @@ -125,6 +125,5 @@ const safety_hooks mazda_hooks = { .init = mazda_init, .rx = mazda_rx_hook, .tx = mazda_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = mazda_fwd_hook, }; diff --git a/board/safety/safety_nissan.h b/board/safety/safety_nissan.h index 1504e39aa..cb7bb9e06 100644 --- a/board/safety/safety_nissan.h +++ b/board/safety/safety_nissan.h @@ -155,6 +155,5 @@ const safety_hooks nissan_hooks = { .init = nissan_init, .rx = nissan_rx_hook, .tx = nissan_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = nissan_fwd_hook, }; diff --git a/board/safety/safety_subaru.h b/board/safety/safety_subaru.h index 9cb650508..1c762d55f 100644 --- a/board/safety/safety_subaru.h +++ b/board/safety/safety_subaru.h @@ -288,7 +288,6 @@ const safety_hooks subaru_hooks = { .init = subaru_init, .rx = subaru_rx_hook, .tx = subaru_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = subaru_fwd_hook, .get_counter = subaru_get_counter, .get_checksum = subaru_get_checksum, diff --git a/board/safety/safety_subaru_preglobal.h b/board/safety/safety_subaru_preglobal.h index c77b18e1c..b246f4120 100644 --- a/board/safety/safety_subaru_preglobal.h +++ b/board/safety/safety_subaru_preglobal.h @@ -122,6 +122,5 @@ const safety_hooks subaru_preglobal_hooks = { .init = subaru_preglobal_init, .rx = subaru_preglobal_rx_hook, .tx = subaru_preglobal_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = subaru_preglobal_fwd_hook, }; diff --git a/board/safety/safety_tesla.h b/board/safety/safety_tesla.h index 82523d4a0..dbfda37b0 100644 --- a/board/safety/safety_tesla.h +++ b/board/safety/safety_tesla.h @@ -222,6 +222,5 @@ const safety_hooks tesla_hooks = { .init = tesla_init, .rx = tesla_rx_hook, .tx = tesla_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = tesla_fwd_hook, }; diff --git a/board/safety/safety_toyota.h b/board/safety/safety_toyota.h index ee825200b..60853c023 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -261,7 +261,6 @@ const safety_hooks toyota_hooks = { .init = toyota_init, .rx = toyota_rx_hook, .tx = toyota_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = toyota_fwd_hook, .get_checksum = toyota_get_checksum, .compute_checksum = toyota_compute_checksum, diff --git a/board/safety/safety_volkswagen_mqb.h b/board/safety/safety_volkswagen_mqb.h index caa7bb01c..6b1d6d2b4 100644 --- a/board/safety/safety_volkswagen_mqb.h +++ b/board/safety/safety_volkswagen_mqb.h @@ -282,7 +282,6 @@ const safety_hooks volkswagen_mqb_hooks = { .init = volkswagen_mqb_init, .rx = volkswagen_mqb_rx_hook, .tx = volkswagen_mqb_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = volkswagen_mqb_fwd_hook, .get_counter = volkswagen_mqb_get_counter, .get_checksum = volkswagen_mqb_get_checksum, diff --git a/board/safety/safety_volkswagen_pq.h b/board/safety/safety_volkswagen_pq.h index 50b53902f..509db4e77 100644 --- a/board/safety/safety_volkswagen_pq.h +++ b/board/safety/safety_volkswagen_pq.h @@ -248,7 +248,6 @@ const safety_hooks volkswagen_pq_hooks = { .init = volkswagen_pq_init, .rx = volkswagen_pq_rx_hook, .tx = volkswagen_pq_tx_hook, - .tx_lin = nooutput_tx_lin_hook, .fwd = volkswagen_pq_fwd_hook, .get_counter = volkswagen_pq_get_counter, .get_checksum = volkswagen_pq_get_checksum, diff --git a/board/safety_declarations.h b/board/safety_declarations.h index 883a8c1a6..94426ea8a 100644 --- a/board/safety_declarations.h +++ b/board/safety_declarations.h @@ -148,7 +148,6 @@ typedef bool (*get_quality_flag_valid_t)(CANPacket_t *to_push); bool safety_rx_hook(CANPacket_t *to_push); bool safety_tx_hook(CANPacket_t *to_send); -bool safety_tx_lin_hook(int lin_num, uint8_t *data, int len); uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last); int to_signed(int d, int bits); void update_sample(struct sample_t *sample, int sample_new); @@ -194,14 +193,12 @@ void pcm_cruise_check(bool cruise_engaged); typedef safety_config (*safety_hook_init)(uint16_t param); typedef void (*rx_hook)(CANPacket_t *to_push); typedef bool (*tx_hook)(CANPacket_t *to_send); -typedef bool (*tx_lin_hook)(int lin_num, uint8_t *data, int len); typedef int (*fwd_hook)(int bus_num, int addr); typedef struct { safety_hook_init init; rx_hook rx; tx_hook tx; - tx_lin_hook tx_lin; fwd_hook fwd; get_checksum_t get_checksum; compute_checksum_t compute_checksum; diff --git a/tests/libpanda/libpanda_py.py b/tests/libpanda/libpanda_py.py index a0fb02b73..1b07543d6 100644 --- a/tests/libpanda/libpanda_py.py +++ b/tests/libpanda/libpanda_py.py @@ -27,7 +27,6 @@ typedef struct { ffi.cdef(""" bool safety_rx_hook(CANPacket_t *to_send); bool safety_tx_hook(CANPacket_t *to_push); -bool safety_tx_lin_hook(int lin_num, uint8_t *data, int len); int safety_fwd_hook(int bus_num, int addr); int set_safety_hooks(uint16_t mode, uint16_t param); """) @@ -78,7 +77,6 @@ class Panda(PandaSafety, Protocol): # safety def safety_rx_hook(self, to_send: CANPacket) -> int: ... def safety_tx_hook(self, to_push: CANPacket) -> int: ... - def safety_tx_lin_hook(self, lin_num: int, data: bytes, _len: int) -> int: ... def safety_fwd_hook(self, bus_num: int, addr: int) -> int: ... def set_safety_hooks(self, mode: int, param: int) -> int: ... diff --git a/tests/safety/common.py b/tests/safety/common.py index 2f7ee3a2c..fca1e78f1 100644 --- a/tests/safety/common.py +++ b/tests/safety/common.py @@ -75,10 +75,6 @@ class PandaSafetyTestBase(unittest.TestCase): def _tx(self, msg): return self.safety.safety_tx_hook(msg) - def _tx_lin(self, priority: int, lin_num: int, to_addr: int, from_addr: int, dat: bytes): - msg = bytes([priority | len(dat), to_addr, from_addr]) + dat - return self.safety.safety_tx_lin_hook(lin_num, msg, len(msg)) - def _generic_limit_safety_check(self, msg_function: MessageFunction, min_allowed_value: float, max_allowed_value: float, min_possible_value: float, max_possible_value: float, test_delta: float = 1, inactive_value: float = 0, msg_allowed = True, additional_setup: Optional[Callable[[float], None]] = None): diff --git a/tests/safety/test_defaults.py b/tests/safety/test_defaults.py index 3dbe8e8fd..81bafeefc 100755 --- a/tests/safety/test_defaults.py +++ b/tests/safety/test_defaults.py @@ -23,10 +23,6 @@ class TestNoOutput(TestDefaultRxHookBase): self.safety.set_safety_hooks(Panda.SAFETY_NOOUTPUT, 0) self.safety.init_tests() - def test_tx_lin_hook(self): - for lin_num in range(2): - self.assertFalse(self._tx_lin(0x0, lin_num, 0x0, 0x0, b'\x00' * 8), f"allowed TX LIN {lin_num=}") - class TestSilent(TestNoOutput): """SILENT uses same hooks as NOOUTPUT""" @@ -47,10 +43,6 @@ class TestAllOutput(TestDefaultRxHookBase): self.safety.set_safety_hooks(Panda.SAFETY_ALLOUTPUT, 0) self.safety.init_tests() - def test_tx_lin_hook(self): - for lin_num in range(2): - self.assertTrue(self._tx_lin(0x0, lin_num, 0x0, 0x0, b'\x00' * 8), f"not allowed TX LIN {lin_num=}") - def test_spam_can_buses(self): # asserts tx allowed for all scanned addrs for bus in range(4): diff --git a/tests/safety/test_elm327.py b/tests/safety/test_elm327.py index 7fcbe2a77..31cd74e9d 100755 --- a/tests/safety/test_elm327.py +++ b/tests/safety/test_elm327.py @@ -31,20 +31,6 @@ class TestElm327(TestDefaultRxHookBase): should_tx = msg_len == 8 self.assertEqual(should_tx, self._tx(common.make_msg(0, 0x700, msg_len))) - def test_tx_lin_hook(self): - # spot check some cases - self.assertFalse(self._tx_lin(0xC0, 1, 0x33, 0xF1, b'\x01\x0F')) # wrong lin number/bus - self.assertFalse(self._tx_lin(0xC0, 0, 0x33, 0xF1, b'')) # wrong length - self.assertFalse(self._tx_lin(0xB0, 0, 0x33, 0xF1, b'\x01\x0E')) # bad priority - self.assertFalse(self._tx_lin(0xC0, 0, 0x00, 0xF1, b'\x01\x0D')) # bad addr - self.assertFalse(self._tx_lin(0xC0, 0, 0x33, 0x00, b'\x01\x0C')) # bad addr - - for msg_len in range(8 + 1): - # first three bytes are made up of priority, len, rx/tx addresses - # payload is not checked, try sending 0xFF - should_tx = 2 <= (msg_len) <= 7 - self.assertEqual(should_tx, self._tx_lin(0xC0, 0, 0x33, 0xF1, b'\xFF' * msg_len)) - def test_tx_hook_on_wrong_safety_mode(self): # No point, since we allow many diagnostic addresses pass