Patrick Venture | accc917 | 2018-07-24 10:51:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 "host-ipmid/ipmid-api.h" |
| 18 | #include "host-ipmid/oemrouter.hpp" |
| 19 | |
Patrick Venture | 3d1786b | 2018-08-01 11:19:24 -0700 | [diff] [blame^] | 20 | #include "flash-ipmi.hpp" |
| 21 | |
Patrick Venture | accc917 | 2018-07-24 10:51:58 -0700 | [diff] [blame] | 22 | /* TODO: Once OEM IPMI number placement is settled, point to that. */ |
| 23 | namespace oem |
| 24 | { |
| 25 | namespace google |
| 26 | { |
| 27 | constexpr int number = 11129; |
| 28 | constexpr int flashOverBTCmd = 127; |
| 29 | } // namespace google |
| 30 | } // namespace oem |
| 31 | |
| 32 | static ipmi_ret_t flashControl(ipmi_cmd_t cmd, const uint8_t* reqBuf, |
| 33 | uint8_t* replyCmdBuf, size_t* dataLen) |
| 34 | { |
| 35 | /* Verify it's at least as long as the shortest message. */ |
| 36 | if ((*dataLen) < 1) |
| 37 | { |
| 38 | return IPMI_CC_INVALID; |
| 39 | } |
| 40 | |
| 41 | return IPMI_CC_INVALID; |
| 42 | } |
| 43 | |
| 44 | static ipmi_ret_t ipmiFlashControl(ipmi_netfn_t netFn, ipmi_cmd_t cmd, |
| 45 | ipmi_request_t request, |
| 46 | ipmi_response_t response, |
| 47 | ipmi_data_len_t dataLen, |
| 48 | ipmi_context_t context) |
| 49 | { |
| 50 | /* request_t, response_t are void*. ipmi_data_len_t is a size_t* */ |
| 51 | auto reqBuf = static_cast<const uint8_t*>(request); |
| 52 | auto replyCmdBuf = static_cast<uint8_t*>(response); |
| 53 | |
| 54 | return flashControl(cmd, reqBuf, replyCmdBuf, dataLen); |
| 55 | } |
| 56 | |
| 57 | void setupGlobalOemFlashControl() __attribute__((constructor)); |
| 58 | |
| 59 | void setupGlobalOemFlashControl() |
| 60 | { |
| 61 | #ifdef ENABLE_GOOGLE |
| 62 | oem::Router* router = oem::mutableRouter(); |
| 63 | |
| 64 | fprintf(stderr, "Registering OEM:[%#08X], Cmd:[%#04X] for Flash Update\n", |
| 65 | oem::google::number, oem::google::flashOverBTCmd); |
| 66 | |
| 67 | router->registerHandler(oem::google::number, oem::google::flashOverBTCmd, |
| 68 | flashControl); |
| 69 | #endif |
| 70 | |
| 71 | ipmi_register_callback(NETFUN_FIRMWARE, oem::google::flashOverBTCmd, NULL, |
| 72 | ipmiFlashControl, PRIVILEGE_USER); |
| 73 | } |