1 /*
2  * Copyright (C) 2021 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 #pragma once
18 
19 #include "../rpmb.h"
20 #include "../rpmb_protocol.h"
21 
22 #define MAX_WRITE_COUNTER (0xffffffff)
23 
24 struct rpmb_data_header {
25     uint32_t write_counter;
26     uint16_t max_block;
27     uint8_t pad1;
28     uint8_t key_programmed;
29     struct rpmb_key key;
30     uint8_t pad[512 - 4 - 2 - 1 - 1 - sizeof(struct rpmb_key)];
31 };
32 
33 #define MAX_PACKET_COUNT (8)
34 
35 struct rpmb_dev_state {
36     struct rpmb_data_header header;
37     struct rpmb_packet cmd[MAX_PACKET_COUNT];
38     struct rpmb_packet res[MAX_PACKET_COUNT];
39     uint16_t cmd_count;
40     uint16_t res_count;
41     int data_fd;
42     int fail_next_writes;
43     bool commit_failed_writes;
44     int fail_next_reads;
45     int fail_next_get_counters;
46 };
47 
48 void rpmb_dev_process_cmd(struct rpmb_dev_state* s);
49 
50 /* verbose is an int for getopt */
51 extern int verbose;
52