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

commit 835e8fa1db4b072124ebd3ffad076830854b9d9f
Author: wangjinjing1 <[email protected]>
AuthorDate: Mon Nov 16 15:01:00 2026 +0800

    net/can: add can transceiver state ioctl cmd
    
    Add SIOCGCANTRSVSTATE and SIOCSCANTRSVSTATE to get and set the state of
    the CAN/LIN transceiver, independently of the controller state.  This is
    needed for power management: a board can put the transceiver into sleep
    or standby to save power and bring it back to normal before use.
    
    The three states are defined by enum can_ioctl_transv_state_e
    (CAN_TRANSV_SLEEP / CAN_TRANSV_STANDBY / CAN_TRANSV_NORMAL) and the
    argument is carried in the new can_ioctl_transv_state_s member of the
    ifreq/lifreq union.  Both commands are dispatched to the driver through
    the common CAN ioctl path in netdev_ioctl.c.
    
    The command numbers (0x0046/0x0047) differ from the original downstream
    change because 0x0043-0x0045 are already used upstream (VLAN and
    SIOCGCANERRORS).
    
    Signed-off-by: wangjinjing <[email protected]>
---
 include/net/if.h          | 21 +++++++++++++++++++++
 include/nuttx/net/ioctl.h |  2 ++
 net/netdev/netdev_ioctl.c |  4 ++++
 3 files changed, 27 insertions(+)

diff --git a/include/net/if.h b/include/net/if.h
index 4a8ef1a0220..52c44d4b7be 100644
--- a/include/net/if.h
+++ b/include/net/if.h
@@ -237,6 +237,19 @@ struct can_ioctl_state_s
   enum can_ioctl_state_e state;
 };
 
+enum can_ioctl_transv_state_e
+{
+  CAN_TRANSV_SLEEP   = 0,     /* The can/lin transceiver sleep state */
+  CAN_TRANSV_STANDBY = 1,     /* The can/lin transceiver standby state */
+  CAN_TRANSV_NORMAL  = 2,     /* The can/lin transceiver normal state */
+};
+
+struct can_ioctl_transv_state_s
+{
+  uintptr_t priv;             /* This is private data. */
+  enum can_ioctl_transv_state_e state;
+};
+
 /* Fault confinement and error counters, SIOCGCANERRORS ioctl command.
  * WARNING is error-active with either error counter at or above 96;
  * PASSIVE and BUSOFF follow the controller's own state.
@@ -284,6 +297,10 @@ struct lifreq
     struct can_ioctl_filter_s  lifru_can_filter;     /* CAN filter request 
data */
     struct can_ioctl_state_s   lifru_can_state;      /* CAN/LIN controller 
state */
     struct can_ioctl_errors_s  lifru_can_errors;     /* CAN error counters */
+
+    /* CAN/LIN transceiver state */
+
+    struct can_ioctl_transv_state_s lifru_can_transv_state;
   } lifr_ifru;
 };
 
@@ -343,6 +360,10 @@ struct ifreq
     struct can_ioctl_filter_s  ifru_can_filter;     /* CAN filter request data 
*/
     struct can_ioctl_state_s   ifru_can_state;      /* CAN/LIN controller 
state */
     struct can_ioctl_errors_s  ifru_can_errors;     /* CAN error counters */
+
+    /* CAN/LIN transceiver state */
+
+    struct can_ioctl_transv_state_s ifru_can_transv_state;
     FAR void                  *ifru_data;           /* For use by interface */
   } ifr_ifru;
 };
diff --git a/include/nuttx/net/ioctl.h b/include/nuttx/net/ioctl.h
index b532e44afe8..c3d5f14c3dc 100644
--- a/include/nuttx/net/ioctl.h
+++ b/include/nuttx/net/ioctl.h
@@ -129,6 +129,8 @@
 #define SIOCSCANSTATE      _SIOC(0x0042)  /* Set the LIN/CAN controller state 
*/
 #define SIOCGCANERRORS     _SIOC(0x0045)  /* Get CAN error counters and fault
                                            * confinement state */
+#define SIOCGCANTRSVSTATE  _SIOC(0x0046)  /* Get state from CAN transceiver */
+#define SIOCSCANTRSVSTATE  _SIOC(0x0047)  /* Set the CAN transceiver state */
 #define SIOCCANOFLUSH      _SIOC(0x0048)  /* Flush data written but not 
transmitted */
 
 /* Network socket control ***************************************************/
diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c
index be2aa60463a..6f907f17206 100644
--- a/net/netdev/netdev_ioctl.c
+++ b/net/netdev/netdev_ioctl.c
@@ -788,6 +788,8 @@ static ssize_t net_ioctl_ifreq_arglen(uint8_t domain, int 
cmd)
       case SIOCGCANSTATE:
       case SIOCSCANSTATE:
       case SIOCGCANERRORS:
+      case SIOCGCANTRSVSTATE:
+      case SIOCSCANTRSVSTATE:
       case SIOCCANOFLUSH:
       case SIOCSIFNAME:
       case SIOCGIFNAME:
@@ -1375,6 +1377,8 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int 
cmd,
       case SIOCGCANSTATE:      /* Get state from a CAN/LIN controller */
       case SIOCSCANSTATE:      /* Set the LIN/CAN controller state */
       case SIOCGCANERRORS:     /* Get CAN error counters and state */
+      case SIOCGCANTRSVSTATE:  /* Get state from CAN transceiver */
+      case SIOCSCANTRSVSTATE:  /* Set the CAN transceiver state */
       case SIOCCANOFLUSH:      /* Flush data written but not transmitted */
         if (dev->d_ioctl)
           {

Reply via email to