summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-02-27 08:23:14 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-02-27 08:23:14 -0600
commit798444f612ee53799dbab255f80b34cd53bf43d5 (patch)
treea25266c7b5909c26dd3378925f98ecc79d712d77
parent76fd203ea431d30a815a30b8eb39a96ed451d4de (diff)
downloadnuttx-798444f612ee53799dbab255f80b34cd53bf43d5.tar.gz
nuttx-798444f612ee53799dbab255f80b34cd53bf43d5.tar.bz2
nuttx-798444f612ee53799dbab255f80b34cd53bf43d5.zip
Networking: Improve the network device registration logic. When multiple link types are used, modify how each interface number is assigned to the device name by incrementing the device number individually for each interface link type. From Max Neklyudov.
-rw-r--r--nuttx/net/netdev/netdev_register.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/nuttx/net/netdev/netdev_register.c b/nuttx/net/netdev/netdev_register.c
index a1f5c1251..b05119400 100644
--- a/nuttx/net/netdev/netdev_register.c
+++ b/nuttx/net/netdev/netdev_register.c
@@ -1,7 +1,7 @@
/****************************************************************************
* net/netdev/netdev_register.c
*
- * Copyright (C) 2007-2012, 2014 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2012, 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -77,7 +77,11 @@
* Private Data
****************************************************************************/
+/* Then next available device number */
+
+#ifndef CONFIG_NET_MULTILINK
static int g_next_devnum = 0;
+#endif
/****************************************************************************
* Public Data
@@ -92,6 +96,55 @@ struct net_driver_s *g_netdevices = NULL;
****************************************************************************/
/****************************************************************************
+ * Function: find_devnum
+ *
+ * Description:
+ * Given a device name format string, find the next device number for the
+ * class of device represented by that format string.
+ *
+ * Parameters:
+ * devfmt - The device format string
+ *
+ * Returned Value:
+ * The next device number for that device class
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_MULTILINK
+static int find_devnum(FAR const char *devfmt)
+{
+ FAR struct net_driver_s *curr;
+ size_t fmt_size;
+ int result = 0;
+
+ fmt_size = strlen(devfmt);
+
+ /* Assumed that devfmt is xxx%d */
+
+ DEBUGASSERT(fmt_size > 2);
+ fmt_size -= 2;
+
+ /* Search the list of currently registered network devices */
+
+ for (curr = g_netdevices; curr; curr = curr->flink )
+ {
+ /* Does this device name match the format we were given? */
+
+ if (strncmp(curr->d_ifname, devfmt, fmt_size) == 0)
+ {
+ /* Yes.. increment the candidate device number */
+
+ result++;
+ }
+ }
+
+ /* Return this next device number for this format */
+
+ return result;
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -179,10 +232,16 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
devfmt = NETDEV_DEFAULT_FORMAT;
#endif
- /* Assign a device name to the interface */
+ /* Get the next available device number and sssign a device name to
+ * the interface
+ */
netdev_semtake();
+#ifdef CONFIG_NET_MULTILINK
+ devnum = find_devnum(devfmt);
+#else
devnum = g_next_devnum++;
+#endif
snprintf(dev->d_ifname, IFNAMSIZ, devfmt, devnum );
/* Add the device to the list of known network devices */