Subaru: Forwarding (#152)

Bus 0 to 1
Bus 1 to 0 exept LKAS
master
Bugsy 2019-01-29 13:42:06 +08:00 committed by rbiasini
parent 9ee628557f
commit d275fa8489
2 changed files with 52 additions and 0 deletions

View File

@ -63,6 +63,7 @@ int controls_allowed = 0;
#include "safety/safety_cadillac.h"
#include "safety/safety_hyundai.h"
#include "safety/safety_chrysler.h"
#include "safety/safety_subaru.h"
#include "safety/safety_elm327.h"
const safety_hooks *current_hooks = &nooutput_hooks;
@ -104,6 +105,7 @@ typedef struct {
#define SAFETY_HYUNDAI 7
#define SAFETY_TESLA 8
#define SAFETY_CHRYSLER 9
#define SAFETY_SUBARU 10
#define SAFETY_TOYOTA_IPAS 0x1335
#define SAFETY_TOYOTA_NOLIMITS 0x1336
#define SAFETY_ALLOUTPUT 0x1337
@ -119,6 +121,7 @@ const safety_hook_config safety_hook_registry[] = {
{SAFETY_CADILLAC, &cadillac_hooks},
{SAFETY_HYUNDAI, &hyundai_hooks},
{SAFETY_CHRYSLER, &chrysler_hooks},
{SAFETY_SUBARU, &subaru_hooks},
{SAFETY_TOYOTA_NOLIMITS, &toyota_nolimits_hooks},
#ifdef PANDA
{SAFETY_TOYOTA_IPAS, &toyota_ipas_hooks},

View File

@ -0,0 +1,49 @@
void subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {}
// FIXME
// *** all output safety mode ***
static void subaru_init(int16_t param) {
controls_allowed = 1;
}
static int subaru_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
return true;
}
static int subaru_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
// shifts bits 29 > 11
int32_t addr = to_fwd->RIR >> 21;
// forward CAN 0 > 1
if (bus_num == 0) {
return 1; // ES CAN
}
// forward CAN 1 > 0, except ES_LKAS
else if (bus_num == 1) {
// outback 2015
if (addr == 0x164) {
return -1;
}
// global platform
if (addr == 0x122) {
return -1;
}
return 0; // Main CAN
}
// fallback to do not forward
return -1;
}
const safety_hooks subaru_hooks = {
.init = subaru_init,
.rx = subaru_rx_hook,
.tx = subaru_tx_hook,
.tx_lin = nooutput_tx_lin_hook,
.ignition = default_ign_hook,
.fwd = subaru_fwd_hook,
};