diff options
author | Ulrich Ölmann <u.oelmann@pengutronix.de> | 2018-12-18 14:57:50 +0100 |
---|---|---|
committer | Roland Hieber <rhi@pengutronix.de> | 2019-01-07 15:47:56 +0100 |
commit | 7bc669877217f54bf0f390205f481f18d33222f8 (patch) | |
tree | ae616eaa2b4c3d28cece91e375d0a12410af2966 | |
parent | 44122040c53042f68e93657450ef5e5ceaa48e4a (diff) | |
download | dt-utils-7bc669877217f54bf0f390205f481f18d33222f8.tar.gz dt-utils-7bc669877217f54bf0f390205f481f18d33222f8.tar.xz |
state: Add function to read state MAC
This ports the following barebox commit:
| commit 09f15cdb3817902897544296cc90d1eeff4a9487
| Author: Daniel Schultz <d.schultz@phytec.de>
| Date: Fri Nov 3 11:48:28 2017 +0100
|
| common: state: Add function to read state MAC
|
| This API function allows to receive a copy of a MAC address from
| variables in a state.
|
| Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
Signed-off-by: Roland Hieber <rhi@pengutronix.de>
-rw-r--r-- | src/barebox-state/state.c | 21 | ||||
-rw-r--r-- | src/state.h | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c index 2c613a9..0036b69 100644 --- a/src/barebox-state/state.c +++ b/src/barebox-state/state.c @@ -692,6 +692,27 @@ int state_get_name(const struct state *state, char const **name) return 0; } +int state_read_mac(struct state *state, const char *name, u8 *buf) +{ + struct state_variable *svar; + struct state_mac *mac; + + if (!state || !name || !buf) + return -EINVAL; + + svar = state_find_var(state, name); + if (IS_ERR(svar)) + return PTR_ERR(svar); + + if (svar->type->type != STATE_VARIABLE_TYPE_MAC) + return -EINVAL; + + mac = to_state_mac(svar); + memcpy(buf, mac->value, 6); + + return 0; +} + void state_info(void) { struct state *state; diff --git a/src/state.h b/src/state.h index ce420d1..888b491 100644 --- a/src/state.h +++ b/src/state.h @@ -23,4 +23,6 @@ int state_load_no_auth(struct state *state); int state_save(struct state *state); void state_info(void); +int state_read_mac(struct state *state, const char *name, u8 *buf); + #endif /* __STATE_H */ |