1 /*
2  * Copyright (C) 2015 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 __RPMB_H__
18 #define __RPMB_H__
19 
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 
24 struct rpmb_key {
25     uint8_t byte[32];
26 };
27 
28 struct rpmb_state;
29 
30 #define RPMB_BUF_SIZE 256
31 
32 /* provides */
33 int rpmb_init(struct rpmb_state** statep, void* mmc_handle);
34 void rpmb_set_key(struct rpmb_state* state, const struct rpmb_key* key);
35 void rpmb_uninit(struct rpmb_state* statep);
36 int rpmb_read(struct rpmb_state* state,
37               void* buf,
38               uint16_t addr,
39               uint16_t count);
40 int rpmb_read_no_mac(struct rpmb_state* state,
41                      void* buf,
42                      uint16_t addr,
43                      uint16_t count);
44 int rpmb_verify(struct rpmb_state* state,
45                 const void* buf,
46                 uint16_t addr,
47                 uint16_t count);
48 int rpmb_program_key(struct rpmb_state* state, const struct rpmb_key* key);
49 /* count must be 1 or 2, addr must be aligned */
50 int rpmb_write(struct rpmb_state* state,
51                const void* buf,
52                uint16_t addr,
53                uint16_t count,
54                bool sync,
55                bool sync_checkpoint);
56 
57 /* needs */
58 int rpmb_send(void* mmc_handle,
59               void* reliable_write_buf,
60               size_t reliable_write_size,
61               void* write_buf,
62               size_t write_buf_size,
63               void* read_buf,
64               size_t read_buf_size,
65               bool sync,
66               bool sync_checkpoint);
67 
68 #endif
69