| Patrick Venture | d26fff4 | 2018-09-18 15:37:59 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2018 Google Inc. | 
|  | 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 "config.h" | 
|  | 18 |  | 
|  | 19 | #include "ethstats.hpp" | 
|  | 20 |  | 
| William A. Kennington III | 539f03f | 2019-02-12 13:28:45 -0800 | [diff] [blame] | 21 | #include <ipmid/iana.hpp> | 
|  | 22 | #include <ipmid/oemopenbmc.hpp> | 
|  | 23 | #include <ipmid/oemrouter.hpp> | 
| Patrick Venture | d26fff4 | 2018-09-18 15:37:59 -0700 | [diff] [blame] | 24 |  | 
| Patrick Williams | 4cf2bef | 2023-05-10 07:51:36 -0500 | [diff] [blame] | 25 | #include <cstdio> | 
|  | 26 |  | 
| Patrick Venture | aca9813 | 2019-03-18 11:14:16 -0700 | [diff] [blame] | 27 | namespace ethstats | 
|  | 28 | { | 
|  | 29 |  | 
| Patrick Venture | 75ca018 | 2020-05-13 18:36:36 -0700 | [diff] [blame] | 30 | EthStats handler; | 
|  | 31 |  | 
| Patrick Venture | aca9813 | 2019-03-18 11:14:16 -0700 | [diff] [blame] | 32 | static ipmi_ret_t ethStatCommand(ipmi_cmd_t cmd __attribute__((unused)), | 
|  | 33 | const uint8_t* reqBuf, uint8_t* replyCmdBuf, | 
|  | 34 | size_t* dataLen) | 
|  | 35 | { | 
| Patrick Venture | 75ca018 | 2020-05-13 18:36:36 -0700 | [diff] [blame] | 36 | return handleEthStatCommand(reqBuf, replyCmdBuf, dataLen, &handler); | 
| Patrick Venture | aca9813 | 2019-03-18 11:14:16 -0700 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
|  | 39 | } // namespace ethstats | 
|  | 40 |  | 
| Patrick Venture | d26fff4 | 2018-09-18 15:37:59 -0700 | [diff] [blame] | 41 | void setupGlobalOemEthStats() __attribute__((constructor)); | 
|  | 42 |  | 
|  | 43 | void setupGlobalOemEthStats() | 
|  | 44 | { | 
|  | 45 | oem::Router* oemRouter = oem::mutableRouter(); | 
|  | 46 |  | 
| Patrick Venture | d72f8b5 | 2019-03-07 16:54:57 -0800 | [diff] [blame] | 47 | #if ENABLE_GOOGLE | 
| Patrick Venture | d26fff4 | 2018-09-18 15:37:59 -0700 | [diff] [blame] | 48 | /* Install in Google OEM Namespace when enabled. */ | 
|  | 49 | std::fprintf(stderr, | 
|  | 50 | "Registering OEM:[%#08X], Cmd:[%#04X] for Ethstats Commands\n", | 
| Patrick Venture | ddee9d0 | 2018-11-15 14:50:52 -0800 | [diff] [blame] | 51 | oem::googOemNumber, oem::Cmd::ethStatsCmd); | 
| Patrick Venture | d26fff4 | 2018-09-18 15:37:59 -0700 | [diff] [blame] | 52 |  | 
| Patrick Venture | ddee9d0 | 2018-11-15 14:50:52 -0800 | [diff] [blame] | 53 | oemRouter->registerHandler(oem::googOemNumber, oem::Cmd::ethStatsCmd, | 
| Patrick Venture | aca9813 | 2019-03-18 11:14:16 -0700 | [diff] [blame] | 54 | ethstats::ethStatCommand); | 
| Patrick Venture | d26fff4 | 2018-09-18 15:37:59 -0700 | [diff] [blame] | 55 | #endif | 
|  | 56 |  | 
|  | 57 | std::fprintf(stderr, | 
|  | 58 | "Registering OEM:[%#08X], Cmd:[%#04X] for Ethstats Commands\n", | 
| Patrick Venture | ddee9d0 | 2018-11-15 14:50:52 -0800 | [diff] [blame] | 59 | oem::obmcOemNumber, oem::Cmd::ethStatsCmd); | 
| Patrick Venture | d26fff4 | 2018-09-18 15:37:59 -0700 | [diff] [blame] | 60 |  | 
| Patrick Venture | ddee9d0 | 2018-11-15 14:50:52 -0800 | [diff] [blame] | 61 | oemRouter->registerHandler(oem::obmcOemNumber, oem::Cmd::ethStatsCmd, | 
| Patrick Venture | aca9813 | 2019-03-18 11:14:16 -0700 | [diff] [blame] | 62 | ethstats::ethStatCommand); | 
| Patrick Venture | d26fff4 | 2018-09-18 15:37:59 -0700 | [diff] [blame] | 63 | } |