This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new c2b7823cafb net/can: reject unsupported CAN protocols in socket()
c2b7823cafb is described below

commit c2b7823cafbbf841bf2a583ab817e68d7dc984d5
Author: Brijesh Thakkar <[email protected]>
AuthorDate: Fri Oct 23 13:35:34 2026 +0530

    net/can: reject unsupported CAN protocols in socket()
    
    can_setup() accepted CAN_BCM, CAN_TP16, CAN_TP20, CAN_MCNET and
    CAN_J1939 although none of them is implemented. The socket was created
    with the same connection structure as a CAN_RAW socket, and because the
    protocol is not recorded anywhere it then behaved exactly like a CAN_RAW
    socket. An application asking for one of these protocols therefore got
    a raw frame socket without any error.
    
    Linux returns EPROTONOSUPPORT for a CAN protocol it does not support.
    Do the same: protocol 0 (used by netlib_ifup() for its control sockets),
    CAN_RAW and CAN_ISOTP are accepted, and every other protocol fails in
    socket() with -EPROTONOSUPPORT before a connection is allocated.
    
    CAN_ISOTP is still accepted because an ISO-TP implementation is being
    prepared for upstream and will provide the protocol behind it.
    
    The CAN_BCM, CAN_TP16, CAN_TP20, CAN_MCNET and CAN_J1939 protocol
    numbers stay defined in nuttx/can.h. Nothing in nuttx or nuttx-apps
    opens a PF_CAN socket with any of them.
    
    Signed-off-by: Brijesh Thakkar <[email protected]>
    Assisted-by: Claude Code
---
 net/can/can_sockif.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/net/can/can_sockif.c b/net/can/can_sockif.c
index ff7541a1dee..e71979c9422 100644
--- a/net/can/can_sockif.c
+++ b/net/can/can_sockif.c
@@ -187,12 +187,7 @@ static int can_setup(FAR struct socket *psock)
     {
       case 0:            /* INET subsystem for netlib_ifup */
       case CAN_RAW:      /* RAW sockets */
-      case CAN_BCM:      /* Broadcast Manager */
-      case CAN_TP16:     /* VAG Transport Protocol v1.6 */
-      case CAN_TP20:     /* VAG Transport Protocol v2.0 */
-      case CAN_MCNET:    /* Bosch MCNet */
       case CAN_ISOTP:    /* ISO 15765-2 Transport Protocol */
-      case CAN_J1939:    /* SAE J1939 */
         break;
 
       default:

Reply via email to