aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / core / agent_cmd.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 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 | |
| 17 | /* agent_cmd.h -- the card command script of the Pi resident-lifecycle qualification image |
| 18 | * (PI5-7 cut 2, build flag CK_PI5_LIFECYCLE, only with CK_PI5_UNLOCK_CARD). |
| 19 | * |
| 20 | * QUALIFICATION ONLY. Nothing reads the Pi's serial port during a run, so the run tool may place |
| 21 | * \EFI\AIENOS\AGENT.CMD on the card's EFI partition holding a short list of lifecycle verbs. The UEFI |
| 22 | * stub (native/boot/efi_agentcmd.c) reads it before ExitBootServices; after the Store stage the resident |
| 23 | * lifecycle (core/lifecycle.c) takes each line in order, exactly as if an operator had typed it on the |
| 24 | * console, prints the reply on the console and the klog, then runs its stop order. The run tool deletes |
| 25 | * the file after the run. The file is a labelled qualification input, never a user interface, and it can |
| 26 | * never carry a secret: unlock, rotate, update and shutdown are refused by the parser (the Store secret |
| 27 | * comes from the card UNLOCK.REQ request, core/unlock_req.h; shutdown is implicit at the end). |
| 28 | * |
| 29 | * File layout: plain text, at most CK_AGENT_CMD_FILE_MAX bytes, LF line ends. |
| 30 | * line 1 exactly "AIENAGC1 QUALIF-AGENT-CMD" |
| 31 | * lines 2.. 1..CK_AGENT_CMD_LINES_MAX command lines, each: |
| 32 | * <verb> status help evidence recall facts approve deny cancel |
| 33 | * <verb> <text> remember prefer prompt task (text 1..CK_AGENT_CMD_TEXT_MAX bytes) |
| 34 | * every byte is printable ASCII 0x20..0x7e or the LF that ends a line; the file ends with an LF; |
| 35 | * no empty line, no CR, no tab, no NUL; a line has no leading or trailing blank and a single blank |
| 36 | * between verb and text. */ |
| 37 | #ifndef AIENOS_CK_AGENT_CMD_H |
| 38 | #define AIENOS_CK_AGENT_CMD_H |
| 39 | #include <stddef.h> |
| 40 | #include <stdint.h> |
| 41 | |
| 42 | #define CK_AGENT_CMD_HEADER "AIENAGC1 QUALIF-AGENT-CMD" |
| 43 | #define CK_AGENT_CMD_PATH "\\EFI\\AIENOS\\AGENT.CMD" |
| 44 | #define CK_AGENT_CMD_FILE_MAX 2048u |
| 45 | #define CK_AGENT_CMD_LINES_MAX 16u |
| 46 | #define CK_AGENT_CMD_TEXT_MAX 48u /* the lifecycle's own text bound (CK_LC_TASK_MAX) */ |
| 47 | #define CK_AGENT_CMD_LINE_MAX 64u /* "remember " + 48 text + NUL fits */ |
| 48 | |
| 49 | struct ck_agent_cmd { |
| 50 | uint32_t nlines; |
| 51 | uint32_t len[CK_AGENT_CMD_LINES_MAX]; |
| 52 | char line[CK_AGENT_CMD_LINES_MAX][CK_AGENT_CMD_LINE_MAX]; |
| 53 | }; |
| 54 | |
| 55 | /* 0 = well formed and *out filled; else -1, *out zeroed and *why names the first failed check. */ |
| 56 | int ck_agent_cmd_parse(const uint8_t *buf, size_t n, struct ck_agent_cmd *out, const char **why); |
| 57 | |
| 58 | enum { CK_AGENT_CMD_NONE = 0, CK_AGENT_CMD_ABSENT = 1, CK_AGENT_CMD_REFUSED = 2, CK_AGENT_CMD_FOUND = 3 }; |
| 59 | |
| 60 | /* What the UEFI stub found (the stub and the kernel are one image). */ |
| 61 | struct ck_agent_cmd_boot { |
| 62 | int state; /* CK_AGENT_CMD_* */ |
| 63 | struct ck_agent_cmd cmd; /* only while FOUND */ |
| 64 | }; |
| 65 | extern struct ck_agent_cmd_boot ck_agent_cmd_boot; |
| 66 | #endif |