blob: 961a131b4a22b4541d6224ebb8a53e507b4fd88b [file] [log] [blame]
Patrick Ventureaccc9172018-07-24 10:51:58 -07001/*
Patrick Venture514f6482018-08-07 14:27:58 -07002 * Copyright 2018 Google Inc.
Patrick Ventureaccc9172018-07-24 10:51:58 -07003 *
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 Venture54c3b532018-08-01 11:45:49 -070017#include <memory>
18
Patrick Ventureaccc9172018-07-24 10:51:58 -070019#include "host-ipmid/ipmid-api.h"
20#include "host-ipmid/oemrouter.hpp"
21
Patrick Venture8ec019f2018-08-07 11:22:33 -070022#include "config.h"
Patrick Venture3d1786b2018-08-01 11:19:24 -070023#include "flash-ipmi.hpp"
Patrick Venture54c3b532018-08-01 11:45:49 -070024#include "ipmi.hpp"
Patrick Venture3d1786b2018-08-01 11:19:24 -070025
Patrick Venture8ec019f2018-08-07 11:22:33 -070026static constexpr auto stagingPath = STAGING_PATH;
Patrick Venture6f17bd22018-08-07 13:24:17 -070027static constexpr auto hashPath = HASH_PATH;
Patrick Venturefdc65b22018-08-07 14:37:58 -070028static constexpr auto statusPath = STATUS_PATH;
Patrick Venture8ec019f2018-08-07 11:22:33 -070029
Patrick Ventureaccc9172018-07-24 10:51:58 -070030/* TODO: Once OEM IPMI number placement is settled, point to that. */
31namespace oem
32{
33namespace google
34{
35constexpr int number = 11129;
36constexpr int flashOverBTCmd = 127;
37} // namespace google
38} // namespace oem
39
Patrick Venture54c3b532018-08-01 11:45:49 -070040/* We have one instance of the FlashUpdate object tracking commands. */
41std::unique_ptr<FlashUpdate> flashUpdateSingleton;
42
Patrick Ventureaccc9172018-07-24 10:51:58 -070043static ipmi_ret_t flashControl(ipmi_cmd_t cmd, const uint8_t* reqBuf,
44 uint8_t* replyCmdBuf, size_t* dataLen)
45{
Patrick Venture9a5a79a2018-08-03 17:23:57 -070046 size_t requestLength = (*dataLen);
47
Patrick Ventureaccc9172018-07-24 10:51:58 -070048 /* Verify it's at least as long as the shortest message. */
Patrick Venture9a5a79a2018-08-03 17:23:57 -070049 if (requestLength < 1)
Patrick Ventureaccc9172018-07-24 10:51:58 -070050 {
51 return IPMI_CC_INVALID;
52 }
53
Patrick Venturea53a7b32018-08-03 09:15:20 -070054 auto subCmd = static_cast<FlashSubCmds>(reqBuf[0]);
55
56 /* Validate the minimum request length for the command. */
Patrick Venture9a5a79a2018-08-03 17:23:57 -070057 if (!validateRequestLength(subCmd, requestLength))
Patrick Venturea53a7b32018-08-03 09:15:20 -070058 {
59 return IPMI_CC_INVALID;
60 }
Patrick Venture54c3b532018-08-01 11:45:49 -070061
Patrick Venture9a5a79a2018-08-03 17:23:57 -070062 auto handler = getCommandHandler(subCmd);
63 if (handler)
Patrick Venture54c3b532018-08-01 11:45:49 -070064 {
Patrick Venture9a5a79a2018-08-03 17:23:57 -070065 return handler(flashUpdateSingleton.get(), reqBuf, replyCmdBuf,
66 dataLen);
Patrick Venture54c3b532018-08-01 11:45:49 -070067 }
68
Patrick Ventureaccc9172018-07-24 10:51:58 -070069 return IPMI_CC_INVALID;
70}
71
72static ipmi_ret_t ipmiFlashControl(ipmi_netfn_t netFn, ipmi_cmd_t cmd,
73 ipmi_request_t request,
74 ipmi_response_t response,
75 ipmi_data_len_t dataLen,
76 ipmi_context_t context)
77{
78 /* request_t, response_t are void*. ipmi_data_len_t is a size_t* */
79 auto reqBuf = static_cast<const uint8_t*>(request);
80 auto replyCmdBuf = static_cast<uint8_t*>(response);
81
82 return flashControl(cmd, reqBuf, replyCmdBuf, dataLen);
83}
84
85void setupGlobalOemFlashControl() __attribute__((constructor));
86
87void setupGlobalOemFlashControl()
88{
Patrick Venture605f75f2018-08-07 16:27:05 -070089 flashUpdateSingleton = std::make_unique<FlashUpdate>(
90 sdbusplus::bus::new_default(), stagingPath, statusPath, hashPath);
Patrick Venture54c3b532018-08-01 11:45:49 -070091
Patrick Ventureaccc9172018-07-24 10:51:58 -070092#ifdef ENABLE_GOOGLE
93 oem::Router* router = oem::mutableRouter();
94
95 fprintf(stderr, "Registering OEM:[%#08X], Cmd:[%#04X] for Flash Update\n",
96 oem::google::number, oem::google::flashOverBTCmd);
97
98 router->registerHandler(oem::google::number, oem::google::flashOverBTCmd,
99 flashControl);
100#endif
101
102 ipmi_register_callback(NETFUN_FIRMWARE, oem::google::flashOverBTCmd, NULL,
103 ipmiFlashControl, PRIVILEGE_USER);
104}