blob: d40807ab88a5fa38b1c5d5c216a92392475effae [file] [log] [blame]
Amit Blay6281ebc2015-01-11 14:44:08 +02001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __APP_MDTP_H
30#define __APP_MDTP_H
31
32#define TOKEN_LEN 16
33#define MAX_BLOCKS 512
34#define MAX_PARTITIONS 3
35#define MAX_PARTITION_NAME_LEN 100
36#define HASH_LEN 32
Reut Zysman18411272015-02-09 13:47:27 +020037#define MDTP_MIN_PIN_LEN 5
Amit Blay6281ebc2015-01-11 14:44:08 +020038#define MDTP_MAX_PIN_LEN 8
39#define DIP_PADDING 11
40
Reut Zysman18411272015-02-09 13:47:27 +020041#define INITIAL_DELAY_MSECONDS 5000
42#define INVALID_PIN_DELAY_MSECONDS 5000
43
Amit Blay6281ebc2015-01-11 14:44:08 +020044#define ROUND_TO_PAGE(x,y) (((x) + (y)) & (~(y)))
45#define MDTP_FWLOCK_BLOCK_SIZE (1024*1024*16)
46#define MDTP_FWLOCK_MAX_FILES (100)
47#define MDTP_FWLOCK_MAX_FILE_NAME_LEN (100)
48
49#pragma pack(push, mdtp, 1)
50
51typedef enum {
52 DIP_STATUS_DEACTIVATED = 0,
53 DIP_STATUS_ACTIVATED,
54 DIP_STATUS_SIZE = 0x7FFFFFFF
55} dip_status_t;
56
57typedef enum {
58 MDTP_FWLOCK_MODE_SINGLE = 0,
59 MDTP_FWLOCK_MODE_BLOCK,
60 MDTP_FWLOCK_MODE_FILES,
61 MDTP_FWLOCK_MODE_SIZE = 0x7FFFFFFF
62} mdtp_fwlock_mode_t;
63
64typedef struct DIP_hash_table_entry {
65 unsigned char hash[HASH_LEN]; /* Hash on block */
66} DIP_hash_table_entry_t;
67
68typedef struct DIP_partition_cfg {
69 uint32_t size; /* DIP size */
70 char name[MAX_PARTITION_NAME_LEN]; /* Partition name */
71 uint8_t lock_enabled; /* Image locked? */
72 mdtp_fwlock_mode_t hash_mode; /* Hash per IMAGE or BLOCK */
73 uint8_t force_verify_block[MAX_BLOCKS]; /* Verify only given block numbers. */
74 char files_to_protect[MDTP_FWLOCK_MAX_FILES][MDTP_FWLOCK_MAX_FILE_NAME_LEN]; /* Verify given files */
75 uint32_t verify_ratio; /* Statistically verify this ratio of blocks */
76 DIP_hash_table_entry_t hash_table[MAX_BLOCKS]; /* Hash table */
77} DIP_partition_cfg_t;
78
79typedef struct mdtp_pin {
80 char mdtp_pin[MDTP_MAX_PIN_LEN+1]; /* A null terminated PIN. */
81} mdtp_pin_t;
82
83/** MDTP configuration. */
84typedef struct mdtp_cfg {
85 uint8_t enable_local_pin_authentication;/* Allow local authentication using a PIN. */
86 mdtp_pin_t mdtp_pin; /* Null terminated PIN provided by the user for local deactivation.
87 PIN length should be from MDTP_MIN_PIN_LEN to MDTP_MAX_PIN_LEN digits. */
88} mdtp_cfg_t;
89
90typedef struct DIP {
91 /* Management area of the DIP */
92 uint32_t version; /* DIP version */
93 dip_status_t status; /* DIP activated/deactivated */
94 mdtp_cfg_t mdtp_cfg; /* MDTP configuration, such as PIN */
95
96 /* Firmware Lock area of the DIP */
97 DIP_partition_cfg_t partition_cfg[MAX_PARTITIONS]; /* Config for each partition */
98
99 /* Footer area of the DIP */
100 uint8_t padding[DIP_PADDING]; /* Pad to multiple of 16 bytes */
101 unsigned char hash[HASH_LEN]; /* DIP integrity */
102} DIP_t;
103
104#pragma pack(pop, mdtp)
105typedef enum {
106 VERIFY_SKIPPED = 0,
107 VERIFY_OK,
108 VERIFY_FAILED,
109} verify_result_t;
110
Reut Zysman18411272015-02-09 13:47:27 +0200111
112/**
113 * mdtp_fwlock_verify_lock
114 *
115 * Start Firmware Lock verification process.
116 *
117 * @return - negative value for an error, 0 for success.
118 */
Amit Blay6281ebc2015-01-11 14:44:08 +0200119int mdtp_fwlock_verify_lock();
120
Reut Zysman18411272015-02-09 13:47:27 +0200121/**
122 * mdtp_fuse_get_enabled
123 *
124 * Return whether the MDTP is currently enabled or
125 * disabled in HW.
126 *
127 * @param[out] enabled: set to true if MDTP enabled,
128 * false otherwise.
129 *
130 * @return - negative value for an error, 0 for success.
131 */
Amit Blaydf42d2f2015-02-03 16:37:09 +0200132int mdtp_fuse_get_enabled(bool *enabled);
133
Reut Zysman18411272015-02-09 13:47:27 +0200134/**
135 * get_pin_from_user
136 *
137 * Display the recovery PIN screen and set received buffer
138 * with the PIN the user has entered.
139 *
140 * @param[out] entered_pin: buffer holding the received PIN.
141 * @param[in] pin_length: PIN length (and also entered_pin buffer length).
142 *
143 * @return - None.
144 */
145void get_pin_from_user(char *entered_pin, uint32_t pin_length);
Amit Blay6281ebc2015-01-11 14:44:08 +0200146
Reut Zysman18411272015-02-09 13:47:27 +0200147/**
148 * display_invalid_pin_msg
149 *
150 * User has entered invalid PIN, display error message and
151 * allow the user to try again.
152 *
153 * @return - None.
154 */
155void display_invalid_pin_msg();
Amit Blay6281ebc2015-01-11 14:44:08 +0200156
Reut Zysman18411272015-02-09 13:47:27 +0200157/**
158 * display_error_msg
159 *
160 * Display error message and stop boot process.
161 *
162 * @return - None.
163 */
164void display_error_msg();
Amit Blay6281ebc2015-01-11 14:44:08 +0200165
166#endif