^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Intel Management Engine Interface (Intel MEI) Linux driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Intel MEI Interface Header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This file is provided under a dual BSD/GPLv2 license. When using or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * redistributing this file, you may do so under either license.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * GPL LICENSE SUMMARY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright(c) 2012 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * it under the terms of version 2 of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * This program is distributed in the hope that it will be useful, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * You should have received a copy of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * along with this program; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * The full GNU General Public License is included in this distribution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * in the file called LICENSE.GPL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Contact Information:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * linux-mei@linux.intel.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * http://www.intel.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * BSD LICENSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * * Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * * Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * notice, this list of conditions and the following disclaimer in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * the documentation and/or other materials provided with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * * Neither the name Intel Corporation nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #include <sys/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #include <stdint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #include <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #include <bits/wordsize.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #include <linux/mei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Intel Management Engine Interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define mei_msg(_me, fmt, ARGS...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (_me->verbose) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) fprintf(stderr, fmt, ##ARGS); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define mei_err(_me, fmt, ARGS...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) fprintf(stderr, "Error: " fmt, ##ARGS); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct mei {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) uuid_le guid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) bool initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) bool verbose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned int buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned char prot_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static void mei_deinit(struct mei *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (cl->fd != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) close(cl->fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) cl->fd = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) cl->buf_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) cl->prot_ver = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) cl->initialized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static bool mei_init(struct mei *me, const uuid_le *guid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) unsigned char req_protocol_version, bool verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct mei_client *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct mei_connect_client_data data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) me->verbose = verbose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) me->fd = open("/dev/mei0", O_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (me->fd == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) mei_err(me, "Cannot establish a handle to the Intel MEI driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) memcpy(&me->guid, guid, sizeof(*guid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) memset(&data, 0, sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) me->initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) memcpy(&data.in_client_uuid, &me->guid, sizeof(me->guid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) result = ioctl(me->fd, IOCTL_MEI_CONNECT_CLIENT, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) mei_err(me, "IOCTL_MEI_CONNECT_CLIENT receive message. err=%d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) cl = &data.out_client_properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) mei_msg(me, "max_message_length %d\n", cl->max_msg_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) mei_msg(me, "protocol_version %d\n", cl->protocol_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if ((req_protocol_version > 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) (cl->protocol_version != req_protocol_version)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) mei_err(me, "Intel MEI protocol version not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) me->buf_size = cl->max_msg_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) me->prot_ver = cl->protocol_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) mei_deinit(me);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static ssize_t mei_recv_msg(struct mei *me, unsigned char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ssize_t len, unsigned long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ssize_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) mei_msg(me, "call read length = %zd\n", len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) rc = read(me->fd, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) mei_err(me, "read failed with status %zd %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) rc, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) mei_deinit(me);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) mei_msg(me, "read succeeded with result %zd\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ssize_t len, unsigned long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct timeval tv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ssize_t written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ssize_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) fd_set set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) tv.tv_sec = timeout / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) tv.tv_usec = (timeout % 1000) * 1000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) mei_msg(me, "call write length = %zd\n", len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) written = write(me->fd, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (written < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) rc = -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) mei_err(me, "write failed with status %zd %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) written, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) FD_ZERO(&set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) FD_SET(me->fd, &set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) rc = select(me->fd + 1 , &set, NULL, NULL, &tv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (rc > 0 && FD_ISSET(me->fd, &set)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) mei_msg(me, "write success\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) } else if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) mei_err(me, "write failed on timeout with status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) } else { /* rc < 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) mei_err(me, "write failed on select with status %zd\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) rc = written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) mei_deinit(me);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * Intel Advanced Management Technology ME Client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #define AMT_MAJOR_VERSION 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define AMT_MINOR_VERSION 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define AMT_STATUS_SUCCESS 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define AMT_STATUS_INTERNAL_ERROR 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #define AMT_STATUS_NOT_READY 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #define AMT_STATUS_INVALID_AMT_MODE 0x3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #define AMT_STATUS_INVALID_MESSAGE_LENGTH 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #define AMT_STATUS_HOST_IF_EMPTY_RESPONSE 0x4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #define AMT_STATUS_SDK_RESOURCES 0x1004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define AMT_BIOS_VERSION_LEN 65
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #define AMT_VERSIONS_NUMBER 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define AMT_UNICODE_STRING_LEN 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct amt_unicode_string {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) uint16_t length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) char string[AMT_UNICODE_STRING_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) } __attribute__((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct amt_version_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct amt_unicode_string description;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct amt_unicode_string version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) } __attribute__((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct amt_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) uint8_t major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) uint8_t minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) } __attribute__((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct amt_code_versions {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) uint8_t bios[AMT_BIOS_VERSION_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) uint32_t count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct amt_version_type versions[AMT_VERSIONS_NUMBER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) } __attribute__((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * Intel Advanced Management Technology Host Interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct amt_host_if_msg_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct amt_version version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) uint16_t _reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) uint32_t command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) uint32_t length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) } __attribute__((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct amt_host_if_resp_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct amt_host_if_msg_header header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) unsigned char data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) } __attribute__((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) const uuid_le MEI_IAMTHIF = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 0xac, 0xa8, 0x46, 0xe0, 0xff, 0x65, 0x81, 0x4c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #define AMT_HOST_IF_CODE_VERSIONS_REQUEST 0x0400001A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #define AMT_HOST_IF_CODE_VERSIONS_RESPONSE 0x0480001A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) const struct amt_host_if_msg_header CODE_VERSION_REQ = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .version = {AMT_MAJOR_VERSION, AMT_MINOR_VERSION},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ._reserved = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) .command = AMT_HOST_IF_CODE_VERSIONS_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) .length = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct amt_host_if {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct mei mei_cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) unsigned long send_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) bool initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static bool amt_host_if_init(struct amt_host_if *acmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) unsigned long send_timeout, bool verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) acmd->send_timeout = (send_timeout) ? send_timeout : 20000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0, verbose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return acmd->initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static void amt_host_if_deinit(struct amt_host_if *acmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) mei_deinit(&acmd->mei_cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) acmd->initialized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static uint32_t amt_verify_code_versions(const struct amt_host_if_resp_header *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) uint32_t status = AMT_STATUS_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct amt_code_versions *code_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) size_t code_ver_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) uint32_t ver_type_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) uint32_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) uint32_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) code_ver = (struct amt_code_versions *)resp->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* length - sizeof(status) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) code_ver_len = resp->header.length - sizeof(uint32_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ver_type_cnt = code_ver_len -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) sizeof(code_ver->bios) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) sizeof(code_ver->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (code_ver->count != ver_type_cnt / sizeof(struct amt_version_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) status = AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) for (i = 0; i < code_ver->count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) len = code_ver->versions[i].description.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (len > AMT_UNICODE_STRING_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) status = AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) len = code_ver->versions[i].version.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (code_ver->versions[i].version.string[len] != '\0' ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) len != strlen(code_ver->versions[i].version.string)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) status = AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static uint32_t amt_verify_response_header(uint32_t command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) const struct amt_host_if_msg_header *resp_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) uint32_t response_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (response_size < sizeof(struct amt_host_if_resp_header)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) } else if (response_size != (resp_hdr->length +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) sizeof(struct amt_host_if_msg_header))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) } else if (resp_hdr->command != command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) } else if (resp_hdr->_reserved != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) } else if (resp_hdr->version.major != AMT_MAJOR_VERSION ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) resp_hdr->version.minor < AMT_MINOR_VERSION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return AMT_STATUS_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static uint32_t amt_host_if_call(struct amt_host_if *acmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) const unsigned char *command, ssize_t command_sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) uint8_t **read_buf, uint32_t rcmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) unsigned int expected_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) uint32_t in_buf_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ssize_t out_buf_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) ssize_t written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct amt_host_if_resp_header *msg_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) in_buf_sz = acmd->mei_cl.buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) *read_buf = (uint8_t *)malloc(sizeof(uint8_t) * in_buf_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (*read_buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return AMT_STATUS_SDK_RESOURCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) memset(*read_buf, 0, in_buf_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) msg_hdr = (struct amt_host_if_resp_header *)*read_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) written = mei_send_msg(&acmd->mei_cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) command, command_sz, acmd->send_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (written != command_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) out_buf_sz = mei_recv_msg(&acmd->mei_cl, *read_buf, in_buf_sz, 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (out_buf_sz <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return AMT_STATUS_HOST_IF_EMPTY_RESPONSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) status = msg_hdr->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (status != AMT_STATUS_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) status = amt_verify_response_header(rcmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) &msg_hdr->header, out_buf_sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (status != AMT_STATUS_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (expected_sz && expected_sz != out_buf_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return AMT_STATUS_INTERNAL_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return AMT_STATUS_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static uint32_t amt_get_code_versions(struct amt_host_if *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct amt_code_versions *versions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct amt_host_if_resp_header *response = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) status = amt_host_if_call(cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) (const unsigned char *)&CODE_VERSION_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) sizeof(CODE_VERSION_REQ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) (uint8_t **)&response,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) AMT_HOST_IF_CODE_VERSIONS_RESPONSE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (status != AMT_STATUS_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) status = amt_verify_code_versions(response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (status != AMT_STATUS_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) memcpy(versions, response->data, sizeof(struct amt_code_versions));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (response != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) free(response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /************************** end of amt_host_if_command ***********************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) int main(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct amt_code_versions ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) struct amt_host_if acmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) uint32_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) bool verbose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) verbose = (argc > 1 && strcmp(argv[1], "-v") == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (!amt_host_if_init(&acmd, 5000, verbose)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) status = amt_get_code_versions(&acmd, &ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) amt_host_if_deinit(&acmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) case AMT_STATUS_HOST_IF_EMPTY_RESPONSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) printf("Intel AMT: DISABLED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) case AMT_STATUS_SUCCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) printf("Intel AMT: ENABLED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) for (i = 0; i < ver.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) printf("%s:\t%s\n", ver.versions[i].description.string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) ver.versions[i].version.string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) printf("An error has occurred\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }