3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

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.
This commit is contained in:
Denis Kenzior 2022-10-19 16:33:18 -05:00
parent 94ecdc799a
commit f1a713a0fa

View File

@ -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, static bool ie_build_cipher_suite(uint8_t *data, const uint8_t *oui,
const enum ie_rsn_cipher_suite suite) const enum ie_rsn_cipher_suite suite)
{ {
uint8_t selector;
switch (suite) { switch (suite) {
case IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER: case IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER:
memcpy(data, oui, 3); selector = 0;
data[3] = 0; goto done;
return true;
case IE_RSN_CIPHER_SUITE_WEP40: case IE_RSN_CIPHER_SUITE_WEP40:
memcpy(data, oui, 3); selector = 1;
data[3] = 1; goto done;
return true;
case IE_RSN_CIPHER_SUITE_TKIP: case IE_RSN_CIPHER_SUITE_TKIP:
memcpy(data, oui, 3); selector = 2;
data[3] = 2; goto done;
return true;
case IE_RSN_CIPHER_SUITE_CCMP: case IE_RSN_CIPHER_SUITE_CCMP:
memcpy(data, oui, 3); selector = 4;
data[3] = 4; goto done;
return true;
case IE_RSN_CIPHER_SUITE_WEP104: case IE_RSN_CIPHER_SUITE_WEP104:
memcpy(data, oui, 3); selector = 5;
data[3] = 5; goto done;
return true;
case IE_RSN_CIPHER_SUITE_BIP_CMAC: case IE_RSN_CIPHER_SUITE_BIP_CMAC:
memcpy(data, oui, 3); selector = 6;
data[3] = 6; goto done;
return true;
case IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC: case IE_RSN_CIPHER_SUITE_NO_GROUP_TRAFFIC:
memcpy(data, oui, 3); selector = 7;
data[3] = 7; goto done;
return true;
} }
return false; return false;
done:
memcpy(data, oui, 3);
data[3] = selector;
return true;
} }
#define RETURN_AKM(data, oui, id) \ #define RETURN_AKM(data, oui, id) \