| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* qmi-firmware-update -- Command line tool to update firmware in QMI devices |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* Copyright (C) 2019 Zodiac Inflight Innovations |
| 19 |
* Copyright (C) 2019 Aleksander Morgado <[email protected]> |
| 20 |
* |
| 21 |
* The definitions in this header file are imported from libopenpst: |
| 22 |
* https://github.com/openpst/libopenpst |
| 23 |
* And from CodeAurora's quic/imm/imm/qdl: |
| 24 |
* https://portland.source.codeaurora.org/quic/imm/imm/qdl |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef QFU_SAHARA_MESSAGE_H |
| 28 |
#define QFU_SAHARA_MESSAGE_H |
| 29 |
|
| 30 |
#include <glib-object.h> |
| 31 |
#include <gio/gio.h> |
| 32 |
|
| 33 |
#include "qfu-image.h" |
| 34 |
|
| 35 |
G_BEGIN_DECLS |
| 36 |
|
| 37 |
typedef struct _QfuSaharaHeader QfuSaharaHeader; |
| 38 |
struct _QfuSaharaHeader { |
| 39 |
guint32 cmd; |
| 40 |
guint32 size; |
| 41 |
} __attribute__ ((packed)); |
| 42 |
|
| 43 |
#define QFU_SAHARA_MESSAGE_MAX_HEADER_SIZE sizeof (QfuSaharaHeader) |
| 44 |
#define QFU_SAHARA_MESSAGE_MAX_PACKET_SIZE 0x400 |
| 45 |
|
| 46 |
typedef enum { |
| 47 |
QFU_SAHARA_CMD_HELLO_REQ = 0x01, /* Initialize connection and protocol */ |
| 48 |
QFU_SAHARA_CMD_HELLO_RSP = 0x02, /* Acknowledge connection/protocol, mode of operation */ |
| 49 |
QFU_SAHARA_CMD_COMMAND_READ_DATA = 0x03, /* Read specified number of bytes from host */ |
| 50 |
QFU_SAHARA_CMD_COMMAND_END_IMAGE_TRANSFER = 0x04, /* image transfer end / target transfer failure */ |
| 51 |
QFU_SAHARA_CMD_COMMAND_DONE = 0x05, /* Acknowledgement: image transfer is complete */ |
| 52 |
QFU_SAHARA_CMD_COMMAND_DONE_RESPONSE = 0x06, /* Target is exiting protocol */ |
| 53 |
QFU_SAHARA_CMD_COMMAND_RESET = 0x07, /* Instruct target to perform a reset */ |
| 54 |
QFU_SAHARA_CMD_COMMAND_RESET_RESPONSE = 0x08, /* Indicate to host that target is about to reset */ |
| 55 |
QFU_SAHARA_CMD_COMMAND_MEMORY_DEBUG = 0x09, /* Indicate to host: target debug mode & ready to transfer memory content */ |
| 56 |
QFU_SAHARA_CMD_COMMAND_MEMORY_READ = 0x0A, /* Read number of bytes, starting from a specified address */ |
| 57 |
QFU_SAHARA_CMD_COMMAND_READY = 0x0B, /* Indicate to host: target ready to receive client commands, */ |
| 58 |
QFU_SAHARA_CMD_COMMAND_SWITCH_MODE = 0x0C, /* Switch to a mode defined in enum SAHARA_MODE */ |
| 59 |
QFU_SAHARA_CMD_COMMAND_EXECUTE_REQ = 0x0D, /* Indicate to host: to execute a given client command */ |
| 60 |
QFU_SAHARA_CMD_COMMAND_EXECUTE_RSP = 0x0E, /* Indicate to host: target command execution status */ |
| 61 |
QFU_SAHARA_CMD_COMMAND_EXECUTE_DATA = 0x0F, /* Indicate to target that host is ready to receive (more) data */ |
| 62 |
QFU_SAHARA_CMD_COMMAND_MEMORY_DEBUG_64 = 0x10, |
| 63 |
QFU_SAHARA_CMD_COMMAND_MEMORY_READ_64 = 0x11, |
| 64 |
} QfuSaharaCmd; |
| 65 |
|
| 66 |
typedef enum { |
| 67 |
QFU_SAHARA_MODE_IMAGE_TX_PENDING = 0x00, |
| 68 |
QFU_SAHARA_MODE_IMAGE_TX_COMPLETE = 0x01, |
| 69 |
QFU_SAHARA_MODE_MEMORY_DEBUG = 0x02, |
| 70 |
QFU_SAHARA_MODE_COMMAND = 0x03, |
| 71 |
} QfuSaharaMode; |
| 72 |
|
| 73 |
typedef enum { |
| 74 |
QFU_SAHARA_STATUS_SUCCESS = 0x00, |
| 75 |
QFU_SAHARA_STATUS_INVALID_COMMAND = 0x01, |
| 76 |
QFU_SAHARA_STATUS_PROTOCOL_MISMATCH = 0x02, |
| 77 |
QFU_SAHARA_STATUS_INVALID_TARGET_PROTOCOL = 0x03, |
| 78 |
QFU_SAHARA_STATUS_INVALID_HOST_PROTOCOL = 0x04, |
| 79 |
QFU_SAHARA_STATUS_INVALID_PACKET_SIZE = 0x05, |
| 80 |
QFU_SAHARA_STATUS_UNEXPECTED_IMAGE_ID = 0x06, |
| 81 |
QFU_SAHARA_STATUS_INVALID_HEADER_SIZE = 0x07, |
| 82 |
QFU_SAHARA_STATUS_INVALID_DATA_SIZE = 0x08, |
| 83 |
QFU_SAHARA_STATUS_INVALID_IMAGE_TYPE = 0x09, |
| 84 |
QFU_SAHARA_STATUS_INVALID_TX_LENGTH = 0x0A, |
| 85 |
QFU_SAHARA_STATUS_INVALID_RX_LENGTH = 0x0B, |
| 86 |
QFU_SAHARA_STATUS_TX_RX_ERROR = 0x0C, |
| 87 |
QFU_SAHARA_STATUS_READ_DATA_ERROR = 0x0D, |
| 88 |
QFU_SAHARA_STATUS_UNSUPPORTED_NUM_PHDRS = 0x0E, |
| 89 |
QFU_SAHARA_STATUS_INVALID_PHDR_SIZE = 0x0F, |
| 90 |
QFU_SAHARA_STATUS_MULTIPLE_SHARED_SEG = 0x10, |
| 91 |
QFU_SAHARA_STATUS_UNINIT_PHDR_LOC = 0x11, |
| 92 |
QFU_SAHARA_STATUS_INVALID_DEST_ADDRESS = 0x12, |
| 93 |
QFU_SAHARA_STATUS_INVALID_IMAGE_HEADER_SIZE = 0x13, |
| 94 |
QFU_SAHARA_STATUS_INVALID_ELF_HEADER = 0x14, |
| 95 |
QFU_SAHARA_STATUS_UNKNOWN_ERROR = 0x15, |
| 96 |
QFU_SAHARA_STATUS_TIMEOUT_RX = 0x16, |
| 97 |
QFU_SAHARA_STATUS_TIMEOUT_TX = 0x17, |
| 98 |
QFU_SAHARA_STATUS_INVALID_MODE = 0x18, |
| 99 |
QFU_SAHARA_STATUS_INVALID_MEMORY_READ = 0x19, |
| 100 |
QFU_SAHARA_STATUS_INVALID_DATA_SIZE_REQUEST = 0x1A, |
| 101 |
QFU_SAHARA_STATUS_MEMORY_DEBUG_NOT_SUPPORTED = 0x1B, |
| 102 |
QFU_SAHARA_STATUS_INVALID_MODE_SWITCH = 0x1C, |
| 103 |
QFU_SAHARA_STATUS_EXEC_FAILURE = 0x1D, |
| 104 |
QFU_SAHARA_STATUS_EXEC_CMD_INVALID_PARAM = 0x1E, |
| 105 |
QFU_SAHARA_STATUS_EXEC_CMD_UNSUPPORTED = 0x1F, |
| 106 |
QFU_SAHARA_STATUS_EXEC_DATA_INVALID = 0x20, |
| 107 |
QFU_SAHARA_STATUS_HASH_TABLE_AUTH_FAILURE = 0x21, |
| 108 |
QFU_SAHARA_STATUS_HASH_VERIFICATION_FAILURE = 0x22, |
| 109 |
QFU_SAHARA_STATUS_HASH_TABLE_NOT_FOUND = 0x23, |
| 110 |
QFU_SAHARA_STATUS_TARGET_INIT_FAILURE = 0x24, |
| 111 |
QFU_SAHARA_STATUS_IMAGE_AUTH_FAILURE = 0x25, |
| 112 |
QFU_SAHARA_STATUS_INVALID_IMG_HASH_TABLE_SIZE = 0x26, |
| 113 |
} QfuSaharaStatus; |
| 114 |
|
| 115 |
gsize qfu_sahara_response_hello_build (guint8 *buffer, |
| 116 |
gsize buffer_len); |
| 117 |
gsize qfu_sahara_request_switch_build (guint8 *buffer, |
| 118 |
gsize buffer_len); |
| 119 |
gsize qfu_sahara_request_switch_data_build (guint8 *buffer, |
| 120 |
gsize buffer_len); |
| 121 |
gboolean qfu_sahara_request_hello_parse (const guint8 *buffer, |
| 122 |
gsize buffer_len, |
| 123 |
GError **error); |
| 124 |
gboolean qfu_sahara_response_switch_parse (const guint8 *buffer, |
| 125 |
gsize buffer_len, |
| 126 |
GError **error); |
| 127 |
gboolean qfu_sahara_response_end_image_transfer_parse (const guint8 *buffer, |
| 128 |
gsize buffer_len, |
| 129 |
GError **error); |
| 130 |
|
| 131 |
G_END_DECLS |
| 132 |
|
| 133 |
#endif /* QFU_SAHARA_MESSAGE_H */ |