summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorCodrin Ciubotariu <codrin.ciubotariu@freescale.com>2015-09-09 18:00:51 +0300
committerYork Sun <yorksun@freescale.com>2015-09-21 08:29:47 -0700
commit0118e83ba4e1811515dc944a826758cad8a394b7 (patch)
tree6231b27301056b7507bf17afc85b5570d2d5d559 /common
parent68c929da6bf754ace639b2159e2d5b9e22323aaa (diff)
common/env_flags.c: Add function to validate a MAC address
The code that checks if a string has the format of a MAC address has been moved to a separate function called eth_validate_ethaddr_str(). This has been done to allow other components (such as vsc9953 driver) to validate a MAC address. Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@freescale.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: York Sun <yorksun@freescale.com>
Diffstat (limited to 'common')
-rw-r--r--common/env_flags.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/common/env_flags.c b/common/env_flags.c
index 5189f5b2dd..e682d85178 100644
--- a/common/env_flags.c
+++ b/common/env_flags.c
@@ -187,6 +187,31 @@ static void skip_num(int hex, const char *value, const char **end,
*end = value;
}
+#ifdef CONFIG_CMD_NET
+int eth_validate_ethaddr_str(const char *addr)
+{
+ const char *end;
+ const char *cur;
+ int i;
+
+ cur = addr;
+ for (i = 0; i < 6; i++) {
+ skip_num(1, cur, &end, 2);
+ if (cur == end)
+ return -1;
+ if (cur + 2 == end && is_hex_prefix(cur))
+ return -1;
+ if (i != 5 && *end != ':')
+ return -1;
+ if (i == 5 && *end != '\0')
+ return -1;
+ cur = end + 1;
+ }
+
+ return 0;
+}
+#endif
+
/*
* Based on the declared type enum, validate that the value string complies
* with that format
@@ -239,19 +264,8 @@ static int _env_flags_validate_type(const char *value,
}
break;
case env_flags_vartype_macaddr:
- cur = value;
- for (i = 0; i < 6; i++) {
- skip_num(1, cur, &end, 2);
- if (cur == end)
- return -1;
- if (cur + 2 == end && is_hex_prefix(cur))
- return -1;
- if (i != 5 && *end != ':')
- return -1;
- if (i == 5 && *end != '\0')
- return -1;
- cur = end + 1;
- }
+ if (eth_validate_ethaddr_str(value))
+ return -1;
break;
#endif
case env_flags_vartype_end: