eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit f1a713a0fae3b983ea97f846c19e01fa24e2fd98
parent 94ecdc799a83714388de8d499b80c3dd48dda798
Author: Denis Kenzior <denkenz@gmail.com>
Date:   Wed, 19 Oct 2022 16:33:18 -0500

ie: Simplify implementation

Instead of copy-pasting the same basic operation (memcpy & assignment),
use a goto and a common path instead.  This should also make it easier
for the compiler to optimize this function.

Diffstat:
Msrc/ie.c | 41++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/ie.c b/src/ie.c @@ -885,38 +885,37 @@ int ie_parse_osen_from_data(const uint8_t *data, size_t len, static bool ie_build_cipher_suite(uint8_t *data, const uint8_t *oui, const enum ie_rsn_cipher_suite suite) { + uint8_t selector; + switch (suite) { case IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER: - memcpy(data, oui, 3); - data[3] = 0; - return true; + selector = 0; + goto done; case IE_RSN_CIPHER_SUITE_WEP40: - memcpy(data, oui, 3); - data[3] = 1; - return true; + selector = 1; + goto done; case IE_RSN_CIPHER_SUITE_TKIP: - memcpy(data, oui, 3); - data[3] = 2; - return true; + selector = 2; + goto done; case IE_RSN_CIPHER_SUITE_CCMP: - memcpy(data, oui, 3); - data[3] = 4; - return true; + selector = 4; + goto done; case IE_RSN_CIPHER_SUITE_WEP104: - memcpy(data, oui, 3); - data[3] = 5; - return true; + selector = 5; + goto done; case IE_RSN_CIPHER_SUITE_BIP_CMAC: - memcpy(data, oui, 3); - data[3] = 6; - return true; + selector = 6; + goto done; case IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC: - memcpy(data, oui, 3); - data[3] = 7; - return true; + selector = 7; + goto done; } return false; +done: + memcpy(data, oui, 3); + data[3] = selector; + return true; } #define RETURN_AKM(data, oui, id) \