Brijesh-Thakkar opened a new pull request, #20922:
URL: https://github.com/apache/nuttx/pull/20922

   ## Summary
   
   `can_setup()` accepted `CAN_BCM`, `CAN_TP16`, `CAN_TP20`, `CAN_MCNET`, 
`CAN_ISOTP` and `CAN_J1939`, although none of them is implemented. The socket 
got the same connection structure as a `CAN_RAW` socket and, since the protocol 
isn't recorded anywhere, silently behaved as `CAN_RAW`. An application asking 
for `CAN_ISOTP` got a raw frame socket with no error.
   
   Linux returns `EPROTONOSUPPORT` for CAN protocols it doesn't support. This 
does the same: only protocol 0 (used by `netlib_ifup()` control sockets) and 
`CAN_RAW` are accepted; every other protocol fails in `socket()` with 
`-EPROTONOSUPPORT` before a connection is allocated. The protocol numbers stay 
defined in `nuttx/can.h`.
   
   Found while looking at #17280 (ISO-TP). When a protocol is implemented it 
gets added back to the accepted list.
   
   ## Impact
   
   - Apps requesting an unimplemented CAN protocol now get `EPROTONOSUPPORT` 
instead of a raw socket.
   - No in-tree users affected. Every `socket(PF_CAN/AF_CAN, ...)` caller in 
nuttx and nuttx-apps uses `CAN_RAW` (cansend, candump, slcan, lely_master, 
opencyphal, sim_hostcan, mr-canhubk3 tja1153) or protocol 0 via 
`NET_SOCK_PROTOCOL` (netlib, getifaddrs, if_nametoindex, ...).
   - No change for `CAN_RAW`. No build or config changes.
   
   ## Testing
   
   Host: Ubuntu (x86_64), sim:can, built with both make and CMake/Ninja, no 
warnings. `tools/nxstyle` on `net/can/can_sockif.c`: clean.
   
   **socket(PF_CAN, SOCK_RAW, p)**, from a throwaway probe app on sim:can:
   
   | protocol  | before (master) | after              |
   |-----------|-----------------|--------------------|
   | 0         | OK              | OK                 |
   | CAN_RAW   | OK              | OK                 |
   | CAN_BCM   | OK              | -1, EPROTONOSUPPORT |
   | CAN_TP16  | OK              | -1, EPROTONOSUPPORT |
   | CAN_TP20  | OK              | -1, EPROTONOSUPPORT |
   | CAN_MCNET | OK              | -1, EPROTONOSUPPORT |
   | CAN_ISOTP | OK              | -1, EPROTONOSUPPORT |
   | CAN_J1939 | OK              | -1, EPROTONOSUPPORT |
   | 99        | -1, EPROTONOSUPPORT | -1, EPROTONOSUPPORT |
   
   **CAN_RAW regression check** against host vcan `can0`:
   - sim → host: `cansend can0 123#DEADBEEF` in NuttX, received on host as 
`123#DEADBEEF`
   - host → sim: host frame `321#112233`, NuttX `candump can0` printed `can0  
321  [3]  11 22 33`
   
   @raiden00pl please tell me if this conflicts with your ISO-TP branch.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to