]> git.openfabrics.org - ~emulex/tmp/compat/.git/commitdiff
compat: add mac_pton()
authorHauke Mehrtens <hauke@hauke-m.de>
Wed, 24 Aug 2011 11:20:37 +0000 (13:20 +0200)
committerLuis R. Rodriguez <mcgrof@qca.qualcomm.com>
Thu, 25 Aug 2011 19:07:19 +0000 (12:07 -0700)
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
compat/Makefile
compat/compat-3.0.c [new file with mode: 0644]
include/linux/compat-3.0.h

index e2a6add66391398b297cf17880127c687104edf0..8e3739c4ea48b25cb7221c7f81b93abefad40534 100644 (file)
@@ -33,4 +33,5 @@ compat-$(CONFIG_COMPAT_KERNEL_2_6_38) += compat-2.6.38.o
 compat-$(CONFIG_COMPAT_KERNEL_2_6_39) += \
        compat-2.6.39.o \
        kstrtox.o
+compat-$(CONFIG_COMPAT_KERNEL_3_0) += compat-3.0.o
 
diff --git a/compat/compat-3.0.c b/compat/compat-3.0.c
new file mode 100644 (file)
index 0000000..312eea0
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2011    Hauke Mehrtens <hauke@hauke-m.de>
+ * Copyright 2011    Alexey Dobriyan <adobriyan@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Compatibility file for Linux wireless for kernels 3.0.
+ */
+
+#include <linux/compat.h>
+#include <linux/if_ether.h>
+
+int mac_pton(const char *s, u8 *mac)
+{
+       int i;
+
+       /* XX:XX:XX:XX:XX:XX */
+       if (strlen(s) < 3 * ETH_ALEN - 1)
+               return 0;
+
+       /* Don't dirty result unless string is valid MAC. */
+       for (i = 0; i < ETH_ALEN; i++) {
+               if (!strchr("0123456789abcdefABCDEF", s[i * 3]))
+                       return 0;
+               if (!strchr("0123456789abcdefABCDEF", s[i * 3 + 1]))
+                       return 0;
+               if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
+                       return 0;
+       }
+       for (i = 0; i < ETH_ALEN; i++) {
+               mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
+       }
+       return 1;
+}
+EXPORT_SYMBOL(mac_pton);
index 667ea387561b49489653c81a33cf36298f74cfb2..7954ddb12d9ed66e6a22cd409863f008813b2dce 100644 (file)
@@ -46,6 +46,8 @@ struct bcma_device_id {
 #define BCMA_ANY_CLASS         0xFF
 #endif /* BCMA_CORE */
 
+int mac_pton(const char *s, u8 *mac);
+
 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)) */
 
 #endif /* LINUX_3_0_COMPAT_H */