Skip to content

Commit

Permalink
feat: add support for virtual can
Browse files Browse the repository at this point in the history
  • Loading branch information
ardrabczyk authored and Edholm committed Sep 26, 2023
1 parent e243d3d commit d307875
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/candevice/device_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
"golang.org/x/sys/unix"
)

const canLinkType = "can"
const (
CanLinkType = "can"
VcanLinkType = "vcan"
)

const (
StateErrorActive = unix.CAN_STATE_ERROR_ACTIVE
Expand Down Expand Up @@ -197,7 +200,7 @@ func (d *Device) SetBitrate(bitrate uint32) error {
}

li := &linkInfoMsg{
linkType: canLinkType,
linkType: CanLinkType,
}

li.info, err = d.getCurrentParametersForSet()
Expand Down Expand Up @@ -230,6 +233,7 @@ type Info struct {
Clock Clock
CtrlMode CtrlMode
BusErrorCounters BusErrorCounters
Type string

State uint32
RestartMs uint32
Expand Down Expand Up @@ -310,6 +314,7 @@ func (d *Device) unmarshalBinary(data []byte) error {
d.ifname = ad.String()
case unix.IFLA_LINKINFO:
ad.Nested(d.li.decode)
d.li.info.Type = d.li.linkType
default:
}
}
Expand Down Expand Up @@ -530,7 +535,7 @@ func (li *linkInfoMsg) decode(nad *netlink.AttributeDecoder) error {
switch nad.Type() {
case unix.IFLA_INFO_KIND:
li.linkType = nad.String()
if li.linkType != canLinkType {
if (li.linkType != CanLinkType) && (li.linkType != VcanLinkType) {
return fmt.Errorf("not a CAN interface")
}
case unix.IFLA_INFO_DATA:
Expand Down

0 comments on commit d307875

Please sign in to comment.