Skip to content

Commit

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

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

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

li := &linkInfoMsg{
linkType: canLinkType,
linkType: CanLinkType,
}
li.info.BitTiming.Bitrate = bitrate
ae := netlink.NewAttributeEncoder()
Expand All @@ -173,6 +174,7 @@ type Info struct {
Clock Clock
CtrlMode CtrlMode
BusErrorCounters BusErrorCounters
Type string

State uint32
RestartMs uint32
Expand Down Expand Up @@ -244,6 +246,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 @@ -456,7 +459,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 a76f104

Please sign in to comment.