diff options
author | Daniel Schultz <d.schultz@phytec.de> | 2017-11-03 11:48:28 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-11-07 07:47:10 +0100 |
commit | 09f15cdb3817902897544296cc90d1eeff4a9487 (patch) | |
tree | b328cabb4d0af3f9c5739371a7093023f1c99d66 | |
parent | dc74265d2ac074a18609d51bad1fdbd2bbcdd608 (diff) | |
download | barebox-09f15cdb3817902897544296cc90d1eeff4a9487.tar.gz barebox-09f15cdb3817902897544296cc90d1eeff4a9487.tar.xz |
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>
-rw-r--r-- | common/state/state.c | 21 | ||||
-rw-r--r-- | include/state.h | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/common/state/state.c b/common/state/state.c index 98a7db361a..6399bd3736 100644 --- a/common/state/state.c +++ b/common/state/state.c @@ -693,6 +693,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/include/state.h b/include/state.h index 63164f92e5..f1882ae026 100644 --- a/include/state.h +++ b/include/state.h @@ -23,4 +23,6 @@ int state_load(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 */ |