|
| 1 | + |
| 2 | +// Copyright 2026 Google LLC |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +#ifndef LIBHOTH_INCLUDE_LIBHOTH_STATUS_H_ |
| 17 | +#define LIBHOTH_INCLUDE_LIBHOTH_STATUS_H_ |
| 18 | + |
| 19 | +#include <stdint.h> |
| 20 | + |
| 21 | +// Represents success |
| 22 | +#define HOTH_SUCCESS 0x0ULL |
| 23 | + |
| 24 | +// Typedef for the error code |
| 25 | +typedef uint64_t libhoth_error; |
| 26 | + |
| 27 | +#define LIBHOTH_ERR_CONSTRUCT(ctx, space, code) \ |
| 28 | + ((((uint64_t)(ctx) & 0xFFFFFFFFULL) << 32) | \ |
| 29 | + (((uint64_t)(space) & 0xFFFFULL) << 16) | ((uint64_t)(code) & 0xFFFFULL)) |
| 30 | + |
| 31 | +// hoth_context_id: High 32 bits of the error code. |
| 32 | +// Uniquely identifies the libhoth operation or subsystem. |
| 33 | +enum hoth_context_id { |
| 34 | + HOTH_CTX_NONE = 0, |
| 35 | + |
| 36 | + // Initialization / General |
| 37 | + HOTH_CTX_INIT = 1, |
| 38 | + |
| 39 | + // Transport layers |
| 40 | + HOTH_CTX_USB = 10, |
| 41 | + HOTH_CTX_SPI = 20, |
| 42 | + |
| 43 | + // Command Execution |
| 44 | + HOTH_CTX_CMD_EXEC = 30, |
| 45 | +}; |
| 46 | + |
| 47 | +// hoth_host_space: Top 16 bits of the low 32-bit Base Error Code. |
| 48 | +// Indicates the domain of host-side errors. |
| 49 | +enum hoth_host_space { |
| 50 | + HOTH_HOST_SPACE_FW = 0x0000, // Firmware errors directly |
| 51 | + HOTH_HOST_SPACE_POSIX = 0x0001, // errno values |
| 52 | + HOTH_HOST_SPACE_LIBUSB = 0x0002, // libusb_error values |
| 53 | + HOTH_HOST_SPACE_LIBHOTH = 0x0005, // libhoth internal errors |
| 54 | +}; |
| 55 | + |
| 56 | +#ifndef __packed |
| 57 | +#define __packed __attribute__((packed)) |
| 58 | +#endif |
| 59 | + |
| 60 | +// Hoth error code: Low 16 bits of the 32-bit Base Error Code |
| 61 | +// Firmware Error |
| 62 | +enum hoth_fw_error_status { |
| 63 | + HOTH_RES_SUCCESS = 0, |
| 64 | + HOTH_RES_INVALID_COMMAND = 1, |
| 65 | + HOTH_RES_ERROR = 2, |
| 66 | + HOTH_RES_INVALID_PARAM = 3, |
| 67 | + HOTH_RES_ACCESS_DENIED = 4, |
| 68 | + HOTH_RES_INVALID_RESPONSE = 5, |
| 69 | + HOTH_RES_INVALID_VERSION = 6, |
| 70 | + HOTH_RES_INVALID_CHECKSUM = 7, |
| 71 | + HOTH_RES_IN_PROGRESS = 8, |
| 72 | + HOTH_RES_UNAVAILABLE = 9, |
| 73 | + HOTH_RES_TIMEOUT = 10, |
| 74 | + HOTH_RES_OVERFLOW = 11, |
| 75 | + HOTH_RES_INVALID_HEADER = 12, |
| 76 | + HOTH_RES_REQUEST_TRUNCATED = 13, |
| 77 | + HOTH_RES_RESPONSE_TOO_BIG = 14, |
| 78 | + HOTH_RES_BUS_ERROR = 15, |
| 79 | + HOTH_RES_BUSY = 16, |
| 80 | + HOTH_RES_INVALID_HEADER_VERSION = 17, |
| 81 | + HOTH_RES_INVALID_HEADER_CRC = 18, |
| 82 | + HOTH_RES_INVALID_DATA_CRC = 19, |
| 83 | + HOTH_RES_DUP_UNAVAILABLE = 20, |
| 84 | + HOTH_RES_MAX = UINT16_MAX |
| 85 | +} __packed; |
| 86 | + |
| 87 | +#endif // LIBHOTH_INCLUDE_LIBHOTH_STATUS_H_ |
0 commit comments