1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef H_LOG_MGMT_ 21 #define H_LOG_MGMT_ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #include "log_mgmt_config.h" 28 29 /** 30 * LOG MGMT specific error codes, 0 -> 6, 8 are same as mcumgr, 31 * 7 and 9 are different for backwards compatibility with newtmgr. 32 */ 33 #define LOG_MGMT_ERR_EOK (0) 34 #define LOG_MGMT_ERR_EUNKNOWN (1) 35 #define LOG_MGMT_ERR_ENOMEM (2) 36 #define LOG_MGMT_ERR_EINVAL (3) 37 #define LOG_MGMT_ERR_ETIMEOUT (4) 38 #define LOG_MGMT_ERR_ENOENT (5) 39 #define LOG_MGMT_ERR_EBADSTATE (6) /* Current state disallows command. */ 40 #define LOG_MGMT_ERR_ECORRUPT (7) 41 #define LOG_MGMT_ERR_ENOTSUP (8) 42 #define LOG_MGMT_ERR_EMSGSIZE (9) 43 #define LOG_MGMT_ERR_EPERUSER (256) 44 45 /** 46 * Command IDs for log management group. 47 */ 48 #define LOG_MGMT_ID_SHOW 0 49 #define LOG_MGMT_ID_CLEAR 1 50 #define LOG_MGMT_ID_APPEND 2 51 #define LOG_MGMT_ID_MODULE_LIST 3 52 #define LOG_MGMT_ID_LEVEL_LIST 4 53 #define LOG_MGMT_ID_LOGS_LIST 5 54 55 /** @brief Log output is streamed without retention (e.g., console). */ 56 #define LOG_MGMT_TYPE_STREAM 0 57 58 /** @brief Log entries are stored in RAM. */ 59 #define LOG_MGMT_TYPE_MEMORY 1 60 61 /** @brief Log entries are persisted across reboots. */ 62 #define LOG_MGMT_TYPE_STORAGE 2 63 64 /* @brief Flags used to indicate type of data in reserved payload. */ 65 #define LOG_MGMT_FLAGS_IMG_HASH (1 << 0) 66 67 /* @brief Log entry types. */ 68 #define LOG_MGMT_ETYPE_STRING 0 69 #define LOG_MGMT_ETYPE_CBOR 1 70 #define LOG_MGMT_ETYPE_BINARY 2 71 72 73 /** @brief Generic descriptor for an OS-specific log. */ 74 struct log_mgmt_log { 75 const char *name; 76 int type; 77 #if !LOG_MGMT_GLOBAL_IDX 78 uint32_t index; 79 #endif 80 }; 81 82 /** @brief Generic descriptor for an OS-specific log entry. */ 83 struct log_mgmt_entry { 84 int64_t ts; 85 uint32_t index; 86 const void *data; 87 size_t len; 88 uint8_t module; 89 uint8_t level; 90 uint8_t type:4; 91 uint8_t flags:4; 92 const uint8_t *imghash; 93 size_t offset; 94 size_t chunklen; 95 void *ctxt; 96 }; 97 98 /** @brief Indicates which log entries to operate on. */ 99 struct log_mgmt_filter { 100 /* If min_timestamp == -1: Only access last log entry; 101 * Elif min_timestamp == 0: Don't filter by timestamp; 102 * Else: Only access entries whose ts >= min_timestamp. 103 */ 104 int64_t min_timestamp; 105 106 /* Only access entries whose index >= min_index. */ 107 uint32_t min_index; 108 }; 109 110 /** 111 * @brief Registers the log management command handler group. 112 */ 113 void log_mgmt_register_group(void); 114 115 #ifdef __cplusplus 116 } 117 #endif 118 119 #endif 120