10a7ce71fSopenharmony_ci/* 20a7ce71fSopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd. 30a7ce71fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 40a7ce71fSopenharmony_ci * you may not use this file except in compliance with the License. 50a7ce71fSopenharmony_ci * You may obtain a copy of the License at 60a7ce71fSopenharmony_ci * 70a7ce71fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 80a7ce71fSopenharmony_ci * 90a7ce71fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 100a7ce71fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 110a7ce71fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120a7ce71fSopenharmony_ci * See the License for the specific language governing permissions and 130a7ce71fSopenharmony_ci * limitations under the License. 140a7ce71fSopenharmony_ci */ 150a7ce71fSopenharmony_ci 160a7ce71fSopenharmony_ci#include "ohos_errno.h" 170a7ce71fSopenharmony_ci#include <stdlib.h> 180a7ce71fSopenharmony_ci#include <sys/types.h> 190a7ce71fSopenharmony_ci#include <unistd.h> 200a7ce71fSopenharmony_ci#include "hal_token.h" 210a7ce71fSopenharmony_ci 220a7ce71fSopenharmony_cistatic int OEMReadToken(char *token, unsigned int len) 230a7ce71fSopenharmony_ci{ 240a7ce71fSopenharmony_ci // OEM need add here, read token from device 250a7ce71fSopenharmony_ci return EC_SUCCESS; 260a7ce71fSopenharmony_ci} 270a7ce71fSopenharmony_ci 280a7ce71fSopenharmony_cistatic int OEMWriteToken(const char *token, unsigned int len) 290a7ce71fSopenharmony_ci{ 300a7ce71fSopenharmony_ci // OEM need add here, write token to device 310a7ce71fSopenharmony_ci return EC_SUCCESS; 320a7ce71fSopenharmony_ci} 330a7ce71fSopenharmony_ci 340a7ce71fSopenharmony_cistatic int OEMGetAcKey(char *acKey, unsigned int len) 350a7ce71fSopenharmony_ci{ 360a7ce71fSopenharmony_ci // OEM need add here, get AcKey 370a7ce71fSopenharmony_ci return EC_SUCCESS; 380a7ce71fSopenharmony_ci} 390a7ce71fSopenharmony_ci 400a7ce71fSopenharmony_cistatic int OEMGetProdId(char *productId, unsigned int len) 410a7ce71fSopenharmony_ci{ 420a7ce71fSopenharmony_ci // OEM need add here, get ProdId 430a7ce71fSopenharmony_ci return EC_SUCCESS; 440a7ce71fSopenharmony_ci} 450a7ce71fSopenharmony_ci 460a7ce71fSopenharmony_cistatic int OEMGetProdKey(char *productKey, unsigned int len) 470a7ce71fSopenharmony_ci{ 480a7ce71fSopenharmony_ci // OEM need add here, get ProdKey 490a7ce71fSopenharmony_ci return EC_SUCCESS; 500a7ce71fSopenharmony_ci} 510a7ce71fSopenharmony_ci 520a7ce71fSopenharmony_cistatic int UidVerify(void) 530a7ce71fSopenharmony_ci{ 540a7ce71fSopenharmony_ci uid_t uid; 550a7ce71fSopenharmony_ci 560a7ce71fSopenharmony_ci uid = getuid(); 570a7ce71fSopenharmony_ci if (uid >= KIT_FRAMEWORK_UID_MAX) { 580a7ce71fSopenharmony_ci return EC_FAILURE; 590a7ce71fSopenharmony_ci } 600a7ce71fSopenharmony_ci return EC_SUCCESS; 610a7ce71fSopenharmony_ci} 620a7ce71fSopenharmony_ci 630a7ce71fSopenharmony_ciint HalReadToken(char *token, unsigned int len) 640a7ce71fSopenharmony_ci{ 650a7ce71fSopenharmony_ci if (token == NULL) { 660a7ce71fSopenharmony_ci return EC_FAILURE; 670a7ce71fSopenharmony_ci } 680a7ce71fSopenharmony_ci 690a7ce71fSopenharmony_ci if (UidVerify()) { 700a7ce71fSopenharmony_ci return EC_FAILURE; 710a7ce71fSopenharmony_ci } 720a7ce71fSopenharmony_ci 730a7ce71fSopenharmony_ci return OEMReadToken(token, len); 740a7ce71fSopenharmony_ci} 750a7ce71fSopenharmony_ci 760a7ce71fSopenharmony_ciint HalWriteToken(const char *token, unsigned int len) 770a7ce71fSopenharmony_ci{ 780a7ce71fSopenharmony_ci if (token == NULL) { 790a7ce71fSopenharmony_ci return EC_FAILURE; 800a7ce71fSopenharmony_ci } 810a7ce71fSopenharmony_ci 820a7ce71fSopenharmony_ci if (UidVerify()) { 830a7ce71fSopenharmony_ci return EC_FAILURE; 840a7ce71fSopenharmony_ci } 850a7ce71fSopenharmony_ci 860a7ce71fSopenharmony_ci return OEMWriteToken(token, len); 870a7ce71fSopenharmony_ci} 880a7ce71fSopenharmony_ci 890a7ce71fSopenharmony_ciint HalGetAcKey(char *acKey, unsigned int len) 900a7ce71fSopenharmony_ci{ 910a7ce71fSopenharmony_ci if (acKey == NULL) { 920a7ce71fSopenharmony_ci return EC_FAILURE; 930a7ce71fSopenharmony_ci } 940a7ce71fSopenharmony_ci 950a7ce71fSopenharmony_ci if (UidVerify()) { 960a7ce71fSopenharmony_ci return EC_FAILURE; 970a7ce71fSopenharmony_ci } 980a7ce71fSopenharmony_ci 990a7ce71fSopenharmony_ci return OEMGetAcKey(acKey, len); 1000a7ce71fSopenharmony_ci} 1010a7ce71fSopenharmony_ci 1020a7ce71fSopenharmony_ciint HalGetProdId(char *productId, unsigned int len) 1030a7ce71fSopenharmony_ci{ 1040a7ce71fSopenharmony_ci if (productId == NULL) { 1050a7ce71fSopenharmony_ci return EC_FAILURE; 1060a7ce71fSopenharmony_ci } 1070a7ce71fSopenharmony_ci 1080a7ce71fSopenharmony_ci return OEMGetProdId(productId, len); 1090a7ce71fSopenharmony_ci} 1100a7ce71fSopenharmony_ci 1110a7ce71fSopenharmony_ciint HalGetProdKey(char *productKey, unsigned int len) 1120a7ce71fSopenharmony_ci{ 1130a7ce71fSopenharmony_ci if (productKey == NULL) { 1140a7ce71fSopenharmony_ci return EC_FAILURE; 1150a7ce71fSopenharmony_ci } 1160a7ce71fSopenharmony_ci 1170a7ce71fSopenharmony_ci if (UidVerify()) { 1180a7ce71fSopenharmony_ci return EC_FAILURE; 1190a7ce71fSopenharmony_ci } 1200a7ce71fSopenharmony_ci 1210a7ce71fSopenharmony_ci return OEMGetProdKey(productKey, len); 1220a7ce71fSopenharmony_ci}