@@ -703,6 +703,17 @@ struct net_if_dev {
703
703
704
704
/** RFC 2863 operational status */
705
705
enum net_if_oper_state oper_state ;
706
+
707
+ /** Last time the operational state was changed.
708
+ * This is used to determine how long the interface has been in the
709
+ * current operational state.
710
+ *
711
+ * This value is set to 0 when the interface is created, and then
712
+ * updated whenever the operational state changes.
713
+ *
714
+ * The value is in milliseconds since boot.
715
+ */
716
+ int64_t oper_state_change_time ;
706
717
};
707
718
708
719
/**
@@ -906,6 +917,12 @@ static inline enum net_if_oper_state net_if_oper_state_set(
906
917
iface -> if_dev -> oper_state = oper_state ;
907
918
}
908
919
920
+ net_if_lock (iface );
921
+
922
+ iface -> if_dev -> oper_state_change_time = k_uptime_get ();
923
+
924
+ net_if_unlock (iface );
925
+
909
926
return iface -> if_dev -> oper_state ;
910
927
}
911
928
@@ -925,6 +942,34 @@ static inline enum net_if_oper_state net_if_oper_state(struct net_if *iface)
925
942
return iface -> if_dev -> oper_state ;
926
943
}
927
944
945
+ /**
946
+ * @brief Get an operational state change time of an interface
947
+ *
948
+ * @param iface Pointer to network interface
949
+ * @param change_time Pointer to store the change time. Time the operational
950
+ * state of an interface was last changed, in milliseconds since boot.
951
+ * If the interface operational state has not been changed yet,
952
+ * then the value is 0.
953
+ *
954
+ * @return 0 if ok, -EINVAL if operational state change time could not be
955
+ * retrieved (for example if iface or change_time is NULL).
956
+ */
957
+ static inline int net_if_oper_state_change_time (struct net_if * iface ,
958
+ int64_t * change_time )
959
+ {
960
+ if (iface == NULL || iface -> if_dev == NULL || change_time == NULL ) {
961
+ return - EINVAL ;
962
+ }
963
+
964
+ net_if_lock (iface );
965
+
966
+ * change_time = iface -> if_dev -> oper_state_change_time ;
967
+
968
+ net_if_unlock (iface );
969
+
970
+ return 0 ;
971
+ }
972
+
928
973
/**
929
974
* @brief Try sending a packet through a net iface
930
975
*
0 commit comments