1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DEVICE_ATTEST_OEM_ADAPTER_H 17 #define DEVICE_ATTEST_OEM_ADAPTER_H 18 19 #include <stdint.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <string.h> 23 #include <ctype.h> 24 25 #ifdef __cplusplus 26 #if __cplusplus 27 extern "C" { 28 #endif 29 #endif /* __cplusplus */ 30 31 #define TOKEN_SIZE 151 32 #define TOKEN_FLAG_SIZE 4 33 #define TOKEN_WITH_FLAG_SIZE (TOKEN_SIZE + TOKEN_FLAG_SIZE) 34 #define TOKEN_ADDR "/data/device_attest" 35 #define TOKEN_A_ADDR "tokenA" 36 #define TOKEN_B_ADDR "tokenB" 37 #define BITS_PER_BYTE 8 38 39 /** 40 * @brief Get Manufacturekey value from device. 41 * 42 * @param manufacturekey : the result Manufacturekey, if get successfully. 43 * @param len : length of the acKey. 44 * @returns 0 if success, otherwise -1. 45 */ 46 int32_t OEMGetManufacturekey(char* manufacturekey, uint32_t len); 47 48 /** 49 * @brief Get ProdId value from device. 50 * 51 * @param productId : product IDs to be populated with. 52 * @param len : length of the productId. 53 * @returns 0 if success, otherwise -1. 54 */ 55 int32_t OEMGetProductId(char* productId, uint32_t len); 56 57 /** 58 * @brief Read token value from device. 59 * 60 * @param token : the result token value, if read successfully. 61 * @param len : length of the token. 62 * @returns 0 if success and get the update area token, 63 * -1 if failed, 64 * -2 if no pre-made token. 65 */ 66 int32_t OEMReadToken(char *token, uint32_t len); 67 68 /** 69 * @brief Write token value to device. 70 * 71 * @param token : the token to write. 72 * @param len : length of the token. 73 * @returns 0 if success, otherwise -1. 74 */ 75 int32_t OEMWriteToken(const char *token, uint32_t len); 76 77 /** 78 * @brief Get ProdKey value from device. 79 * 80 * @param productKey : The productKey value 81 * @param len : The productKey len. 82 * @returns 0 if success, otherwise -1. 83 */ 84 int32_t OEMGetProductKey(char* productKey, uint32_t len); 85 86 #ifdef __cplusplus 87 #if __cplusplus 88 } 89 #endif 90 #endif /* __cplusplus */ 91 92 #endif 93