/*
 * Copyright (C) 2014 Samsung Electronics. Co. Ltd,
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SSP_H
#define SSP_H

#include "tz_platform.h"
#include "sec_apdu.h"

/*
 * SSP object sizes definition
 */
#define SSP_MIN_AID_SIZE                            5  /* Minimum Applet ID size */
#define SSP_MAX_AID_SIZE                            16 /* Maximum Applet ID size */
#define SSP_TID_SIZE                                16 /* Trusted Application ID size */
#define SSP_AP_ID_SIZE                              16
#define SSP_ESE_ID_SIZE                             16
#define SSP_ENTRY_ID_SIZE                           4
#define SSP_MAX_APPLET_ID_SIZE                      16

#define SSP_SESSION_RANDOM_SIZE                     16
#define SSP_RESET_RANDOM_SIZE                       32
#define SSP_RESET_CHALLENGE_SIZE                    (2048/8)

#define SSP_CMAC_SIZE                               16

#define SSP_OTP_KEY_SIZE                            32
#define SSP_SESSION_KEY_SIZE                        32

#define SSP_MAX_CAPDU_SIZE                          223
#define SSP_MAX_RAPDU_SIZE                          239

#define SSP_MAX_X509_CERT_SIZE                      2048

#define SSP_ECC_PRIVKEY_SIZE                        32
#define SSP_ECC_PUBKEY_SIZE                         65
#define SSP_ECC_SECRET_SIZE                         32

#define SSP_MAX_WRAPPED_OTP_KEY_SIZE                200
#define SSP_MAX_SECURE_OBJECT_SIZE                  5100

typedef uint16_t SSPSTATUS;


/*
 * SSP return values
 */

#define SSPSTATUS_SUCCESS                           0x0000
#define SSPSTATUS_FAILED                            0x0001
#define SSPSTATUS_INVALID_ARGUMENT                  0x0002
#define SSPSTATUS_ESE_FAILED                        0x0003
#define SSPSTATUS_UNEXPECTED_RESPONSE               0x0004
#define SSPSTATUS_SSP_NOT_EXIST                     0x0005
#define SSPSTATUS_CERT_NOT_EXIST                    0x0006
#define SSPSTATUS_GET_CERT_VERIFICATION_FAIL        0x0007

#define SSPSTATUS_OVER_MAX_DATA_SIZE                0x0010
#define SSPSTATUS_INVALID_CMAC                      0x0011

#define SSPSTATUS_OTP_KEY_CORRUPTED                 0x0020
#define SSPSTATUS_OTP_KEY_CONFIRMATION_CORRUPTED    0x0021

#define SSPSTATUS_SESSION_OPEN_FAIL                 0x0030
#define SSPSTATUS_SESSION_INIT_FAIL                 0x0031
#define SSPSTATUS_INVAILD_SESSION_ID                0x0032

#define SSPSTATUS_ESE_CHANNEL_OPEN_FAILED           0x0040
#define SSPSTATUS_ESE_CHANNEL_CLOSE_FAILED          0x0041

void isSspValid(p_cmd_t cmd, p_rsp_t rsp);
void getSspVerStatus(p_rsp_t rsp);
void provisionKotp(p_cmd_t cmd, p_rsp_t rsp, uint8_t type);
void resetSspForFactory(p_rsp_t rsp);

#endif /* SSP_H */
