xref: /aosp_15_r20/system/teeui/libteeui/src/generic_messages.cpp (revision 20bfefbe1966c142a35ae1ab84a8af250b3fd403)
1*20bfefbeSAndroid Build Coastguard Worker /*
2*20bfefbeSAndroid Build Coastguard Worker  *
3*20bfefbeSAndroid Build Coastguard Worker  * Copyright 2019, The Android Open Source Project
4*20bfefbeSAndroid Build Coastguard Worker  *
5*20bfefbeSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*20bfefbeSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*20bfefbeSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
8*20bfefbeSAndroid Build Coastguard Worker  *
9*20bfefbeSAndroid Build Coastguard Worker  *     http://www.apache.org/licenses/LICENSE-2.0
10*20bfefbeSAndroid Build Coastguard Worker  *
11*20bfefbeSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*20bfefbeSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*20bfefbeSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*20bfefbeSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*20bfefbeSAndroid Build Coastguard Worker  * limitations under the License.
16*20bfefbeSAndroid Build Coastguard Worker  */
17*20bfefbeSAndroid Build Coastguard Worker 
18*20bfefbeSAndroid Build Coastguard Worker #include <teeui/generic_messages.h>
19*20bfefbeSAndroid Build Coastguard Worker 
20*20bfefbeSAndroid Build Coastguard Worker namespace teeui {
21*20bfefbeSAndroid Build Coastguard Worker 
readU32(ReadStream in)22*20bfefbeSAndroid Build Coastguard Worker std::tuple<ReadStream, uint32_t> readU32(ReadStream in) {
23*20bfefbeSAndroid Build Coastguard Worker     volatile const uint32_t* pos = reinterpret_cast<volatile const uint32_t*>(in.pos());
24*20bfefbeSAndroid Build Coastguard Worker     in += sizeof(uint32_t);
25*20bfefbeSAndroid Build Coastguard Worker     if (!in) return {in, 0};
26*20bfefbeSAndroid Build Coastguard Worker     return {in, *pos};
27*20bfefbeSAndroid Build Coastguard Worker }
28*20bfefbeSAndroid Build Coastguard Worker 
readCommand(ReadStream in)29*20bfefbeSAndroid Build Coastguard Worker std::tuple<ReadStream, Command> readCommand(ReadStream in) {
30*20bfefbeSAndroid Build Coastguard Worker     return readCmd<Command>(in);
31*20bfefbeSAndroid Build Coastguard Worker }
32*20bfefbeSAndroid Build Coastguard Worker 
peakCommand(ReadStream in)33*20bfefbeSAndroid Build Coastguard Worker Command peakCommand(ReadStream in) {
34*20bfefbeSAndroid Build Coastguard Worker     auto [_, cmd] = readCommand(in);
35*20bfefbeSAndroid Build Coastguard Worker     return cmd;
36*20bfefbeSAndroid Build Coastguard Worker }
37*20bfefbeSAndroid Build Coastguard Worker 
readProtocol(ReadStream in)38*20bfefbeSAndroid Build Coastguard Worker std::tuple<ReadStream, Protocol> readProtocol(ReadStream in) {
39*20bfefbeSAndroid Build Coastguard Worker     return readCmd<Protocol, kProtoInvalid>(in);
40*20bfefbeSAndroid Build Coastguard Worker }
41*20bfefbeSAndroid Build Coastguard Worker 
peakProtocol(ReadStream in)42*20bfefbeSAndroid Build Coastguard Worker Protocol peakProtocol(ReadStream in) {
43*20bfefbeSAndroid Build Coastguard Worker     auto [_, proto] = readProtocol(in);
44*20bfefbeSAndroid Build Coastguard Worker     return proto;
45*20bfefbeSAndroid Build Coastguard Worker }
46*20bfefbeSAndroid Build Coastguard Worker 
47*20bfefbeSAndroid Build Coastguard Worker }  // namespace teeui
48