xref: /openbmc/fb-ipmi-oem/src/transportcommands.cpp (revision 2f45499fc3a71ae67774061e95a5b3c6febf1893)
1 /*
2  * Copyright (c)  2018-present Facebook.
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 #include <ipmid/api.h>
18 
19 #include <commandutils.hpp>
20 #include <ipmid/api-types.hpp>
21 
22 constexpr ipmi::Cc ccParameterNotSupported = 0x80;
23 
24 namespace ipmi
25 {
26 
27 void registerTransportFunctions() __attribute__((constructor));
28 
29 // Transport Command Codes (IPMI/Table H-1)
30 enum
31 {
32     CMD_TRANSPORT_GET_SOL_CONFIG = 0x22,
33 };
34 
35 // SOL Configuration parameters (IPMI/Table 26-5)
36 enum
37 {
38     SOL_PARAM_SET_IN_PROG,
39     SOL_PARAM_SOL_ENABLE,
40     SOL_PARAM_SOL_AUTH,
41     SOL_PARAM_SOL_THRESHOLD,
42     SOL_PARAM_SOL_RETRY,
43     SOL_PARAM_SOL_BITRATE,
44     SOL_PARAM_SOL_NV_BITRATE,
45 };
46 
47 //----------------------------------------------------------------------
48 // Get SoL Config (IPMI/Section 26.3) (CMD_TRANSPORT_GET_SOL_CONFIG)
49 //----------------------------------------------------------------------
ipmiTransGetSolConfig(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t response,ipmi_data_len_t data_len,ipmi_context_t)50 ipmi_ret_t ipmiTransGetSolConfig(
51     ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, ipmi_response_t response,
52     ipmi_data_len_t data_len, ipmi_context_t)
53 {
54     uint8_t* req = reinterpret_cast<uint8_t*>(request);
55     uint8_t* res = reinterpret_cast<uint8_t*>(response);
56     uint8_t param = req[0];
57     uint8_t paramSel = req[1];
58 
59     *res++ = 0x01; // Parameter revision
60     *data_len = 1;
61 
62     /* If request for revision only then return
63      * with only one byte of data
64      */
65     if (param & 0x80)
66         return ipmi::ccSuccess;
67 
68     switch (paramSel)
69     {
70         case SOL_PARAM_SET_IN_PROG:
71             *res++ = 0x00; // Set this value as (set complete)
72             *data_len += 1;
73             break;
74         case SOL_PARAM_SOL_ENABLE:
75             *res++ = 0x01; // Enable SoL payload
76             *data_len += 1;
77             break;
78         case SOL_PARAM_SOL_AUTH:
79             *res++ = 0x02; // Set as (User Level)
80             *data_len += 1;
81             break;
82         case SOL_PARAM_SOL_THRESHOLD:
83             *res++ = 0x00;
84             /* Byte 2: Char send threshold: setting this value to 1 means
85              * that BMC to send packet as soon as first character arrived.
86              */
87             *res++ = 0x01;
88             *data_len += 2;
89             break;
90         case SOL_PARAM_SOL_RETRY:
91             *res++ = 0x00; // Retry count: No retry after packet transmission.
92             *res++ = 0x00; // Retry interval
93             *data_len += 2;
94             break;
95         case SOL_PARAM_SOL_BITRATE:
96         case SOL_PARAM_SOL_NV_BITRATE:
97             *res++ = 0x09; // Bit rate: set as 57.6 kbps
98             *data_len += 1;
99             break;
100         default:
101             *data_len = 0;
102             return ccParameterNotSupported;
103             break;
104     }
105 
106     return ipmi::ccSuccess;
107 }
108 
registerTransportFunctions()109 void registerTransportFunctions()
110 {
111     ipmiPrintAndRegister(ipmi::netFnTransport, CMD_TRANSPORT_GET_SOL_CONFIG,
112                          NULL, ipmiTransGetSolConfig,
113                          PRIVILEGE_OPERATOR); // Get Sol Config
114 
115     return;
116 }
117 } // namespace ipmi
118