blob: 4f652e6a045becc3ed4d039445d1e8126f003656 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <wlan/mlme/key.h>
#include <fuchsia/wlan/mlme/cpp/fidl.h>
#include <wlan/protocol/mac.h>
#include <optional>
namespace wlan {
namespace wlan_mlme = ::fuchsia::wlan::mlme;
std::optional<wlan_key_config_t> ToKeyConfig(const wlan_mlme::SetKeyDescriptor& key_descriptor) {
uint8_t key_type;
switch (key_descriptor.key_type) {
case wlan_mlme::KeyType::PAIRWISE:
key_type = WLAN_KEY_TYPE_PAIRWISE;
break;
case wlan_mlme::KeyType::PEER_KEY:
key_type = WLAN_KEY_TYPE_PEER;
break;
case wlan_mlme::KeyType::IGTK:
key_type = WLAN_KEY_TYPE_IGTK;
break;
default:
key_type = WLAN_KEY_TYPE_GROUP;
break;
}
wlan_key_config_t key_config = {};
memcpy(key_config.key, key_descriptor.key.data(), key_descriptor.key.size());
key_config.key_type = key_type;
key_config.key_len = static_cast<uint8_t>(key_descriptor.key.size());
key_config.key_idx = key_descriptor.key_id;
key_config.protection = WLAN_PROTECTION_RX_TX;
key_config.cipher_type = key_descriptor.cipher_suite_type;
memcpy(key_config.cipher_oui, key_descriptor.cipher_suite_oui.data(),
sizeof(key_config.cipher_oui));
memcpy(key_config.peer_addr, key_descriptor.address.data(), sizeof(key_config.peer_addr));
return key_config;
}
} // namespace wlan