2
* Copyright 2011 Hauke Mehrtens <hauke@hauke-m.de>
3
* Copyright 2011 Alexey Dobriyan <adobriyan@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation.
9
* Compatibility file for Linux wireless for kernels 3.0.
12
#include <linux/compat.h>
13
#include <linux/if_ether.h>
15
int mac_pton(const char *s, u8 *mac)
19
/* XX:XX:XX:XX:XX:XX */
20
if (strlen(s) < 3 * ETH_ALEN - 1)
23
/* Don't dirty result unless string is valid MAC. */
24
for (i = 0; i < ETH_ALEN; i++) {
25
if (!strchr("0123456789abcdefABCDEF", s[i * 3]))
27
if (!strchr("0123456789abcdefABCDEF", s[i * 3 + 1]))
29
if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
32
for (i = 0; i < ETH_ALEN; i++) {
33
mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
37
EXPORT_SYMBOL(mac_pton);
39
#define kstrto_from_user(f, g, type) \
40
int f(const char __user *s, size_t count, unsigned int base, type *res) \
42
/* sign, base 2 representation, newline, terminator */ \
43
char buf[1 + sizeof(type) * 8 + 1 + 1]; \
45
count = min(count, sizeof(buf) - 1); \
46
if (copy_from_user(buf, s, count)) \
49
return g(buf, base, res); \
53
kstrto_from_user(kstrtoull_from_user, kstrtoull, unsigned long long);
54
kstrto_from_user(kstrtoll_from_user, kstrtoll, long long);
55
kstrto_from_user(kstrtoul_from_user, kstrtoul, unsigned long);
56
kstrto_from_user(kstrtol_from_user, kstrtol, long);
57
kstrto_from_user(kstrtouint_from_user, kstrtouint, unsigned int);
58
kstrto_from_user(kstrtoint_from_user, kstrtoint, int);
59
kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);
60
kstrto_from_user(kstrtos16_from_user, kstrtos16, s16);
61
kstrto_from_user(kstrtou8_from_user, kstrtou8, u8);
62
kstrto_from_user(kstrtos8_from_user, kstrtos8, s8);