1 /* 2 * Copyright (C) 2016 The Android Open Source Project 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 #ifndef TRUSTY_NVRAM_TRUSTY_NVRAM_IMPLEMENTATION_H_ 18 #define TRUSTY_NVRAM_TRUSTY_NVRAM_IMPLEMENTATION_H_ 19 20 #include <stdint.h> 21 22 #include <nvram/hal/nvram_device_adapter.h> 23 #include <nvram/messages/nvram_messages.h> 24 25 namespace nvram { 26 27 // |TrustyNvramImplementation| proxies requests to the Trusty NVRAM app. It 28 // serializes the request objects, sends it to the Trusty app and finally reads 29 // back the result and decodes it. 30 class TrustyNvramImplementation : public nvram::NvramImplementation { 31 public: 32 ~TrustyNvramImplementation() override; 33 34 void Execute(const nvram::Request& request, 35 nvram::Response* response) override; 36 37 private: 38 // Connects the IPC channel to the Trusty app if it is not already open. 39 // Returns true if the channel is open, false on errors. 40 bool Connect(); 41 42 // Dispatches a command to the trust app. Returns true if successful (note 43 // that the response may still indicate an error on the Trusty side), false if 44 // there are any I/O or encoding/decoding errors. 45 bool SendRequest(const nvram::Request& request, 46 nvram::Response* response); 47 48 // The file descriptor for the IPC connection to the Trusty app. 49 int tipc_nvram_fd_ = -1; 50 51 // Response buffer. This puts a hard size limit on the responses from the 52 // Trusty app. 4096 matches the maximum IPC message size currently supported 53 // by Trusty. 54 uint8_t response_buffer_[4096]; 55 }; 56 57 } // namespace nvram 58 59 #endif // TRUSTY_NVRAM_TRUSTY_NVRAM_IMPLEMENTATION_H_ 60