/* Copyright 2019 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include "info.h" #include #include #include #include "commands.h" #include "utils.h" void out_text(const std::string name, const std::vector value, const unsigned char delimeter=' ') { std::cout << name << ": "; int char_count = 1; for (unsigned char tmp : value) { std::cout << std::setfill('0') << std::setw(2) << std::hex << (unsigned int) tmp; if (char_count++ < value.size()) { std::cout << delimeter; } } std::cout << std::endl; } void out_text(const std::string name, const std::string value) { std::cout << name << ": "; std::cout << value; std::cout << std::endl; } void out_text(const std::string name, const int value) { std::cout << name << ": "; std::cout << value; std::cout << std::endl; } void out_text(const std::string name, const std::vector value) { int count = 1; std::cout << name << std::endl; for (std::string tmp : value) { std::cout << std::setfill('0') << std::setw(2) << count++ << ":"; std::cout << tmp << std::endl; } } bool info_get_version() { std::string tmp; if (!cmd_get_version(tmp)) return false; out_text("Version", tmp); return true; } bool info_get_build_number() { std::string tmp; if (!cmd_get_build_number(tmp)) return false; out_text("Build number", tmp); return true; } bool info_get_sku() { std::string tmp; if (!cmd_get_sku(tmp)) return false; out_text("SKU", tmp); return true; } bool info_get_uuid() { std::string uuid_string; std::vector tmp; if (!cmd_get_uuid(tmp)) return false; if (!util_format_uuid(tmp, uuid_string)) return false; out_text("UUID", uuid_string); return true; } bool info_get_control_mode() { int tmp; if (!cmd_get_control_mode(tmp)) return false; std::string control_mode; if (tmp == 0) control_mode = "pre-provisioning state"; else if (tmp == 1) control_mode = "activated in client control mode"; else if (tmp == 2) control_mode = "activated in admin control mode"; out_text("Control mode", control_mode); return true; } bool info_get_dns_suffix() { std::string tmp; if (!cmd_get_dns_suffix(tmp)) return false; out_text("DNS suffix", tmp); return true; } bool info_get_wired_mac_address() { std::vector tmp; if (!cmd_get_wired_mac_address(tmp)) return false; out_text("Wired MAC address", tmp, '-'); return true; } bool info_get_certificate_hashes() { std::vector tmp; if (!cmd_get_certificate_hashes(tmp)) return false; out_text("Certificate hashes", tmp); return true; } bool info_get_all() { std::vector tmp; if (info_get_version() && info_get_build_number() && info_get_sku() && info_get_uuid() && info_get_control_mode() && info_get_dns_suffix() && info_get_wired_mac_address() && info_get_certificate_hashes()) { return true; } return true; } bool info_get(const std::string info) { if (info.compare("ver") == 0) { return info_get_version(); } else if (info.compare("build") == 0) { return info_get_build_number(); } else if (info.compare("sku") == 0) { return info_get_sku(); } else if (info.compare("uuid") == 0) { return info_get_uuid(); } else if (info.compare("mode") == 0) { return info_get_control_mode(); } else if (info.compare("dns") == 0) { return info_get_dns_suffix(); } else if (info.compare("mac") == 0) { return info_get_wired_mac_address(); } else if (info.compare("cert") == 0) { return info_get_certificate_hashes(); } else if (info.compare("all") == 0) { return info_get_all(); } return false; }