+static bool
+read_int_file(int dir_fd, const char *file, int *val)
+{
+ char buf[64];
+ bool ret = false;
+
+ ret = read_string_file(dir_fd, file, buf, sizeof(buf));
+ if (ret)
+ *val = strtoul(buf, NULL, 0);
+
+ return ret;
+}
+
+/* Assume advertised flags == supported flags */
+static const struct {
+ uint32_t mask;
+ const char *name;
+} ethtool_link_modes[] = {
+ { ADVERTISED_10baseT_Half, "10H" },
+ { ADVERTISED_10baseT_Full, "10F" },
+ { ADVERTISED_100baseT_Half, "100H" },
+ { ADVERTISED_100baseT_Full, "100F" },
+ { ADVERTISED_1000baseT_Half, "1000H" },
+ { ADVERTISED_1000baseT_Full, "1000F" },
+};
+
+static void system_add_link_modes(struct blob_buf *b, __u32 mask)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(ethtool_link_modes); i++) {
+ if (mask & ethtool_link_modes[i].mask)
+ blobmsg_add_string(b, NULL, ethtool_link_modes[i].name);
+ }
+}
+