From 09f15cdb3817902897544296cc90d1eeff4a9487 Mon Sep 17 00:00:00 2001 From: Daniel Schultz Date: Fri, 3 Nov 2017 11:48:28 +0100 Subject: 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 Signed-off-by: Sascha Hauer --- common/state/state.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'common/state') 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; -- cgit v1.2.3