xref: /openbmc/google-ipmi-sys/main.cpp (revision 8c0094e4)
1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "handler_impl.hpp"
16 #include "ipmi.hpp"
17 
18 #include <ipmid/api.h>
19 
20 #include <ipmid/api-types.hpp>
21 #include <ipmid/handler.hpp>
22 #include <ipmid/iana.hpp>
23 #include <stdplus/print.hpp>
24 
25 #include <cstdint>
26 #include <cstdio>
27 #include <functional>
28 #include <span>
29 
30 namespace oem
31 {
32 namespace google
33 {
34 constexpr int sysCmd = 50;
35 } // namespace google
36 } // namespace oem
37 
38 namespace google
39 {
40 namespace ipmi
41 {
42 
43 void setupGoogleOemSysCommands() __attribute__((constructor));
44 
setupGoogleOemSysCommands()45 void setupGoogleOemSysCommands()
46 {
47     static Handler handlerImpl;
48 
49     stdplus::print(
50         stderr, "Registering OEM:[{:#08X}], Cmd:[{:#04X}] for Sys Commands\n",
51         oem::googOemNumber, oem::google::sysCmd);
52 
53     ::ipmi::registerOemHandler(
54         ::ipmi::prioOemBase, oem::googOemNumber, oem::google::sysCmd,
55         ::ipmi::Privilege::User,
56         [](::ipmi::Context::ptr ctx, uint8_t cmd,
57            const std::vector<uint8_t>& data) {
58             return handleSysCommand(&handlerImpl, ctx, cmd, data);
59         });
60 }
61 
62 } // namespace ipmi
63 } // namespace google
64