Skip to content

Commit cd89ca9

Browse files
committed
[protocol] Add the centeralized status to libhoth
Add a place to hold the centeralized error status and link it to the basic framework without changing the overall error system. Signed-off-by: Ellis Nguyen <sarzanguyen@google.com>
1 parent f67b02c commit cd89ca9

6 files changed

Lines changed: 105 additions & 6 deletions

File tree

BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ cc_library(
77
hdrs = [":gen_version_header"],
88
)
99

10+
cc_library(
11+
name = "libhoth_status",
12+
hdrs = ["include/libhoth/status.h"],
13+
strip_include_prefix = "include",
14+
visibility = ["//visibility:public"],
15+
)
16+
17+
1018
genrule(
1119
name = "gen_version_header",
1220
outs = ["git_version.h"],

examples/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ git_version_h = vcs_tag(
66
replace_string: '@GIT_COMMIT@',
77
)
88

9-
incdir = include_directories('..')
9+
incdir = libhoth_include_dirs
1010
link_with = [libhoth.get_static_lib()]
1111
c_args = []
1212

include/libhoth/status.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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_

meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
project('libhoth', 'c', 'cpp', license: 'Apache-2.0', version: '0.0.0')
22

3+
install_headers('include/libhoth/status.h', subdir: 'libhoth')
4+
5+
libhoth_include_dirs = include_directories('include', '.')
6+
37
header_subdirs = ['libhoth']
48
libhoth_objs = []
59
libhoth_deps = []

protocol/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ protocol_srcs = [
2626
'console.c'
2727
]
2828

29-
incdir = include_directories('..')
29+
incdir = libhoth_include_dirs
3030

3131
libhoth_protocol = static_library(
3232
'hoth_protocols',
3333
protocol_srcs,
34-
include_directories: incdir,
34+
include_directories: libhoth_include_dirs,
3535
link_with: [libhoth_transport],
3636
)
3737
libhoth_objs += [libhoth_protocol.extract_all_objects(recursive: false)]

transports/meson.build

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ transport_srcs = [
77
'libhoth_usb_mailbox.c',
88
]
99

10-
incdir = include_directories('..')
10+
incdir = libhoth_include_dirs
1111
libusb = dependency('libusb-1.0')
1212
libsystemd = dependency('libsystemd')
1313
libcap = dependency('libcap')
@@ -16,7 +16,7 @@ if get_option('dbus_backend')
1616
libhoth_dbus = static_library(
1717
'hoth_dbus',
1818
'libhoth_dbus.c',
19-
include_directories: incdir,
19+
include_directories: libhoth_include_dirs,
2020
dependencies: [libsystemd],
2121
)
2222
libhoth_objs += [libhoth_dbus.extract_all_objects(recursive: false)]
@@ -27,7 +27,7 @@ endif
2727
libhoth_transport = static_library(
2828
'hoth_transports',
2929
transport_srcs,
30-
include_directories: incdir,
30+
include_directories: libhoth_include_dirs,
3131
dependencies: [libusb],
3232
)
3333

0 commit comments

Comments
 (0)