diff --git a/board/build.mk b/board/build.mk index ef20b42b9..d7e28f069 100644 --- a/board/build.mk +++ b/board/build.mk @@ -7,6 +7,7 @@ OBJDUMP = arm-none-eabi-objdump ifeq ($(RELEASE),1) CERT = ../../pandaextra/certs/release + CFLAGS += "-DPANDA_SAFETY" else CERT = ../certs/debug CFLAGS += "-DALLOW_DEBUG" diff --git a/board/honda_safety.h b/board/honda_safety.h index 50fb5faaa..1508c2c96 100644 --- a/board/honda_safety.h +++ b/board/honda_safety.h @@ -82,3 +82,7 @@ int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { return 1; } +int safety_tx_lin_hook(int lin_num, uint8_t *data, int len) { + return 1; +} + diff --git a/board/main.c b/board/main.c index 5dde1372b..37d17f4db 100644 --- a/board/main.c +++ b/board/main.c @@ -315,7 +315,13 @@ inline int putc(uart_ring *q, char elem) { void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push); int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send); +int safety_tx_lin_hook(int lin_num, uint8_t *data, int len); + +#ifdef PANDA_SAFETY +#include "panda_safety.h" +#else #include "honda_safety.h" +#endif // ***************************** CAN ***************************** @@ -482,7 +488,9 @@ void usb_cb_ep2_out(uint8_t *usbdata, int len) { if (len == 0) return; uart_ring *ur = get_ring_by_number(usbdata[0]); if (!ur) return; - for (i = 1; i < len; i++) while (!putc(ur, usbdata[i])); + if ((usbdata[0] < 2) || safety_tx_lin_hook(usbdata[0]-2, usbdata+1, len-1)) { + for (i = 1; i < len; i++) while (!putc(ur, usbdata[i])); + } } // send on CAN diff --git a/board/panda_safety.h b/board/panda_safety.h new file mode 100644 index 000000000..75faf901f --- /dev/null +++ b/board/panda_safety.h @@ -0,0 +1,13 @@ +// pandas by default do not allow sending in this firmware + +void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { +} + +int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { + return 0; +} + +int safety_tx_lin_hook(int lin_num, uint8_t *data, int len) { + return 0; +} +