diff --git a/board/main.c b/board/main.c index 69db9b8ef..8c0f90556 100644 --- a/board/main.c +++ b/board/main.c @@ -622,6 +622,9 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) { case 0xdb: // toggle GMLAN set_can2_mode(setup->b.wValue.w); break; + case 0xdc: // set controls allowed + controls_allowed = setup->b.wValue.w == 0x1337; + break; case 0xe0: // uart read ur = get_ring_by_number(setup->b.wValue.w); if (!ur) break; diff --git a/board/panda_safety.h b/board/panda_safety.h index 029975c56..c6eb36a17 100644 --- a/board/panda_safety.h +++ b/board/panda_safety.h @@ -4,10 +4,10 @@ void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { } int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send, int hardwired) { - return hardwired; + return hardwired && controls_allowed; } int safety_tx_lin_hook(int lin_num, uint8_t *data, int len, int hardwired) { - return hardwired; + return hardwired && controls_allowed; } diff --git a/lib/panda.py b/lib/panda.py index 3cc1494aa..a9f9e042d 100644 --- a/lib/panda.py +++ b/lib/panda.py @@ -105,6 +105,12 @@ class Panda(object): # ******************* configuration ******************* + def set_controls_allowed(self, on): + if on: + self.handle.controlWrite(usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE, 0xdc, 0x1337, 0, '') + else: + self.handle.controlWrite(usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE, 0xdc, 0, 0, '') + def set_gmlan(self, on): if on: self.handle.controlWrite(usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE, 0xdb, 1, 0, '') diff --git a/tests/loopback_test.py b/tests/loopback_test.py index f970c1f16..d279a8aba 100755 --- a/tests/loopback_test.py +++ b/tests/loopback_test.py @@ -25,6 +25,9 @@ def run_test(): h = map(lambda x: Panda(x), pandas) print h + h[0].set_controls_allowed(True) + h[1].set_controls_allowed(True) + # test both directions for ho in [[0,1], [1,0]]: diff --git a/tests/standalone_test.py b/tests/standalone_test.py index 0404ee863..fa050314d 100755 --- a/tests/standalone_test.py +++ b/tests/standalone_test.py @@ -11,6 +11,7 @@ if __name__ == "__main__": p = Panda() print p.health() print p.get_serial() + p.set_controls_allowed(True) a = 0 while 1: