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 | |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame^] | 17 | #include <memory> |
| 18 | |
Patrick Venture | accc917 | 2018-07-24 10:51:58 -0700 | [diff] [blame] | 19 | #include "host-ipmid/ipmid-api.h" |
| 20 | #include "host-ipmid/oemrouter.hpp" |
| 21 | |
Patrick Venture | 3d1786b | 2018-08-01 11:19:24 -0700 | [diff] [blame] | 22 | #include "flash-ipmi.hpp" |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame^] | 23 | #include "ipmi.hpp" |
Patrick Venture | 3d1786b | 2018-08-01 11:19:24 -0700 | [diff] [blame] | 24 | |
Patrick Venture | accc917 | 2018-07-24 10:51:58 -0700 | [diff] [blame] | 25 | /* TODO: Once OEM IPMI number placement is settled, point to that. */ |
| 26 | namespace oem |
| 27 | { |
| 28 | namespace google |
| 29 | { |
| 30 | constexpr int number = 11129; |
| 31 | constexpr int flashOverBTCmd = 127; |
| 32 | } // namespace google |
| 33 | } // namespace oem |
| 34 | |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame^] | 35 | /* We have one instance of the FlashUpdate object tracking commands. */ |
| 36 | std::unique_ptr<FlashUpdate> flashUpdateSingleton; |
| 37 | |
Patrick Venture | accc917 | 2018-07-24 10:51:58 -0700 | [diff] [blame] | 38 | static ipmi_ret_t flashControl(ipmi_cmd_t cmd, const uint8_t* reqBuf, |
| 39 | uint8_t* replyCmdBuf, size_t* dataLen) |
| 40 | { |
| 41 | /* Verify it's at least as long as the shortest message. */ |
| 42 | if ((*dataLen) < 1) |
| 43 | { |
| 44 | return IPMI_CC_INVALID; |
| 45 | } |
| 46 | |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame^] | 47 | uint8_t subCmd = reqBuf[0]; |
| 48 | |
| 49 | /* TODO: This could be cleaner to just have a function pointer table, may |
| 50 | * transition in later patchset. |
| 51 | */ |
| 52 | switch (subCmd) |
| 53 | { |
| 54 | case FlashSubCmds::flashStartTransfer: |
| 55 | return startTransfer(flashUpdateSingleton.get(), reqBuf, |
| 56 | replyCmdBuf, dataLen); |
| 57 | default: |
| 58 | return IPMI_CC_INVALID; |
| 59 | } |
| 60 | |
Patrick Venture | accc917 | 2018-07-24 10:51:58 -0700 | [diff] [blame] | 61 | return IPMI_CC_INVALID; |
| 62 | } |
| 63 | |
| 64 | static ipmi_ret_t ipmiFlashControl(ipmi_netfn_t netFn, ipmi_cmd_t cmd, |
| 65 | ipmi_request_t request, |
| 66 | ipmi_response_t response, |
| 67 | ipmi_data_len_t dataLen, |
| 68 | ipmi_context_t context) |
| 69 | { |
| 70 | /* request_t, response_t are void*. ipmi_data_len_t is a size_t* */ |
| 71 | auto reqBuf = static_cast<const uint8_t*>(request); |
| 72 | auto replyCmdBuf = static_cast<uint8_t*>(response); |
| 73 | |
| 74 | return flashControl(cmd, reqBuf, replyCmdBuf, dataLen); |
| 75 | } |
| 76 | |
| 77 | void setupGlobalOemFlashControl() __attribute__((constructor)); |
| 78 | |
| 79 | void setupGlobalOemFlashControl() |
| 80 | { |
Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -0700 | [diff] [blame^] | 81 | flashUpdateSingleton = std::make_unique<FlashUpdate>(); |
| 82 | |
Patrick Venture | accc917 | 2018-07-24 10:51:58 -0700 | [diff] [blame] | 83 | #ifdef ENABLE_GOOGLE |
| 84 | oem::Router* router = oem::mutableRouter(); |
| 85 | |
| 86 | fprintf(stderr, "Registering OEM:[%#08X], Cmd:[%#04X] for Flash Update\n", |
| 87 | oem::google::number, oem::google::flashOverBTCmd); |
| 88 | |
| 89 | router->registerHandler(oem::google::number, oem::google::flashOverBTCmd, |
| 90 | flashControl); |
| 91 | #endif |
| 92 | |
| 93 | ipmi_register_callback(NETFUN_FIRMWARE, oem::google::flashOverBTCmd, NULL, |
| 94 | ipmiFlashControl, PRIVILEGE_USER); |
| 95 | } |