[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 87/92] hw/net/can: sja1000 ignore CAN FD frames
From: |
Paolo Bonzini |
Subject: |
[PULL 87/92] hw/net/can: sja1000 ignore CAN FD frames |
Date: |
Thu, 24 Sep 2020 05:23:09 -0400 |
From: Jan Charvat <charvj10@fel.cvut.cz>
Signed-off-by: Jan Charvat <charvj10@fel.cvut.cz>
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Reviewed-by: Vikram Garhwal <fnu.vikram@xilinx.com>
Message-Id:
<48d9ebf6b64e7652851c12fe4566e06b44803372.1600069689.git.pisa@cmp.felk.cvut.cz>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/net/can/can_sja1000.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c
index ec66d4232d..42d2f99dfb 100644
--- a/hw/net/can/can_sja1000.c
+++ b/hw/net/can/can_sja1000.c
@@ -323,11 +323,16 @@ static void buff2frame_bas(const uint8_t *buff,
qemu_can_frame *frame)
static int frame2buff_pel(const qemu_can_frame *frame, uint8_t *buff)
{
int i;
+ int dlen = frame->can_dlc;
if (frame->can_id & QEMU_CAN_ERR_FLAG) { /* error frame, NOT support now.
*/
return -1;
}
+ if (dlen > 8) {
+ return -1;
+ }
+
buff[0] = 0x0f & frame->can_dlc; /* DLC */
if (frame->can_id & QEMU_CAN_RTR_FLAG) { /* RTR */
buff[0] |= (1 << 6);
@@ -338,18 +343,18 @@ static int frame2buff_pel(const qemu_can_frame *frame,
uint8_t *buff)
buff[2] = extract32(frame->can_id, 13, 8); /* ID.20~ID.13 */
buff[3] = extract32(frame->can_id, 5, 8); /* ID.12~ID.05 */
buff[4] = extract32(frame->can_id, 0, 5) << 3; /* ID.04~ID.00,xxx */
- for (i = 0; i < frame->can_dlc; i++) {
+ for (i = 0; i < dlen; i++) {
buff[5 + i] = frame->data[i];
}
- return frame->can_dlc + 5;
+ return dlen + 5;
} else { /* SFF */
buff[1] = extract32(frame->can_id, 3, 8); /* ID.10~ID.03 */
buff[2] = extract32(frame->can_id, 0, 3) << 5; /* ID.02~ID.00,xxxxx */
- for (i = 0; i < frame->can_dlc; i++) {
+ for (i = 0; i < dlen; i++) {
buff[3 + i] = frame->data[i];
}
- return frame->can_dlc + 3;
+ return dlen + 3;
}
return -1;
@@ -358,6 +363,7 @@ static int frame2buff_pel(const qemu_can_frame *frame,
uint8_t *buff)
static int frame2buff_bas(const qemu_can_frame *frame, uint8_t *buff)
{
int i;
+ int dlen = frame->can_dlc;
/*
* EFF, no support for BasicMode
@@ -369,17 +375,21 @@ static int frame2buff_bas(const qemu_can_frame *frame,
uint8_t *buff)
return -1;
}
+ if (dlen > 8) {
+ return -1;
+ }
+
buff[0] = extract32(frame->can_id, 3, 8); /* ID.10~ID.03 */
buff[1] = extract32(frame->can_id, 0, 3) << 5; /* ID.02~ID.00,xxxxx */
if (frame->can_id & QEMU_CAN_RTR_FLAG) { /* RTR */
buff[1] |= (1 << 4);
}
buff[1] |= frame->can_dlc & 0x0f;
- for (i = 0; i < frame->can_dlc; i++) {
+ for (i = 0; i < dlen; i++) {
buff[2 + i] = frame->data[i];
}
- return frame->can_dlc + 2;
+ return dlen + 2;
}
static void can_sja_update_pel_irq(CanSJA1000State *s)
@@ -766,6 +776,13 @@ ssize_t can_sja_receive(CanBusClientState *client, const
qemu_can_frame *frames,
if (frames_cnt <= 0) {
return 0;
}
+ if (frame->flags & QEMU_CAN_FRMF_TYPE_FD) {
+ if (DEBUG_FILTER) {
+ can_display_msg("[cansja]: ignor fd frame ", frame);
+ }
+ return 1;
+ }
+
if (DEBUG_FILTER) {
can_display_msg("[cansja]: receive ", frame);
}
--
2.26.2
- [PULL 67/92] qom: Use kernel-doc private/public tags in structs, (continued)
- [PULL 67/92] qom: Use kernel-doc private/public tags in structs, Paolo Bonzini, 2020/09/24
- [PULL 68/92] qom: Use ``code`` Sphinx syntax where appropriate, Paolo Bonzini, 2020/09/24
- [PULL 69/92] qom: Add kernel-doc markup to introduction doc comment, Paolo Bonzini, 2020/09/24
- [PULL 70/92] qom: Reformat section titles using Sphinx syntax, Paolo Bonzini, 2020/09/24
- [PULL 71/92] qom: Indent existing code examples, Paolo Bonzini, 2020/09/24
- [PULL 72/92] qom: Add code block markup to all code blocks, Paolo Bonzini, 2020/09/24
- [PULL 73/92] docs: Create docs/devel/qom.rst, Paolo Bonzini, 2020/09/24
- [PULL 74/92] docs: Move object.h overview doc comment to qom.rst, Paolo Bonzini, 2020/09/24
- [PULL 75/92] hw/i386/xen: Rename X86/PC specific function as xen_hvm_init_pc(), Paolo Bonzini, 2020/09/24
- [PULL 80/92] checkpatch: Detect '%#' or '%0#' in printf-style format strings, Paolo Bonzini, 2020/09/24
- [PULL 87/92] hw/net/can: sja1000 ignore CAN FD frames,
Paolo Bonzini <=
- [PULL 76/92] sysemu/xen: Add missing 'exec/cpu-common.h' header for ram_addr_t type, Paolo Bonzini, 2020/09/24
- [PULL 78/92] hw/xen: Split x86-specific declaration from generic hardware ones, Paolo Bonzini, 2020/09/24
- [PULL 77/92] stubs: Split accelerator / hardware related stubs, Paolo Bonzini, 2020/09/24
- [PULL 85/92] target/i386: kvm: do not use kvm_check_extension to find paravirtual capabilities, Paolo Bonzini, 2020/09/24
- [PULL 86/92] net/can: Initial host SocketCan support for CAN FD., Paolo Bonzini, 2020/09/24
- [PULL 79/92] typedefs: Restrict PCMachineState to 'hw/i386/pc.h', Paolo Bonzini, 2020/09/24
- [PULL 82/92] target/i386: Fix VM migration when interrupt based APF is enabled, Paolo Bonzini, 2020/09/24
- [PULL 83/92] target/i386: always create kvmclock device, Paolo Bonzini, 2020/09/24
- [PULL 81/92] helper_syscall x86_64: clear exception_is_int, Paolo Bonzini, 2020/09/24
- [PULL 88/92] net/can: Add can_dlc2len and can_len2dlc for CAN FD., Paolo Bonzini, 2020/09/24