Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018-present Facebook. All Rights Reserved. |
| 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 | |
Patrick Williams | f863a18 | 2022-06-16 16:17:28 -0500 | [diff] [blame] | 17 | #include <ipmid/api.h> |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 18 | #include <stdbool.h> |
| 19 | #include <stdio.h> |
| 20 | #include <sys/stat.h> |
| 21 | |
| 22 | #include <appcommands.hpp> |
| 23 | #include <ipmid/api.hpp> |
Patrick Williams | 2405ae9 | 2023-05-10 07:50:09 -0500 | [diff] [blame] | 24 | #include <ipmid/utils.hpp> |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 25 | #include <nlohmann/json.hpp> |
Karthikeyan Pasupathi | e1ff81f | 2022-11-21 17:54:46 +0530 | [diff] [blame] | 26 | #include <phosphor-logging/lg2.hpp> |
Patrick Williams | 2405ae9 | 2023-05-10 07:50:09 -0500 | [diff] [blame] | 27 | #include <phosphor-logging/log.hpp> |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 28 | #include <sdbusplus/asio/connection.hpp> |
Karthikeyan Pasupathi | 39836ff | 2022-01-17 12:20:06 +0530 | [diff] [blame] | 29 | #include <sdbusplus/asio/property.hpp> |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 30 | |
| 31 | #include <fstream> |
| 32 | #include <iomanip> |
| 33 | #include <iostream> |
| 34 | #include <sstream> |
| 35 | |
| 36 | namespace ipmi |
| 37 | { |
| 38 | |
| 39 | #define JSON_POST_DATA_FILE "/usr/share/lcd-debug/post_desc.json" |
| 40 | #define JSON_GPIO_DATA_FILE "/usr/share/lcd-debug/gpio_desc.json" |
| 41 | #define JSON_SENSOR_NAMES_FILE "/usr/share/lcd-debug/cri_sensors.json" |
| 42 | |
| 43 | #define ETH_INTF_NAME "eth0" |
| 44 | |
| 45 | #define ESCAPE "\x1B" |
| 46 | #define ESC_BAT ESCAPE "B" |
| 47 | #define ESC_MCU_BL_VER ESCAPE "U" |
| 48 | #define ESC_MCU_RUN_VER ESCAPE "R" |
| 49 | #define ESC_ALT ESCAPE "[5;7m" |
| 50 | #define ESC_RST ESCAPE "[m" |
| 51 | |
| 52 | #define LINE_DELIMITER '\x1F' |
| 53 | |
| 54 | #define FRAME_BUFF_SIZE 4096 |
| 55 | #define FRAME_PAGE_BUF_SIZE 256 |
| 56 | #define FRU_ALL 0 |
| 57 | #define MAX_VALUE_LEN 64 |
| 58 | |
| 59 | #define DEBUG_GPIO_KEY "GpioDesc" |
| 60 | #define GPIO_ARRAY_SIZE 4 |
| 61 | #define GPIO_PIN_INDEX 0 |
| 62 | #define GPIO_LEVEL_INDEX 1 |
| 63 | #define GPIO_DEF_INDEX 2 |
| 64 | #define GPIO_DESC_INDEX 3 |
| 65 | #define BMC_POSITION 0 |
| 66 | #define MAX_HOST_POS 4 |
| 67 | |
| 68 | /* Used for systems which do not specifically have a |
| 69 | * phase, and we want to ignore the phase provided by the |
| 70 | * debug card */ |
| 71 | #define PHASE_ANY 0xff |
| 72 | |
| 73 | static constexpr bool DEBUG = false; |
| 74 | static const uint8_t meAddress = 1; |
| 75 | static constexpr uint8_t lun = 0; |
| 76 | |
| 77 | using IpmbMethodType = |
| 78 | std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>; |
| 79 | |
| 80 | typedef struct _sensor_desc |
| 81 | { |
| 82 | char name[16]; |
| 83 | uint8_t sensor_num; |
| 84 | char unit[5]; |
| 85 | uint8_t fru; |
| 86 | uint8_t disp_prec; |
| 87 | } sensor_desc_t; |
| 88 | |
| 89 | struct frame |
| 90 | { |
| 91 | char title[32]; |
| 92 | size_t max_size; |
| 93 | size_t max_page; |
| 94 | char* buf; |
| 95 | uint16_t idx_head, idx_tail; |
| 96 | uint8_t line_per_page; |
| 97 | uint8_t line_width; |
| 98 | uint16_t lines, pages; |
| 99 | uint8_t esc_sts; |
| 100 | uint8_t overwrite; |
| 101 | time_t mtime; |
Patrick Williams | 2405ae9 | 2023-05-10 07:50:09 -0500 | [diff] [blame] | 102 | frame() : buf(NULL), pages(0), mtime(0) {} |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 103 | int init(size_t size); |
| 104 | int append(const char* string, int indent); |
| 105 | int insert(const char* string, int indent); |
| 106 | int getPage(int page, char* page_buf, size_t page_buf_size); |
| 107 | int isFull(); |
| 108 | int isEscSeq(char chr); |
| 109 | int parse(char* buf, size_t buf_size, const char* input, int indent); |
| 110 | }; |
| 111 | |
| 112 | struct frame frame_info; |
| 113 | struct frame frame_sel; |
| 114 | struct frame frame_snr; |
Peter Yin | b340aa2 | 2024-07-08 16:07:55 +0800 | [diff] [blame^] | 115 | struct frame frame_postcode; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 116 | |
| 117 | enum ENUM_PANEL |
| 118 | { |
| 119 | PANEL_MAIN = 1, |
| 120 | PANEL_BOOT_ORDER = 2, |
| 121 | PANEL_POWER_POLICY = 3, |
| 122 | }; |
| 123 | |
| 124 | struct ctrl_panel |
| 125 | { |
| 126 | uint8_t parent; |
| 127 | uint8_t item_num; |
Delphine CC Chiu | 7bb4592 | 2023-04-10 13:34:04 +0800 | [diff] [blame] | 128 | std::string item_str[8]; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 129 | uint8_t (*select)(uint8_t item); |
| 130 | }; |
| 131 | |
| 132 | static uint8_t panel_main(uint8_t item); |
| 133 | static uint8_t panel_boot_order(uint8_t item); |
| 134 | static uint8_t panel_power_policy(uint8_t item); |
| 135 | |
| 136 | static struct ctrl_panel panels[] = { |
| 137 | {/* dummy entry for making other to 1-based */}, |
| 138 | { |
| 139 | .parent = PANEL_MAIN, |
| 140 | .item_num = 2, |
| 141 | .item_str = |
| 142 | { |
| 143 | "User Setting", |
| 144 | ">Boot Order", |
| 145 | ">Power Policy", |
| 146 | }, |
| 147 | .select = panel_main, |
| 148 | }, |
| 149 | { |
| 150 | .parent = PANEL_MAIN, |
| 151 | .item_num = 0, |
| 152 | .item_str = |
| 153 | { |
| 154 | "Boot Order", |
| 155 | }, |
| 156 | .select = panel_boot_order, |
| 157 | }, |
| 158 | { |
| 159 | .parent = PANEL_MAIN, |
| 160 | .item_num = 0, |
| 161 | .item_str = |
| 162 | { |
| 163 | "Power Policy", |
| 164 | }, |
| 165 | .select = panel_power_policy, |
| 166 | }, |
| 167 | }; |
| 168 | |
| 169 | } // end of namespace ipmi |