summaryrefslogtreecommitdiffstats
path: root/common/state
diff options
context:
space:
mode:
authorDaniel Schultz <d.schultz@phytec.de>2017-11-03 11:48:28 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-11-07 07:47:10 +0100
commit09f15cdb3817902897544296cc90d1eeff4a9487 (patch)
treeb328cabb4d0af3f9c5739371a7093023f1c99d66 /common/state
parentdc74265d2ac074a18609d51bad1fdbd2bbcdd608 (diff)
downloadbarebox-09f15cdb3817902897544296cc90d1eeff4a9487.tar.gz
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>
Diffstat (limited to 'common/state')
-rw-r--r--common/state/state.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/common/state/state.c b/common/state/state.c
index 98a7db3..6399bd3 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;