初始版本

This commit is contained in:
xiaozhengsheng
2025-08-19 09:49:41 +08:00
parent 10f1ddf1c1
commit 6df0f7d96e
2974 changed files with 1712873 additions and 54 deletions

View File

@@ -0,0 +1,39 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file Version.h
*
* \brief This file defines the Host Library version number.
*
*/
#ifndef _VERSION_H_
#define _VERSION_H_
/// Version information of the Host Library
#define VERSION_HOST_LIBRARY "Ver 1.50.1153"
#endif //_VERSION_H_

View File

@@ -0,0 +1,880 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines APIs, types and data structures used in the
* Command Library implementation.
*
* \addtogroup grCmdLib
* @{
*/
#ifndef _CMD_LIB_H_
#define _CMD_LIB_H_
#include <stdint.h>
#include "optiga/common/Datatypes.h"
#include "optiga/common/ErrorCodes.h"
#include "optiga/common/AuthLibSettings.h"
#include "optiga/comms/optiga_comms.h"
/****************************************************************************
*
* API Error Codes
*
****************************************************************************/
///Requested operation completed without any error
#define CMD_LIB_OK 0x75E96B01
///Device error, the device error(last error code) is available in the least significant byte e.g. for Invalid OID 0x80010001 is returned.
#define CMD_DEV_ERROR 0x80010000
///An error to indicate that command execution failed.It is possibly that the application on security chip is not open or communication failure has occurred.
#define CMD_DEV_EXEC_ERROR 0x80020000
///Null parameter(s)
#define CMD_LIB_NULL_PARAM 0x80001001
///Invalid or unsupported parameter(s)
#define CMD_LIB_INVALID_PARAM (CMD_LIB_NULL_PARAM + 1)
///Insufficient memory
#define CMD_LIB_INSUFFICIENT_MEMORY (CMD_LIB_NULL_PARAM + 2)
///Length of Input is zero
#define CMD_LIB_LENZERO_ERROR (CMD_LIB_NULL_PARAM + 3)
///Invalid Session ID
#define CMD_LIB_INVALID_SESSIONID (CMD_LIB_NULL_PARAM + 4)
///Invalid Tag
#define CMD_LIB_INVALID_TAG (CMD_LIB_NULL_PARAM + 5)
///Invalid Tag Length
#define CMD_LIB_INVALID_TAGLEN (CMD_LIB_NULL_PARAM + 6)
///Invalid Length
#define CMD_LIB_INVALID_LEN (CMD_LIB_NULL_PARAM + 7)
///Decryption failed
#define CMD_LIB_DECRYPT_FAILURE (CMD_LIB_NULL_PARAM + 8)
///Invalid OID
#define CMD_LIB_INVALID_OID (CMD_LIB_NULL_PARAM + 9)
///Generic error condition
#define CMD_LIB_ERROR 0xF87ECF01
///Length of the hash context information for SHA 256
#define CALC_HASH_SHA256_CONTEXT_SIZE (130)
///Overhead for all hash calculation operations (Tag and Length size (3 bytes) + APDU header (4 bytes))
#define CALC_HASH_FIXED_OVERHEAD_SIZE (0x03 + 0x04)
///Overhead for import or export hash context (Tag and Length size (3 bytes))
#define CALC_HASH_IMPORT_OR_EXPORT_OVERHEAD_SIZE (0x03)
///Overhead for import and export hash context
#define CALC_HASH_IMPORT_AND_EXPORT_OVERHEAD_SIZE (0x06)
/****************************************************************************
*
* Common data structure used across all functions.
*
****************************************************************************/
/**
* \brief Structure to receive the response of the device for a command.
*/
typedef struct sCmdResponse_d
{
///The length of the buffer
uint16_t wBufferLength;
///Pointer to the buffer to copy the response
uint8_t *prgbBuffer;
///Actual length of the response
uint16_t wRespLength;
}sCmdResponse_d;
/**
* \brief Function to send a command and receive response for the command.
*/
typedef int32_t (*pFTransceive)(const void* ctx,const uint8_t *PprgbWriteBuffer, const uint16_t *PpwWriteBufferLen, uint8_t *PprgbReadBuffer, uint16_t *PpwReadBufferLen);
/****************************************************************************
*
* Definitions related to OpenApplication and CloseApplication commands.
*
****************************************************************************/
/**
* \brief Enumerations to open the application on security chip.
*/
typedef enum eOpenType_d
{
///Initialise a clean application context
eInit = 0x00
}eOpenType_d;
/**
* \brief Structure to specify open application command parameters.
*/
typedef struct sOpenApp_d
{
///Type of option for Open application
eOpenType_d eOpenType;
}sOpenApp_d;
/**
* \brief Opens the Security Chip Application.
*/
LIBRARY_EXPORTS int32_t CmdLib_OpenApplication(const sOpenApp_d* PpsOpenApp);
/// @cond hidden
LIBRARY_EXPORTS void CmdLib_SetOptigaCommsContext(const optiga_comms_t *p_input_optiga_comms);
/// @endcond
/****************************************************************************
*
* Definitions related to GetDataObject and SetDataObject commands.
*
****************************************************************************/
/**
* \brief Enumeration to specify data or metadata.
*/
typedef enum eDataOrMedata_d
{
///Read or write data
eDATA,
///Read or write metadata
eMETA_DATA
}eDataOrMedata_d;
/**
* \brief Enumeration to specify write option.
*/
typedef enum eWriteOption_d
{
///Perform write operation
eWRITE,
///Perform erase and write operation
eERASE_AND_WRITE
}eWriteOption_d;
/**
* \brief Structure to specify GetDataObject command parameters.
*/
typedef struct sGetData_d
{
///OID of data object
uint16_t wOID;
///Offset within the data object
uint16_t wOffset;
///Number of data bytes to read
uint16_t wLength;
///To read data or metadata
eDataOrMedata_d eDataOrMdata;
}sGetData_d;
/**
* \brief Structure to specify SetDataObject command parameters.
*/
typedef struct sSetData_d
{
///OID of data object
uint16_t wOID;
///Offset within the data object
uint16_t wOffset;
///Number of data bytes to write
uint16_t wLength;
///Data bytes to be written
uint8_t *prgbData;
///To write data or metadata
eDataOrMedata_d eDataOrMdata;
///Write option
eWriteOption_d eWriteOption;
}sSetData_d;
#ifdef MODULE_ENABLE_READ_WRITE
/**
* \brief Reads the specified data object by issuing GetDataObject command.
*/
LIBRARY_EXPORTS int32_t CmdLib_GetDataObject(const sGetData_d *PpsGDVector, sCmdResponse_d *PpsResponse);
/**
* \brief Writes to the specified data object by issuing SetDataObject command.
*/
LIBRARY_EXPORTS int32_t CmdLib_SetDataObject(const sSetData_d *PpsSDVector);
/**
* \brief Reads maximum communication buffer size supported by the security chip.
*/
LIBRARY_EXPORTS uint16_t CmdLib_GetMaxCommsBufferSize(Void);
#endif
/****************************************************************************
*
* Definitions related to authentication commands.
*
****************************************************************************/
///Challenge minimum length
#define CHALLENGE_MIN_LEN 0x08
///Challenge maximum length
#define CHALLENGE_MAX_LEN 0x100
/**
* \brief Enumeration to specify an authentication scheme.
*/
typedef enum eAuthScheme_d
{
///The ECDSA signature scheme as specified within FIPS 186-3 (SHA256)
eECDSA = 0x91,
///DTLS Client scheme with cipher suite as DTLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
eDTLSClient = 0x99
}eAuthScheme_d;
/**
* \brief Structure to specify authentication command parameters.
*/
typedef struct sAuthMsg_d
{
///Challenge length
uint16_t wRndLength;
///Challenge
uint8_t *prgbRnd;
///Authentication scheme
eAuthScheme_d eAuthScheme;
///Private key
uint16_t wOIDDevPrivKey;
}sAuthMsg_d;
/**
* \brief Structure to specify authentication Scheme parameters.
*/
typedef struct sAuthScheme_d
{
///OID of Device Private key
uint16_t wDevicePrivKey;
///OID of Session Key
uint16_t wSessionKeyId;
///Authentication scheme
eAuthScheme_d eAuthScheme;
}sAuthScheme_d;
/**
* \brief Enumeration to specify the type of the random number
*/
typedef enum eRngType_d
{
///True random number
eTRNG = 0x00,
///Deterministic random number
eDRNG = 0x01,
}eRngType_d;
/**
* \brief Structure to specify option to generate random number
*/
typedef struct sRngOptions_d
{
///Type of Random number
eRngType_d eRngType;
///Length of the random number to be generated
uint16_t wRandomDataLen;
}sRngOptions_d;
/**
* \brief Gets the signature generated by Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_GetSignature(const sAuthMsg_d *PpsAuthMsg, sCmdResponse_d *PpsResponse);
/**
* \brief Gets the true random bytes generated by Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_GetRandom(const sRngOptions_d *PpsRng, sCmdResponse_d *PpsResponse);
/**
* \brief Sets the Authentication Scheme by issuing SetAuthScheme command to Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_SetAuthScheme(const sAuthScheme_d *PpsAuthVector);
/**
* \brief Enumeration to specify Hashing algorithm.
*/
typedef enum eHashAlg_d
{
///SHA256 for Hashing
eSHA256 = 0xE2
}eHashAlg_d;
/**
* \brief Enumeration to specify Hashing Sequence.
*/
typedef enum eHashSequence_d
{
///Start hashing
eStartHash = 0x00,
///Start and Finalize hashing
eStartFinalizeHash = 0x01,
///Continue hashing
eContinueHash = 0x02,
///Finalize hashing
eFinalizeHash = 0x03,
///Terminate hashing
eTerminateHash = 0x04,
///Get Intermediate hash
eIntermediateHash = 0x05
}eHashSequence_d;
/**
* \brief Enumeration to specify Hashing data type.
*/
typedef enum eDataType_d
{
///Data stream
eDataStream = 0x00,
///OID contents
eOIDData = 0x01
}eDataType_d;
/**
* \brief Structure to specify OID information.
*/
typedef struct sOIDInfo_d
{
///OID of data object
uint16_t wOID;
///Offset within the data object
uint16_t wOffset;
///Number of data bytes starting from the offset
uint16_t wLength;
}sOIDInfo_d;
/**
* \brief Enumeration to specify the action to be performed with the context.
*/
typedef enum eContextAction_d
{
///Context data is not used
eUnused = 0x00,
///Import hash context to perform the hash
eImport = 0x06,
///Export the current active hash context
eExport = 0x07,
///Import the provided hash context and export back the hash context after hashing
eImportExport = 0x67
}eContextAction_d;
/**
* \brief Structure to specify the information for context information.
*/
typedef struct sContextInfo_d
{
///Action on the input context
eContextAction_d eContextAction;
///Pointer to memory , to copy to/from context data
uint8_t* pbContextData;
///Length of the context while importing/ Length of memory while exporting context
uint16_t dwContextLen;
}sContextInfo_d;
/**
* \brief Structure to specify parameters for Hash generation.
*/
typedef struct sCalcHash_d
{
///Hashing Algorithm
eHashAlg_d eHashAlg;
///Hashing sequence
eHashSequence_d eHashSequence;
///Type of data for hashing
eDataType_d eHashDataType;
///Data stream blob for hashing
sbBlob_d sDataStream;
///Object data for hashing
sOIDInfo_d sOIDData;
///Output Hash
sCmdResponse_d sOutHash;
///Context Information
sContextInfo_d sContextInfo;
}sCalcHash_d;
/**
* \brief Structure to specify hash information.
*/
typedef struct sHashinfo
{
///Hash Algorithm type
eHashAlg_d eHashAlgo;
///Hash Length
uint8_t bHashLen;
///Hash context data
uint16_t wHashCntx;
}sHashinfo_d;
/**
* \brief Enumeration for supported Signing scheme.
*/
typedef enum eSignScheme_d
{
///ECDSA FIPS 186-3 w/o hash
eECDSA_FIPS_186_3_WITHOUT_HASH = 0x11
}eSignScheme_d;
/**
* \brief Enumeration for supported algorithm identifier.
*/
typedef enum eAlgId_d
{
///Elliptic curve key on NIST P256 curve
eECC_NIST_P256 = 0x03,
///Elliptic curve key on NIST P384 curve
eECC_NIST_P384 = 0x04
}eAlgId_d;
/**
* \brief Structure to specify public key for verify hash
*/
typedef struct sPubKeyInput_d
{
///Algorithm identifier
eAlgId_d eAlgId;
///Data stream containing public key
sbBlob_d sDataStream;
}sPubKeyInput_d;
/**
* \brief Structure to specify parameters for Signature verification.
*/
typedef struct sVerifyOption_d
{
///Signing scheme
eSignScheme_d eSignScheme;
///Source of the public key
eDataType_d eVerifyDataType;
///Data stream blob for hashing
sPubKeyInput_d sPubKeyInput;
///OID of data object
uint16_t wOIDPubKey;
}sVerifyOption_d;
/**
* \brief Structure to return key pair as output.
*/
typedef struct sOutKeyPair_d
{
///Blob pointing to memory to store public key
sbBlob_d sPublicKey;
///Blob pointing to memory to store private key
sbBlob_d sPrivateKey;
}sOutKeyPair_d;
/**
* \brief Enumeration to specify the action on key pair.
*/
typedef enum eKeyExport_d
{
///Stores only the private key in the OID and exports the public key
eStorePrivKeyOnly = 0x01,
///Exports both public and private key as the output
eExportKeyPair = 0x07
}eKeyExport_d;
/**
* \brief Enumeration to specify supported key usage.
*/
typedef enum eKeyUsage_d
{
///The key is used for authentication
eAuthentication = 0x01,
///The key is used for encryption
eEncryption = 0x02,
///The key is used for host firmware update
eHostFwUpdate = 0x04,
///The key is used for device management
eDevMgmt = 0x08,
///The key is used for signature
eSign = 0x10,
///The key agreement
eKeyAgreement = 0x20
}eKeyUsage_d;
/**
* \brief Structure to specify parameters for Key Pair Generation.
*/
typedef struct sKeyPairOption_d
{
///Algorithm identifier of the key to be generated
eAlgId_d eAlgId;
///Option to export/store keys
eKeyExport_d eKeyExport;
///OID of the private key/session context to be generated
uint16_t wOIDPrivKey;
///Key Usage
eKeyUsage_d eKeyUsage;
}sKeyPairOption_d;
/**
* \brief Structure to specify parameters for signature generation.
*/
typedef struct sCalcSignOptions_d
{
///Signing scheme
eSignScheme_d eSignScheme;
///OID of the signature key
uint16_t wOIDSignKey;
///Digest to be signed
sbBlob_d sDigestToSign;
}sCalcSignOptions_d;
/**
* \brief Enumeration to specify supported key agreement primitives
*/
typedef enum eKeyAgreementType_d
{
///Elliptic Curve Diffie-Hellman shared secret agreement according to NIST SP-800 56A
eECDH_NISTSP80056A = 0x01
}eKeyAgreementType_d;
/**
* \brief Structure to specify parameters for shared secret calculation.
*/
typedef struct sCalcSSecOptions_d
{
///Key agreement algorithm
eKeyAgreementType_d eKeyAgreementType;
///Algorithm identifier of the public key
eAlgId_d ePubKeyAlgId;
///OID of the private key/session context for shared secret calculation
uint16_t wOIDPrivKey;
///OID of the session context to store the calculated secret
uint16_t wOIDSharedSecret;
///Public key for shared secret calculation
sbBlob_d sPubKey;
}sCalcSSecOptions_d;
/**
* \brief Enumeration to specify supported key derivation method
*/
typedef enum eKeyDerivationMethod_d
{
///IETF 5246 TLS PRF SHA256
eTLS_PRF_SHA256 = 0x01
}eKeyDerivationMethod_d;
/**
* \brief Structure to specify parameters for derive key generation.
*/
typedef struct sDeriveKeyOptions_d
{
///Key derivation method
eKeyDerivationMethod_d eKDM;
///OID of Shared Secret to derive the new secret from
uint16_t wOIDSharedSecret;
///The length of the key to be derived
uint16_t wDerivedKeyLen;
///OID to store the Derived key
uint16_t wOIDDerivedKey;
///Seed
sbBlob_d sSeed;
}sDeriveKeyOptions_d;
#ifdef MODULE_ENABLE_TOOLBOX
/**
* \brief Calculates the hash on input data by issuing CalcHash command to Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_CalcHash(sCalcHash_d* PpsCalcHash);
/**
* \brief Verify the signature on digest by issuing VerifySign command to Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_VerifySign(const sVerifyOption_d* PpsVerifySign,const sbBlob_d * PpsDigest,const sbBlob_d * PpsSignature);
/**
* \brief Generate a key pair by issuing GenKeyPair command to Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_GenerateKeyPair(const sKeyPairOption_d* PpsKeyPairOption,sOutKeyPair_d* PpsOutKeyPair);
/**
* \brief Calculate signature on a digest by issuing CalcSign command to the Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_CalculateSign(const sCalcSignOptions_d *PpsCalcSign,sbBlob_d *PpsSignature);
/**
* \brief Calculate shared secret by issuing CalcSSec command to the Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_CalculateSharedSecret(const sCalcSSecOptions_d *PpsCalcSSec,sbBlob_d *PpsSecret);
/**
* \brief Derive session key by issuing DeriveKey command to the Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_DeriveKey(const sDeriveKeyOptions_d *PpsDeriveKey,sbBlob_d *PpsKey);
#endif/*MODULE_ENABLE_TOOLBOX*/
/****************************************************************************
*
* Definitions related to (D)TLS commands.
*
****************************************************************************/
///Length of APDU header
#define LEN_APDUHEADER 0x04
///Number of bytes in Session ID field
#define BYTES_SESSIONID 0x02
///bits per byte
#define BITS_PER_BYTE 0x08
///Tag Encoding length
#define LEN_TAG_ENCODING 0x03
///Additional bytes for Encryption/Decryption
#define ADDITIONALBYTES_ENCDEC 10
///Overhead for all uplink/downlink messages
#define OVERHEAD_UPDOWNLINK (LEN_APDUHEADER + BYTES_SESSIONID + LEN_TAG_ENCODING + ADDITIONALBYTES_ENCDEC)
//Overhead for Encrypt/Decrypt response
#define OVERHEAD_ENCDEC_RESPONSE (LEN_APDUHEADER + LEN_TAG_ENCODING)
/**
* \brief Enumeration to specify the type of message.
*/
typedef enum eMsgType_d
{
//Client Side Message type
///Client Hello
eClientHello = 0x01,
///Client Hello with Cookie
eClientHelloWithCookie = 0x03,
///Client Certificate
eClientCertificate = 0x0B,
///Client Key Exchange
eClientKeyExchange = 0x10,
///Certificate Verify
eCertificateVerify = 0x0F,
///Client Finished
eClientFinished = 0x14,
//Server Side Message type
///Hello Verify Request
eHelloVerifyRequest = 0x03,
///Server Hello
eServerHello = 0x02,
///Server Certificate
eServerCertificate = 0x0B,
///Server Key Exchange
eServerKeyExchange = 0x0C,
///Certificate Request
eCertificateRequest = 0x0D,
///Server Hello Done
eServerHelloDone = 0x0E,
///Server Finished
eServerFinished = 0x14,
///Change cipher spec
eChangeCipherSpec = 0x13,
///Close session
eCloseSession = 0x71
}eMsgType_d;
/**
* \brief Union to specify message specific parameters
*/
typedef union uMsgParams_d
{
///Client Hello Params
struct sMsgParamCH_d
{
///Unix Time
uint32_t dwUnixTime;
}sMsgParamCH_d;
///Certificate Params
struct sMsgParamCert_d
{
///Certificate OID
uint16_t wCertOID;
}sMsgParamCert_d;
}uMsgParams_d;
///Callback to Caller to accept the message
typedef int32_t (*fAcceptMessage)(Void*,const sbBlob_d*);
/**
* \brief Structure to specify Call back parameters for Get Message.
*/
typedef struct sCallBack_d
{
///Callback to Caller to accept the message
fAcceptMessage pfAcceptMessage;
///Params for Call back
Void* fvParams;
}sCallBack_d;
/**
* \brief Structure to specify parameters for (D)TLS handshake messages.
*/
typedef struct sProcMsgData_d
{
///Pointer to Input Buffer memory
sbBlob_d* psBlobInBuffer;
///Type of Message
eMsgType_d eParam;
///Session Key OID
uint16_t wSessionKeyOID;
///Message related parameters
uMsgParams_d* puMsgParams;
///Pointer to a structure containing Callback function and parameter pointer to Caller to accept the message
sCallBack_d *psCallBack;
}sProcMsgData_d;
/**
* \brief Structure to specify ProcUpLink/ProcDownLink command parameters.
*/
typedef struct sProcCryptoData_d
{
///Contains data to be encrypted/decrypted.This should contain enough memory to accommodate APDU header, data formatting and the data for encryption/decryption
sbBlob_d sInData;
///Actual length of data to be encrypted/decrypted
uint16_t wInDataLength;
///Session Key OID
uint16_t wSessionKeyOID;
///Holds the output data after encryption/decryption
sCmdResponse_d sOutData;
}sProcCryptoData_d;
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
/**
* \brief Generates Uplink message by issuing ProcUpLink command to Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_GetMessage(const sProcMsgData_d *PpsGMsgVector);
/**
* \brief Process Authentication message by issuing ProcDownLink command to Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_PutMessage(const sProcMsgData_d *PpsPMsgVector);
/**
* \brief Encrypts data by issuing ProcUpLink command to Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_Encrypt(sProcCryptoData_d *PpsEncVector);
/**
* \brief Decrypts data by issuing ProcDownLink command to Security Chip.
*/
LIBRARY_EXPORTS int32_t CmdLib_Decrypt(sProcCryptoData_d *PpsDecVector);
/**
* \brief Closes the Security Chip session as indicated by the Session Reference Id.
*/
LIBRARY_EXPORTS int32_t CmdLib_CloseSession(uint16_t PwSessionRefId);
#endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH*/
#endif //_CMD_LIB_H_
/**
* @}
*/

View File

@@ -0,0 +1,91 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file is defines the compilation switches to build code with required features.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef _AUTH_LIB_SETTINGS_H_
#define _AUTH_LIB_SETTINGS_H_
/*
To enable a user in choosing required feature set, compilation switches are provided to build the code.
1.FEATURE_ONEWAY_AUTH : One Way authentication feature is enabled.
2.FEATURE_DTLS_MUTUAL_AUTH : Mutual authentication feature is enabled.
3.FEATURE_TOOLBOX : Tool box feature is enabled
4.By default all features are enabled.
A user can define more switches in the following way and add it before the default #else directive
//Sample definition for new compile time switch
#ifdef NEW_REQUIRED_FEATURES
#define MODULE_X
#define MODULE_Y
#define MODULE_Z
#endif
*/
//If only One Way Authentication feature required
#ifdef FEATURE_ONEWAY_AUTH
#define MODULE_ENABLE_READ_WRITE
#define MODULE_ENABLE_ONE_WAY_AUTH
#define FEATURE_ENABLED
#endif
//If only Mutual Authentication feature required
#ifdef FEATURE_DTLS_MUTUAL_AUTH
#define MODULE_ENABLE_READ_WRITE
#define MODULE_ENABLE_DTLS_MUTUAL_AUTH
#define FEATURE_ENABLED
#endif
#ifdef FEATURE_TOOLBOX
#define MODULE_ENABLE_TOOLBOX
#define FEATURE_ENABLED
#endif
//By Default all are enabled
#ifndef FEATURE_ENABLED
#define MODULE_ENABLE_READ_WRITE
#define MODULE_ENABLE_ONE_WAY_AUTH
// #define MODULE_ENABLE_DTLS_MUTUAL_AUTH
#define MODULE_ENABLE_TOOLBOX
#endif
#ifdef OPTIMIZE_CODE
#define OPTIMIZE_CODE(x) #ifndef x
#define OPTIMIZE_CODE_ENDS(x) #endif
#else
#define OPTIMIZE_CODE(x)
#define OPTIMIZE_CODE_ENDS(x)
#endif
#endif /* _AUTH_LIB_SETTINGS_H_*/
/**
* @}
*/

View File

@@ -0,0 +1,140 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
*
* \file
*
* \brief This file contains the type definitions for the fundamental data types.
*
*
*
*/
#ifndef _DATATYPES_H_
#define _DATATYPES_H_
/******************************************************************************
* required includes
* Setup common include order for the used types and definitions
******************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
/******************************************************************************
* DataTypes.h
******************************************************************************/
/******************************************************************************
* defines
******************************************************************************/
/// @cond hidden
#ifndef _OPTIGA_EXPORTS_DLLEXPORT_H_
#define _OPTIGA_EXPORTS_DLLEXPORT_H_
#if defined(WIN32) || defined(_WIN32)
#ifdef OPTIGA_LIB_EXPORTS
#define LIBRARY_EXPORTS __declspec(dllexport)
#elif defined(OPTIGA_LIB_EXCLUDE_IMPORT)
#define LIBRARY_EXPORTS
#else
#define LIBRARY_EXPORTS __declspec(dllimport)
#endif // OPTIGA_LIB_EXPORTS
#else
#define LIBRARY_EXPORTS
#endif //WIN32
#endif /*_OPTIGA_EXPORTS_DLLEXPORT_H_*/
/// @endcond
/// Definition for false
#ifndef FALSE
#define FALSE 0
#endif
/// Definition for true
#ifndef TRUE
#define TRUE 1
#endif
/******************************************************************************
* fundamental typedefs
******************************************************************************/
/// Typedef for one byte integer
typedef char char_t;
/// Typedef for native byte pointer
typedef uint8_t* puint8_t;
/// Typedef for a 4 byte unsigned integer pointer
typedef uint32_t* puint32_t;
/// Typedef for unsigned word pointer
typedef uint16_t* puint16_t ;
/// Typedef for a void
typedef void Void;
/// Typedef for a double word
typedef double double_t;
/// Typedef for a float
typedef float float_t;
/// Typedef for a boolean
typedef uint8_t bool_t;
/// Typedef for Handle
typedef Void* hdl_t;
/// typedef for host library status
typedef uint16_t host_lib_status_t;
/// typedef for OPTIGA host library status (will be updated to different data type in the future to keep in sync with other modules)
typedef int32_t optiga_lib_status_t;
/**
* \brief Structure to specify a byte stream consisting of length and data
* pointer.
*/
typedef struct sbBlob_d
{
/// Length of the byte stream
uint16_t wLen;
/// Pointer to byte array which contains the data stream
uint8_t *prgbStream;
} sbBlob_d;
/// typedef for application event handler
typedef void (*app_event_handler_t)(void* upper_layer_ctx, host_lib_status_t event);
#ifndef _STATIC_H
#define _STATIC_H static
#endif
#endif /* __DATATYPES_H__ */

View File

@@ -0,0 +1,153 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines the error codes.
*
*
*
*/
#ifndef _ERRORCODES_H_
#define _ERRORCODES_H_
/******************************************************************************
* required includes
* Setup common include order for the used types and definitions
******************************************************************************/
/******************************************************************************
* ErrorCodes.h
******************************************************************************/
/******************************************************************************
* defines
******************************************************************************/
/// Communication success
#define E_COMMS_SUCCESS 0x00000000
/// Error code if protocol exit timeout has occurred
#define E_COMMS_TIMEOUT_OCCURRED 0x80000003
/// Error code if soft reset is not supported by slave
#define E_COMMS_SOFT_RESET_NOT_SUPPORTED 0x80000005
/// Error code if network layer channel does not mismatch with that of the slave
#define E_COMMS_CHANNEL_NUM_MISMATCH 0x80000006
/// Error code if packet size could not be set
#define E_COMMS_PACKET_SIZE_NOT_SET 0x80000007
/// Error code for invalid key
#define E_COMMS_INVALID_KEY 0x80000008
/// Error code if the input parameter is NULL
#define E_COMMS_PARAMETER_NULL 0x8000000A
/// Error code for uninitialized protocol
#define E_COMMS_PROTOCOL_NOT_INITIALIZED 0x8000000B
/// Error code for wrong reset value
#define E_INVALID_RESET_VALUE 0x8000000C
///Error code for invalid value for a given key
#define E_INVALID_VALUE_FOR_KEY 0x8000000D
/// Error code for if the slave doesn't have any data ready
#define E_COMMS_SLAVE_NODATA 0x8000000E
/// Error code if no channel information is present
#define E_COMMS_NO_CHANNEL_INFORMATION 0x8000000F
/// Error code if APDU is not present
#define E_COMMS_NO_APDU_PRESENT 0x80000010
/// Error code for cold reset not supported
#define E_COMMS_COLD_RESET_NOT_SUPPORTED 0x80000011
/// Error code for partial frame send
#define E_COMMS_PARTIAL_FRAME_SENT 0x80000012
/// Error code for low level I2C write failed
#define E_COMMS_I2C_WRITE_FAILED 0x80000013
/// Error code for low level I2C read failed
#define E_COMMS_I2C_READ_FAILED 0x80000014
/// Error code for buffer size or memory insufficient
#define E_COMMS_INSUFFICIENT_BUF_SIZE 0x80000015
/// Error code when the value of key is not set
#define E_COMMS_KEY_VALUE_NOT_SET 0x80000016
/// Error code for setting a property within a session not allowed
#define E_COMMS_SET_PROPERTY_DENIED 0x80000017
/// Error code for opening the already opened protocol stack
#define E_COMMS_ALREADY_OPEN 0x80000018
/// Error code for frame buffer overflow(at data link layer)
#define E_COMMS_FRAME_BUFFER_OVERFLOW 0x80000019
/// Error code for unsupported functionality
#define E_COMMS_FUNCTION_NOT_SUPPORTED 0x8000001A
/// Error code for invalid channel number
#define E_COMMS_INVALID_CHANNEL_NO 0x8000001B
/// Error code for insufficient memory
#define E_COMMS_INSUFFICIENT_MEMORY 0x8000001C
/// Error code if Nack is received
#define E_COMMS_I2C_NACK_RECEIVED 0x8000001D
/// Error code for I2C Tx/Rx Error
#define E_COMMS_I2C_TXRX_ERROR 0x8000001E
/// Error code for I2C Tx/Rx Error
#define E_COMMS_I2C_TIMEOUT 0x8000001F
/// Error code for I2C Tx/Rx Error
#define E_COMMS_INVALID_REQUEST 0x80000020
/// Error code for communication failure
#define E_COMMS_FAILURE 0xFFFFFFFF
/// Indicates no session available at OPTIGA
#define OPTIGA_LIB_NO_SESSION_AVAILABLE 0x0000
/// OPTIGA Host Library API status - Success
#define OPTIGA_LIB_SUCCESS 0x0000
/// OPTIGA Host Library API status - Busy
#define OPTIGA_LIB_STATUS_BUSY 0x0001
/// OPTIGA Host Library API status - Failure
#define OPTIGA_LIB_ERROR 0xFFFF
#endif /* _ERRORCODES_H_ */

View File

@@ -0,0 +1,362 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
* \file
*
* \brief This file contains a light weight logger.
*
*
* \addtogroup grLogger
* @{
*
*/
#ifndef __LOGGER_H__
#define __LOGGER_H__
#include "optiga/common/Util.h"
#ifdef WIN32
#include <stdio.h>
#endif
/// @cond hidden
/*****************************************************************************
* Defines
*****************************************************************************/
/// Flag for transmit direction
#define TX_DIRECTION 0
/// Flag for reception direction
#define RX_DIRECTION 1
/// Flag to write to console UART
#define CONSOLE_PORT 0
/// Flag to write to cuint UART
#define CUNIT_PORT 1
/// Flag to write to code coverage UART
#define CODE_COVERAGE_PORT 2
//Pointer to writer
typedef int32_t (*pFWriteData)(uint32_t PdwPort, uint8_t* PprgbBuf, uint32_t PdwDataLen);
///This is pointer to log writer
extern pFWriteData pfWriter;
///This function converts Uint8 value to Hex String
void ConvUint8ToHexString (uint8_t* PprgbHexByteArray, uint8_t* PprgbHexString, \
uint32_t dwNoOfBytes, uint8_t PbIsSpaceReq);
///This function converts Uint32 to Hex String
void ConvUint32ToHexString (uint32_t dwVal, uint8_t* PprgbHexString);
///This function converts Uint32 value to Decimal String
void ConvUint32ToDecString (uint32_t dwVal, uint8_t* PprgbDecStr, \
uint8_t bExpStrLen, uint8_t bFillChar);
/*****************************************************************************
* Exposed Logging APIs
*****************************************************************************/
/// Logs a new line
void Util_NewLine(uint32_t PdwUartPort);
/// Logs a string with newline at the end
void Util_LogStringLine(uint32_t PdwUartPort, const char_t *pszString);
/// Logs a string
void Util_LogString(uint32_t PdwUartPort, const char_t *pszString);
//Logs Integer
void Util_LogInt(uint32_t PdwUartPort, const char_t *pszMsg, uint32_t dwValue);
/// Logs a byte array
void Util_LogArray(uint8_t* prgbBuf, uint16_t wLen, bool_t fDirection, bool_t fDumpPacketAnalysis);
/// Print an array in hex format
void Util_DumpHex(uint8_t* prgbBuf, uint16_t wLen);
//Print on console port with new line
#define CONSOLE_LOGSTRINGLINE(pszString) Util_LogStringLine(CONSOLE_PORT,pszString);
//Print on console port
#define CONSOLE_LOGSTRING(pszString) Util_LogString(CONSOLE_PORT,pszString);
//Print on console port
#define CONSOLE_LOGINTEGER(pszString,value) Util_LogInt(CONSOLE_PORT,pszString,value);
//Print on Cunit port
#define CUNIT_LOGSTRING(pszString) Util_LogString(CUNIT_PORT,pszString);
//Print on coverage port
#define COVERAGE_LOGSTRING(pszString,dwLen) pfWriter(CODE_COVERAGE_PORT,pszString,dwLen);
/*****************************************************************************
* Level based logging Exposed APIs
*****************************************************************************/
/// @endcond
/**
* \brief Structure to Logger.
*/
typedef struct sLogger_d
{
///Handle to instance of writer
uint32_t* pHdl;
///Log Writer
hdl_t phfWriter;//This to be replaced by actual type
}sLogger_d;
#ifdef ENABLE_LOG
//This is second write
typedef int32_t (*pFWriteData2)(void* Hdl, uint8_t* PprgbBuf, uint32_t PdwDataLen);
//This is the arguement to be passed to pfWriter.It refers to the handle to writer context/structure.
extern void* pHandle;
//This is second log writer
extern pFWriteData2 pfWriter2;
///Delimiter to indicate "Seperator Open"
#define DELIMITER_OPEN "["
///Delimiter to indicate "Seperator Close"
#define DELIMITER_CLOSE "]"
///Format to print time as [hh:mm:ss][level][type] :message newline
#define LOG_FORMAT "[%s]%-4s%-2s:%s%s"
///Log message Level
///This indicates message is an Information
#define LOGGER_LEVEL_INFO DELIMITER_OPEN"Info"DELIMITER_CLOSE
///This indicates message is a Warning
#define LOGGER_LEVEL_WARNING DELIMITER_OPEN"Warn"DELIMITER_CLOSE
///This indicates message is an Error
#define LOGGER_LEVEL_ERROR DELIMITER_OPEN"Erro"DELIMITER_CLOSE
///Log message Type
///This indicates message is logged from Handshake Layer
#define LOGGER_TYPE_HANDSHAKE DELIMITER_OPEN"HS"DELIMITER_CLOSE
///This indicates message is logged from Record Layer
#define LOGGER_TYPE_RECORDLAYER DELIMITER_OPEN"RL"DELIMITER_CLOSE
///This indicates message is logged from Transport Layer
#define LOGGER_TYPE_TRANSPORTLAYER DELIMITER_OPEN"TL"DELIMITER_CLOSE
/**
* \brief This structure represents Log Level Types
*/
typedef enum eLogLevel {
///Information
eInfo = 1,
///Warning
eWarning = 2,
///Error
eError = 3,
}eLogLevel;
/**
* \brief This structure represents Log Layer Types
*/
typedef enum eLogLayer {
///Handshake
eHS = 1,
///Record
eRL = 2,
///Transport
eTL = 3,
}eLogLayer;
/**
* \brief This structure contains state of logging
*/
typedef enum eSetState {
///Enable Logging
eEnable = 0x01,
///Disable Logging
eDisable = 0x02,
//Invalid
eInvalid = 0xFF
}eSetState;
/**
* \brief Returns the current state of Logging level.
*/
eSetState Util_GetLogLevelState(eLogLevel level);
/**
* \brief Sets the state of the Logging Level.
*/
void Util_SetLogLevelState(eLogLevel type,eSetState value);
/**
* \brief Returns the current state of the Logging Layer.
*/
eSetState Util_GetLogLayerState(eLogLayer layer);
/**
* \brief Sets the state of the Logging Layer.
*/
void Util_SetLogLayerState(eLogLayer layer,eSetState value);
/**
* \brief Sets the Log Writer and handle.
*/
void Util_SetLogWriter(pFWriteData2 writer,void* pHdl);
/**
* \brief Logs a message with type and level information.
*/
void Util_LogMessage(char* message, eLogLayer layer, eLogLevel level);
/**
* \brief Logs a 4 byte debug value with type and level information.
*/
void Util_LogDebugVal(uint32_t dwDBValue, eLogLayer layer, eLogLevel level);
/**
* \brief Logs a message with type,level information and also the content of the buffer.
*/
void Util_LogMsgArray(char* pzMsg, uint8_t* PrgbBuffer, uint16_t wLen, eLogLayer eLayer, eLogLevel eLevel);
#endif
///Define ENABLE_LOG to enable logging
#ifdef ENABLE_LOG
///Disable Layer during runtime
#define DISABLE_LOGGING_LAYER(layer) Util_SetLogLayerState(layer,eDisable)
///Enable Layer during runtime
#define ENABLE_LOGGING_LAYER(layer) Util_SetLogLayerState(layer,eEnable)
///Get Layer State
#define GET_LOGGING_LAYER(layer) Util_GetLogLayerState(layer)
///Disable Level during runtime
#define DISABLE_LOGGING_LEVEL(level) Util_SetLogLevelState(level,eDisable)
///Enable Level during runtime
#define ENABLE_LOGGING_LEVEL(level) Util_SetLogLevelState(level,eEnable)
///Get Level State
#define GET_LOGGING_LEVEL(level) Util_GetLogLevelState(level)
#else
/// @cond hidden
#define DISABLE_LOGGING_LAYER(layer)
#define ENABLE_LOGGING_LAYER(layer)
#define GET_LOGGING_LAYER(layer)
#define DISABLE_LOGGING_LEVEL(level)
#define ENABLE_LOGGING_LEVEL(level)
#define GET_LOGGING_LEVEL(level)
/// @endcond
#endif
/// @cond hidden
#ifdef _OCPDEBUG_WIN32
#define DEBUG_PRINT(msg) printf("%s",msg);
#else
#define DEBUG_PRINT(msg)
#endif
/// @endcond
///Define ENABLE_LOG and ENABLE_HANDSHAKETYPE to enable Handshake layer logging.
///ENABLE_LOG enable logs at top level and logging will not wok if not defined.
#if !defined ENABLE_HANDSHAKETYPE || !defined ENABLE_LOG
/// @cond hidden
#define LOG_HANDSHAKEMSG(msg,level) DEBUG_PRINT("HANDSHAKETYPE Undefined\n")
#define LOG_HANDSHAKEDBVAL(val,level) DEBUG_PRINT("HANDSHAKETYPE Undefined\n")
/// @endcond
#else
///Log Handshake Message
#define LOG_HANDSHAKEMSG(msg,level) \
{ \
if(eEnable==Util_GetLogLayerState(eHS)) \
Util_LogMessage(msg,eHS,level); \
else{DEBUG_PRINT("Handshake Layer Disabled\n");} \
}
///Logs Handshake layer 4 byte debug value
#define LOG_HANDSHAKEDBVAL(val,level) \
{ \
if(eEnable==Util_GetLogLayerState(eHS)) \
Util_LogDebugVal(val,eHS,level); \
else{DEBUG_PRINT("Handshake Layer Disabled\n");} \
}
#endif
///Define ENABLE_LOG and ENABLE_RECORDLAYERTYPE to enable Record layer logging.
///ENABLE_LOG enable logs at top level and logging will not wok if not defined.
#if !defined ENABLE_RECORDLAYERTYPE || !defined ENABLE_LOG
/// @cond hidden
#define LOG_RECORDLAYERMSG(msg,level) DEBUG_PRINT("RECORDLAYERTYPE Undefined\n")
#define LOG_RECORDLAYERDBVAL(val,level) DEBUG_PRINT("RECORDLAYERTYPE Undefined\n")
/// @endcond
#else
///Log Record Header Message
#define LOG_RECORDLAYERMSG(msg,level) \
{ \
if(eEnable==Util_GetLogLayerState(eRL)) \
Util_LogMessage(msg,eRL,level); \
else{DEBUG_PRINT("Record Layer Disabled\n");} \
}
///Logs record layer 4 byte debug value
#define LOG_RECORDLAYERDBVAL(val,level) \
{ \
if(eEnable==Util_GetLogLayerState(eRL)) \
Util_LogDebugVal(val,eRL,level); \
else{DEBUG_PRINT("Record Layer Disabled\n");} \
}
#endif
///Define ENABLE_LOG and ENABLE_TRANSPORTTYPE to enable Transport Layer logging.
///ENABLE_LOG enable logs at top level and logging will not wok if not defined.
#if !defined ENABLE_TRANSPORTTYPE || !defined ENABLE_LOG
/// @cond hidden
#define LOG_TRANSPORTMSG(msg,level) DEBUG_PRINT("TRANSPORTTYPE Undefined\n")
#define LOG_TRANSPORTDBVAL(val,level) DEBUG_PRINT("TRANSPORTTYPE Undefined\n")
#define LOG_TRANSPORTDBARY(Msg, buffer, wLen, level) DEBUG_PRINT("TRANSPORTTYPE Undefined\n")
/// @endcond
#else
///Log Transport layer Message
#define LOG_TRANSPORTMSG(msg,level) \
{ \
if(eEnable==Util_GetLogLayerState(eTL)) \
Util_LogMessage(msg,eTL,level); \
else{DEBUG_PRINT("Transport Layer Disabled\n");} \
}
///Logs Transport layer 4 byte debug value
#define LOG_TRANSPORTDBVAL(val,level) \
{ \
if(eEnable==Util_GetLogLayerState(eTL)) \
Util_LogDebugVal(val,eTL,level); \
else{DEBUG_PRINT("Transport Layer Disabled\n");} \
}
///Logs Transport layer Array value
#define LOG_TRANSPORTDBARY(Msg, buffer, wLen, level) \
{ \
if(eEnable==Util_GetLogLayerState(eTL)) \
Util_LogMsgArray(Msg, buffer, wLen, eTL, level); \
else{DEBUG_PRINT("Transport Layer Disabled\n");} \
}
#endif
#ifdef ENABLE_LOG
///Enable the logger handle
#define LOG_SETWRITER(writer,hdl) Util_SetLogWriter((pFWriteData2)writer,hdl);
#else
/// @cond hidden
#define LOG_SETWRITER(writer,hdl) DEBUG_PRINT("Logger is Disabled\n")
/// @endcond
#endif
#endif //__LOGGER_H__
/**
* @}
*/

View File

@@ -0,0 +1,53 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines the memory management related macros.
*
*
* \addtogroup grMutualAuth
*
*/
#ifndef _MEMMGMT_H_
#define _MEMMGMT_H_
///Malloc function to allocate the heap memory
#define OCP_MALLOC(size) malloc(size)
///Malloc function to allocate the heap memory
#define OCP_CALLOC(block,blocksize) calloc(block,blocksize)
///To free the allocated memory
#define OCP_FREE(node) free(node)
///To copy the data from source to destination
#define OCP_MEMCPY(dst,src,size) memcpy(dst,src,size)
///To copy the data from source to destination
#define OCP_MEMSET(src,val,size) memset(src,val,size)
#endif /* _MEMMGMT_H_ */

View File

@@ -0,0 +1,153 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file contains utility functions
*
*
*
*/
#ifndef _UTIL_H_
#define _UTIL_H_
#include "optiga/common/Datatypes.h"
///Greater than
#define GREATER_THAN 0x00000001
///Lesser than
#define LESSER_THAN 0x00000002
///Equal
#define EQUAL 0x00000000
/// Default Low bound value value
#define DEFAULT_LOWBOUND_DOUBLEWORD 0x00000000
/// Mask double word value
#define MASK_DOUBLE_WORD 0xFFFFFFFF
///Word bit size
#define WORD_SIZE 32
///Successful Execution
#define UTIL_SUCCESS 0x00000000
///Execution Failure
#define UTIL_ERROR 0xFFFFFFFF
///Least significant bit set to high
#define LEAST_SIGNIFICANT_BIT_HIGH 0x00000001
///Least significant bit set to high
#define MOST_SIGNIFICANT_BIT_HIGH 0x80000000
/**
* \brief structure to store the record sequence number
*/
typedef struct sUint64
{
///Higher 32 bit of the record sequence number
uint32_t dwHigherByte;
///Lower 32 bit of the record sequence number
uint32_t dwLowerByte;
}sUint64;
/**
* \brief The function compares two uint64 data type.<br>
*/
int32_t CompareUint64(const sUint64 *PpsSrc1, const sUint64 *PpsSrc2);
/**
* \brief Calculates the difference between the two uint64 data.<br>
*/
int32_t SubtractUint64(const sUint64 *PpsMinuend, const sUint64 *PpsSubtrahend,sUint64 *PpsDifference);
/**
* \brief Adds two uint64 data.<br>
*/
int32_t AddUint64(const sUint64 *PpsSrc1, const sUint64 *PpsSrc2,sUint64 *PpsDest);
/**
* \brief Increments uint64 data.<br>
*/
int32_t IncrementUint64(sUint64 *PpsSrc1);
/**
* \brief Converts byte array to uint64.<br>
*/
int32_t GetUint64(sUint64 *PpsOut,const uint8_t* pbVal,uint16_t wLen);
/**
* \brief To Slide the window by shift count.<br>
*/
int32_t ShiftLeftUint64(sUint64 *PpsWindow, sUint64 PsShiftCount, uint8_t PWindowSize, uint8_t PbMaxWindowSize);
/**
* \brief To set a bit in the sUnit64 data.<br>
*/
int32_t Utility_SetBitUint64(sUint64* PprgbData, uint8_t bWindowSize, uint8_t bBitPosition);
/**
* \brief Prepares uint16 [Big endian] type value from the buffer.<br>
*/
uint16_t Utility_GetUint16 (const uint8_t* PprgbData);
/**
* \brief Prepares uint32 [Big endian] type value from the buffer .<br>
*/
uint32_t Utility_GetUint32 (const uint8_t* PprgbData);
/**
* \brief Copies 2 bytes of uint16 type value to the buffer<br>
*/
void Utility_SetUint16 (puint8_t PprgbData,uint16_t PwValue);
/**
* \brief Prepares uint24 [Big endian] type value from the buffer .<br>
*/
uint32_t Utility_GetUint24 (const uint8_t* PprgbData);
/**
* \brief Copies LSB 3 bytes of uint32 [Big endian] type value to the buffer and store.<br>
*/
void Utility_SetUint24 (uint8_t* PprgbData,uint32_t Pdwvalue);
/**
* \brief Copies LSB 4 bytes of uint32 [Big endian] type value to the buffer and store.<br>
*/
void Utility_SetUint32 (uint8_t* PprgbData,uint32_t Pdwvalue);
/**
* \brief Copies the data from source buffer to destination buffer.<br>
*/
void Utility_Memmove(puint8_t PprgbDestBuf, const puint8_t PprgbSrcBuf, uint16_t PwLength);
#endif //_UTIL_H_

View File

@@ -0,0 +1,104 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file implements optiga comms abstraction layer for IFX I2C Protocol.
*
* \addtogroup grOptigaComms
* @{
*/
#ifndef _OPTIGA_COMMS_H_
#define _OPTIGA_COMMS_H_
/**********************************************************************************************************************
* HEADER FILES
*********************************************************************************************************************/
#include "optiga/common/Datatypes.h"
/**********************************************************************************************************************
* MACROS
*********************************************************************************************************************/
/// Succesfull execution
#define OPTIGA_COMMS_SUCCESS 0x0000
/// Error in execution
#define OPTIGA_COMMS_ERROR 0x0001
/// Busy, doing operation
#define OPTIGA_COMMS_BUSY 0x0002
/**********************************************************************************************************************
* DATA STRUCTURES
*********************************************************************************************************************/
/** @brief optiga comms structure */
typedef struct optiga_comms
{
/// Comms structure pointer
void* comms_ctx;
/// Upper layer contect
void* upper_layer_ctx;
/// Upper layer handler
app_event_handler_t upper_layer_handler;
/// Optiga comms state
uint8_t state;
}optiga_comms_t;
extern optiga_comms_t optiga_comms;
/**********************************************************************************************************************
* API Prototypes
*********************************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Opens the communication channel with OPTIGA.
*/
LIBRARY_EXPORTS host_lib_status_t optiga_comms_open(optiga_comms_t *p_ctx);
/**
* \brief Resets the OPTIGA.
*/
LIBRARY_EXPORTS host_lib_status_t optiga_comms_reset(optiga_comms_t *p_ctx,uint8_t reset_type);
/**
* \brief Sends and receives the APDU.
*/
LIBRARY_EXPORTS host_lib_status_t optiga_comms_transceive(optiga_comms_t *p_ctx,const uint8_t* p_data,
const uint16_t* p_data_length,
uint8_t* p_buffer, uint16_t* p_buffer_len);
/**
* \brief Closes the communication channel with OPTIGA.
*/
LIBRARY_EXPORTS host_lib_status_t optiga_comms_close(optiga_comms_t *p_ctx);
/**
* @}
*/
#endif /*_OPTIGA_COMMS_H_*/

View File

@@ -0,0 +1,88 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file AlertProtocol.h
*
* \brief This file defines APIs, types and data structures used in the
* (D)TLS Alert implementation.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef __ALERT_H__
#define __ALERT_H__
#include "optiga/dtls/OcpCommon.h"
#include "optiga/dtls/OcpCommonIncludes.h"
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
/****************************************************************************
*
* API Error Codes
*
****************************************************************************/
/// Successful execution
#define OCP_AL_OK 0x74281527
/// Failure in execution
#define OCP_AL_ERROR 0xFC468021
///Null Parameter(s)
#define OCP_AL_NULL_PARAM BASE_ERROR_ALERT
///Length of input is zero
#define OCP_AL_LENZERO_ERROR (BASE_ERROR_ALERT + 1)
///Fatal error
#define OCP_AL_FATAL_ERROR (BASE_ERROR_ALERT + 2)
///Warning error
#define OCP_AL_WARNING_ERROR (BASE_ERROR_ALERT + 3)
/**
* \brief Process the Alert Messages.
*/
int32_t Alert_ProcessMsg(const sbBlob_d* PpsAlertMsg,int32_t* Ppi4ErrorCode);
/**
* \brief Sends Alert based on the internal error code via the Record Layer.
*/
void Alert_Send(sConfigRL_d *PpsConfigRL,int32_t Pi4ErrorCode);
///Macro to Send Alert
#ifndef DISABLE_ALERT
#define SEND_ALERT(RLHdl,error) Alert_Send(RLHdl,error);
#else
#define SEND_ALERT(RLHdl,error)
#endif
#endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH */
#endif //__ALERT_H__
/**
* @}
*/

View File

@@ -0,0 +1,93 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines the error code layering.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef _BASEERRORCODE_H_
#define _BASEERRORCODE_H_
/*
The following defines the Error code layering for a 4 byte error code.
Each byte is represented as XX, where X being a single nibble.
|8X|XX|XX|XX|
| | | |---->Error Codes
| | |------->Layer
| |---------->Unused
|------------->80
*/
/// Base Error Code
#define ERROR_CODE_BASE 0x80000000
///Base Error code for Comms
#define BASE_ERROR_COMMS (ERROR_CODE_BASE | 0x00000000)
///Base Error code for Command Lib
#define BASE_ERROR_CMDLIB (ERROR_CODE_BASE | 0x00000100)
///Base Error code for Integration Lib
#define BASE_ERROR_INTLIB (ERROR_CODE_BASE | 0x00000200)
///Base Error code for Crypto Lib
#define BASE_ERROR_CRYPTOLIB (ERROR_CODE_BASE | 0x00000300)
///Base Error code for Alert
#define BASE_ERROR_ALERT (ERROR_CODE_BASE | 0x00000500)
///Base Error code for Handshake Layer
#define BASE_ERROR_HANDSHAKELAYER (ERROR_CODE_BASE | 0x00000600)
///Base Error code for Transport Layer
#define BASE_ERROR_TRANSPORTLAYER (ERROR_CODE_BASE | 0x00000700)
///Base Error code for OCP
#define BASE_ERROR_OCPLAYER (ERROR_CODE_BASE | 0x00000800)
///Base Error code for Record Layer
#define BASE_ERROR_RECORDLAYER (ERROR_CODE_BASE | 0x00000900)
///Base Error code for Windowing
#define BASE_ERROR_WINDOW (ERROR_CODE_BASE | 0x00000A00)
///Base Error code for Message Layer
#define BASE_ERROR_MESSAGELAYER (ERROR_CODE_BASE | 0x00000B00)
///Base Error code for Flight Handler
#define BASE_ERROR_FLIGHT (ERROR_CODE_BASE | 0x00000C00)
///Base Error code for Crypto Layer
#define BASE_ERROR_CRYPTO_LAYER (ERROR_CODE_BASE | 0x00000D00)
///Base Error code UDP
#define BASE_ERROR_UDP (ERROR_CODE_BASE | 0x00000E00)
#endif //_BASEERRORCODE_H_
/**
* @}
*/

View File

@@ -0,0 +1,199 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file DtlsFlighthandler.h
*
* \brief This file defines APIs, types and data structures used in the
* DTLS Flight handlers implementation.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef __DTLSFH_H__
#define __DTLSFH_H__
#include "optiga/dtls/MessageLayer.h"
#include "optiga/dtls/DtlsHandshakeProtocol.h"
#include "optiga/dtls/AlertProtocol.h"
#include "optiga/optiga_dtls.h"
#include "optiga/dtls/DtlsRecordLayer.h"
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
/// @cond hidden
#define DEV_ERROR_CODE_MASK 0xFFFFFF00
#define DEV_ERROR_LSBCODE_MASK 0xFF
/// @endcond
/****************************************************************************
*
* API Error Codes
*
****************************************************************************/
/// Successful execution
#define OCP_FL_OK 0x7569412
/// Failure in execution
#define OCP_FL_ERROR 0xF4358417
///Null Parameter(s)
#define OCP_FL_NULL_PARAM BASE_ERROR_FLIGHT
///Flight not listed
#define OCP_FL_NOT_LISTED (OCP_FL_NULL_PARAM + 1)
///State of Flight is old
#define OCP_FL_STATE_OLD (OCP_FL_NULL_PARAM + 2)
///Message with invalid sequence number
#define OCP_FL_INVALID_MSG_SEQNUM (OCP_FL_NULL_PARAM + 3)
///Message doesn't belong to a flight
#define OCP_FL_MSG_NOT_IN_FLIGHT (OCP_FL_NULL_PARAM + 4)
///Message sequence number is not in expected sequence
#define OCP_FL_MSG_OPT_MSG_ERROR (OCP_FL_NULL_PARAM + 5)
///Message received again
#define OCP_MSG_RXAGAIN (OCP_FL_NULL_PARAM + 6)
///Flight messages being received
#define OCP_FL_RXING (OCP_FL_NULL_PARAM + 7)
///Flight processing is past the current flight
#define OCP_FL_DONE (OCP_FL_NULL_PARAM + 8)
///Node for a message is not available in the list
#define OCP_FL_MSG_NODE_NOT_AVAIL (OCP_FL_NULL_PARAM + 9)
///Node for a message is available in the list
#define OCP_FL_MSG_NODE_AVAIL (OCP_FL_NULL_PARAM + 10)
///Message is completely received
#define OCP_FL_MSG_RECEIVED (OCP_FL_NULL_PARAM + 11)
///Message completion check error
#define OCP_FL_MSG_ERROR (OCP_FL_NULL_PARAM + 12)
///Malloc failure
#define OCP_FL_MALLOC_FAILURE (OCP_FL_NULL_PARAM + 13)
///Message sending to Security chip failed
#define OCP_FL_SEND_MSG_TO_OPTIGA_ERROR (OCP_FL_NULL_PARAM + 14)
///Sending message to server failed
#define OCP_FL_FLIGHTSEND_ERROR (OCP_FL_NULL_PARAM + 15)
///Getting a message from Security chip failed
#define OCP_FL_GET_MSG_FROM_OPTIGA_ERROR (OCP_FL_NULL_PARAM + 16)
///Message Incomplete error
#define OCP_FL_MSG_INCOMPLETE (OCP_FL_NULL_PARAM + 17)
///Message with invalid length
#define OCP_FL_INVALID_MSG_LENGTH (OCP_FL_NULL_PARAM + 18)
///Message received is more than max count
#define OCP_FL_MSG_MAXCOUNT (OCP_FL_NULL_PARAM + 19)
///Message with invalid sequence
#define OCP_FL_INVALID_MSG_SEQ (OCP_FL_NULL_PARAM + 20)
///Message with invalid LENGTH
#define OCP_FL_INVALID_PROCFLIGHT (OCP_FL_NULL_PARAM + 21)
///Message with invalid message type
#define OCP_FL_MSG_NOT_LISTED (OCP_FL_NULL_PARAM + 22)
///Message to be ignored
#define OCP_FL_MSG_IGNORE (OCP_FL_NULL_PARAM + 23)
///Internal Error
#define OCP_FL_INT_ERROR (OCP_FL_NULL_PARAM + 24)
///Invalid Handshake Error
#define OCP_FL_HS_ERROR (OCP_FL_NULL_PARAM + 25)
/**
* \brief Checks whether the received message belongs to the expected flight.<br>
*/
int32_t DtlsHS_MsgCheck(uint8_t PbLastProcFlight, const sbBlob_d* PpsBlobMessage, const sMsgLyr_d* PpsMessageLayer);
/**
* \brief Initializes flight node.
*/
int32_t DtlsHS_FlightNodeInit(sFlightDetails_d* PpsFlightNode, uint8_t PbLastProcFlight);
/**
* \brief Gets the Flight type for the corresponding message type.<br>
*/
int32_t DtlsHS_GetFlightID(uint8_t PbMsgType, uint8_t* PpFlightID);
/**
* \brief Searches the look-up table and returns the message descriptors of a flight.<br>
*/
void DtlsHS_GetFlightMsgInfo(uint8_t PeFlightID, uint16_t** PpwMessageList);
/**
* \brief Validates the sequence number of message/ fragment received of flight 2.<br>
*/
int32_t DtlsHS_Flight2CheckMsgSeqNum(uint8_t PbRxMsgID, uint16_t PwRxMsgSeqNum, const sMsgInfo_d *PpsMessageList);
/**
* \brief Flight one handler to process flight 1 messages.
*/
int32_t DtlsHS_Flight1Handler(uint8_t PbLastProcFlight, sFlightStats_d* PpThisFlight, sMsgLyr_d* PpsMessageLayer);
/**
* \brief Flight two handler to process flight 2 messages.
*/
int32_t DtlsHS_Flight2Handler(uint8_t PbLastProcFlight, sFlightStats_d* PpThisFlight, sMsgLyr_d* PpsMessageLayer);
/**
* \brief Flight three handler to process flight 3 messages.
*/
int32_t DtlsHS_Flight3Handler(uint8_t PbLastProcFlight, sFlightStats_d* PpThisFlight, sMsgLyr_d* PpsMessageLayer);
/**
* \brief Flight four handler to process flight 4 messages.
*/
int32_t DtlsHS_Flight4Handler(uint8_t PbLastProcFlight, sFlightStats_d* PpThisFlight, sMsgLyr_d* PpsMessageLayer);
/**
* \brief Flight five handler to process flight 5 messages.
*/
int32_t DtlsHS_Flight5Handler(uint8_t PbLastProcFlight, sFlightStats_d* PpThisFlight, sMsgLyr_d* PpsMessageLayer);
/**
* \brief Flight six handler to process flight 6 messages.
*/
int32_t DtlsHS_Flight6Handler(uint8_t PbLastProcFlight, sFlightStats_d* PpThisFlight, sMsgLyr_d* PpsMessageLayer);
#endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH*/
#endif //__DTLSFH_H__
/**
* @}
*/

View File

@@ -0,0 +1,364 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines APIs, types and data structures used in the
* DTLS Handshake protocol.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef __DTLSHS_H__
#define __DTLSHS_H__
#include "optiga/common/Util.h"
#include "optiga/dtls/OcpCommon.h"
#include "optiga/dtls/MessageLayer.h"
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
/****************************************************************************
*
* API Error Codes
*
****************************************************************************/
///Invalid Fragment size
#define OCP_HL_INVALID_FRAGMENT_SIZE (BASE_ERROR_HANDSHAKELAYER + 2)
///Invalid Current offset
#define OCP_HL_INVALID_OFFSET_LEN (BASE_ERROR_HANDSHAKELAYER + 3)
///Insufficient memory
#define OCP_HL_INSUFFICIENT_MEMORY (BASE_ERROR_HANDSHAKELAYER + 4)
///Invalid Length
#define OCP_HL_INVALID_LENGTH (BASE_ERROR_HANDSHAKELAYER + 5)
///Fragment Length mismatch
#define OCP_HL_LEN_MISMATCH (BASE_ERROR_HANDSHAKELAYER + 6)
///Total Length mismatch
#define OCP_HL_TOTALLEN_MISMATCH (BASE_ERROR_HANDSHAKELAYER + 7)
///Invalid message type
#define OCP_HL_INVALID_MSGTYPE (BASE_ERROR_HANDSHAKELAYER + 8)
///Previous flight message received
#define OCP_HL_RETRANSMISSION (BASE_ERROR_HANDSHAKELAYER + 9)
///Future flight message received
#define OCP_HL_CONTINUE (BASE_ERROR_HANDSHAKELAYER + 10)
///Future flight message received
#define OCP_HL_TIMEOUT (BASE_ERROR_HANDSHAKELAYER + 11)
///Malloc failure
#define OCP_HL_MALLOC_FAILURE (BASE_ERROR_HANDSHAKELAYER + 12)
///Ignore the Record
#define OCP_HL_IGNORE_RECORD (BASE_ERROR_HANDSHAKELAYER + 13)
///Buffer overflow
#define OCP_HL_BUFFER_OVERFLOW (BASE_ERROR_HANDSHAKELAYER + 14)
///Invalid sequence
#define OCP_HL_INVALID_SEQUENCE (BASE_ERROR_HANDSHAKELAYER + 15)
///Invalid Hello request message
#define OCP_HL_INVALID_HRMSG (BASE_ERROR_HANDSHAKELAYER + 16)
/****************************************************************************
*
* Common data structure used across all functions.
*
****************************************************************************/
///Maximum value of message type
#define MAX_MSG_TYPE_VALUE 20
/**
* \brief Structure to hold fragmentation data
*/
typedef struct sFragmentMsg_d
{
///Complete Message
sbBlob_d* psCompleteMsg;
///Fragment Size
uint16_t wFragmentSize;
///Message fragment
sbBlob_d* psMsgFrag;
///Current offset in complete message
uint16_t wCurrentOffset;
///Remaining length to be fragmented
uint16_t wRemainingLen;
}sFragmentMsg_d;
/**
* \brief Structure to hold header information
*/
typedef struct sMsgHeader_d
{
///Specifies message type
uint8_t bMsgType;
///Total length of the handshake message
uint32_t dwTotalLength;
///Message sequence
uint16_t wMsgSequence;
///Specifies the offset of fragment data in actual message
uint32_t dwFragmentOffset;
///Message fragment
uint32_t dwFragmentLength;
///Flight to which the message belongs
eFlight_d eFlight;
///Indicate memory is already Allocated
bool_t fMemoryAllocated;
}sMsgHeader_d;
/**
* \brief Status of Message in the buffer
*/
typedef enum eMsgState_d
{
///Message is partial
ePartial = 0x01,
///Message is complete
eComplete = 0x02,
//Message is processed/returned
eProcessed = 0x03,
//Message receiving again
eReReceiving = 0x04
}eMsgState_d;
/**
* \brief Enum values for server message type
*/
typedef enum eServerMessage_d
{
//Server Side Message type
///Server Hello message
eServer_Hello = 2,
///Hello Verify Request
eHello_Verify_Request = 3,
///Server request message
eServer_Certificate = 11,
///Server key Exchange
eServer_Key_Exchange = 12,
///Certificate request message
eServer_Certificate_Request = 13,
///Server hello done message
eServer_Hello_Done = 14,
///Server finished message
eServer_Finished = 20
}eServerMessage_d;
/**
* \brief This structure maps message type to the flight number
*/
typedef struct sFlightMapTable_d
{
///Message type
uint8_t bMsgType;
///Flight number
eFlight_d FlightNum;
}sFlightMapTable_d;
/// MAcro to update the flight or message state
#define UPDATE_FSTATE(X,Y) (X=Y)
/**
* \brief Structure to hold message fragment in buffer
*/
typedef struct sMsg_d
{
///Message type
uint8_t bMsgType;
///Message sequence
uint16_t wMsgSequence;
///Complete Message Holder
uint8_t* psMsgHolder;
//Message Length
uint32_t dwMsgLength;
//Fragments info
uint8_t* psMsgMapPtr;
///State of the Message
eMsgState_d eMsgState;
///Max Msg reception count
uint8_t bMsgCount;
///Pointer to next message
struct sMsg_d* psNext;
}sMsgInfo_d;
/**
* \brief Flight States
*/
typedef enum eFlightState_d
{
///Initialize state where flight node is created
efInit = 0,
///State where message will be receiving or sent to/from Host
efReady,
///State where flight is completely received and buffered
efReceived,
///State where flight is received again
efReReceive,
///Message is processed by security chip
efProcessed,
///Message is formed by security chip and sent out
efTransmitted,
///Message is retransmitted
efReTransmit,
///Completion of flight handling
efDone
}eFlightState_d;
/**
* \brief Enum values for message type in the flight
*/
typedef enum eOptionalFlag_d
{
///Mandatory message in the flight
eMandatory = 0,
///Optional message in the flight
eOptional = 1,
}eOptionalFlag_d;
/**
* \brief Structure to hold the Flight status
*/
typedef struct sFlightStats_d
{
///Current Flight state
uint8_t bFlightState;
///Pointer to structure #sMsgInfo_d
sMsgInfo_d *psMessageList;
}sFlightStats_d;
/**
* \brief Structure to hold the information required for Message Layer.
*/
typedef struct sMsgLyr_d
{
///Optional Message List
uint8_t rgbOptMsgList[5];
///(D)TLS Session ID
uint16_t wSessionID;
///Maximum PMTU
uint16_t wMaxPmtu;
///Receive Message Sequence Number
uint32_t dwRMsgSeqNum;
///Record Layer
sConfigRL_d* psConfigRL;
///Certificate Type used for Authentication
uint16_t wOIDDevCertificate;
///Callback function pointer to get unixtime
fGetUnixTime_d pfGetUnixTIme;
///Message/Fragment
sbBlob_d sMsg;
///Message/Fragment from the transport layer
sbBlob_d sTLMsg;
///Flight received
eFlight_d eFlight;
} sMsgLyr_d;
///Macro to check for mandatory message
#define IsMandatory(x) ((x & 0xFF00) ? 0: 1)
///Macro to check for optional message
#define IsOptional(x) ((x & 0xFF00) ? 1: 0)
///Macro to get the Flight number
#define FLIGHTID(x) (x & 0xFF)
/**
* \brief Flight handler function pointer
*/
typedef int32_t (*fFlightHandler)(uint8_t PbLastProcFlight, sFlightStats_d* PpThisFlight, sMsgLyr_d* PpsMessageLayer);
/**
* \brief DTLS Spec reference table
*/
typedef struct sFlightTable_d
{
///Lower byte - Flight ID, Upper byte - eOptional/ eMandatory
uint16_t wFlightDesc;
///Lower byte - Message ID, Upper byte - eOptional/ eMandatory
uint16_t wMsgTypes[6];
/// Flight Handler
fFlightHandler pFlightHndlr;
}sFlightTable_d;
/**
* \brief Structure to hold information of a Flight
*/
typedef struct sFlightDetails_d
{
///Flight Descriptor
uint16_t wFlightDecp;
///Flight handler
fFlightHandler pFlightHndlr;
///Structure containing flight status
sFlightStats_d sFlightStats;
///Pointer to the next flight node
struct sFlightDetails_d* psNext;
}sFlightDetails_d;
///Table to map number of msg in a send flight and its flight handler
extern const sFlightTable_d rgsSFlightInfo[];
///Table to map number of msg in a send flight and its flight handler
extern const sFlightTable_d rgsRFlightInfo[];
/****************************************************************************
*
* Definitions related to (D)TLS commands.
*
****************************************************************************/
/**
* \brief Prepares Handshake message header
*/
int32_t DtlsHS_PrepareMsgHeader(uint8_t* PpbMsgHeader, const sMsgInfo_d *sMsgInfo);
/**
* \brief Performs (D)TLS handshake
*/
int32_t DtlsHS_Handshake(sHandshake_d* PphHandshake);
/**
* \brief Sends a message to the server.
*/
int32_t DtlsHS_FSendMessage(const sMsgInfo_d* PpsMsgPtr, const sMsgLyr_d* PpsMessageLayer);
/**
* \brief Process and validates Handshake message header.<br>
*/
int32_t DtlsHS_ProcHeader(sbBlob_d PsBlobMessage);
#endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH*/
#endif //__DTLSHS_H__
/**
* @}
*/

View File

@@ -0,0 +1,204 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file DtlsRecordLayer.h
*
* \brief This file contains structures and prototypes of record layer functionalities for DTLS.
* \addtogroup grOCP
* @{
*
*/
#ifndef __DTLSRECORDLAYER_H__
#define __DTLSRECORDLAYER_H__
#include "optiga/dtls/DtlsWindowing.h"
#include "optiga/dtls/OcpRecordLayer.h"
#include "optiga/dtls/MessageLayer.h"
#include "optiga/dtls/OcpCommonIncludes.h"
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
///Failure in execution and record already received
#define OCP_RL_WINDOW_IGNORE BASE_ERROR_WINDOW
///Valid record is received and window is updated and moved
#define OCP_RL_WINDOW_UPDATED (BASE_ERROR_WINDOW + 1)
///Valid record is received and window is updated
#define OCP_RL_WINDOW_MOVED (BASE_ERROR_WINDOW + 2)
///Window overflow
#define OCP_RL_SEQUENCE_OVERFLOW (BASE_ERROR_WINDOW + 3)
///Encryption/Decryption enabled flag
#define ENC_DEC_ENABLED 0xB5
///Encryption/Decryption disabled flag
#define ENC_DEC_DISABLED 0x6A
/// @cond hidden
///Record Header offset for Content Type
#define OFFSET_RL_CONTENTTYPE (0)
///Record Header offset for Protocol Version
#define OFFSET_RL_PROT_VERSION (OFFSET_RL_CONTENTTYPE + 1) //1
///Record Header offset for Epoch
#define OFFSET_RL_EPOCH (OFFSET_RL_PROT_VERSION + 2) //3
///Record Header offset Sequence Number
#define OFFSET_RL_SEQUENCE (OFFSET_RL_EPOCH + 2) //5
///Record Header offset for Fragment Length
#define OFFSET_RL_FRAG_LENGTH (OFFSET_RL_SEQUENCE + 6) //11
///Record Header offset for Start of Fragment
#define OFFSET_RL_FRAGMENT (OFFSET_RL_FRAG_LENGTH + 2) //13
///Record Header length
#define LENGTH_RL_HEADER (OFFSET_RL_FRAGMENT)
///Record Header length of sequence number bytes
#define LENGTH_RL_SEQUENCE 6
///Flag to indicate change cipher spec is received
#define CCS_RECORD_RECV 0x01
///Flag to indicate change cipher spec is not received
#define CCS_RECORD_NOTRECV 0x00
/// @endcond
/**
* \brief Structure for Record Layer (D)TLS.
*/
typedef struct sRecordLayer_d
{
///Server epoch Number
uint16_t wServerEpoch;
///Server Sequence Number
sUint64 sServerSeqNumber;
///(D)TLS Version Information
uint16_t wTlsVersionInfo;
///Client epoch Number
uint16_t wClientEpoch;
///Client Next epoch Number
uint16_t wClientNextEpoch;
///Client Sequence Number
sUint64 sClientSeqNumber;
///Client Sequence Number for the next Epoch
sUint64 sClientNextSeqNumber;
///Flag whether record to be encrypted/decrypted while send/recv.
uint8_t bEncDecFlag;
///Pointer to callback to validate record
int32_t (*fEncDecRecord)(const sCL_d*, const sbBlob_d*, sbBlob_d*, uint16_t);
///Argument to be passed to callback, if any
sCL_d* pEncDecArgs;
///Window
sWindow_d* psWindow;
///Window for next epoch
sWindow_d* psNextWindow;
///Session Key OID
uint16_t wSessionKeyOID;
///Indicates if the record received is encrypted or not
uint8_t *pbDec;
///Indicates if the record received is Change cipher spec
uint8_t *pbRecvCCSRecord;
} sRecordLayer_d;
/**
* \brief Structure for Record contents.
*/
typedef struct sRecordData_d
{
///Content Type
uint8_t bContentType;
///Actual message in the record
sbBlob_d *psBlobInOutMsg;
///Information of record
//uint32_t dwRecordInfo;
///Indicates if memory needs to be allocated or not
uint8_t bMemoryAllocated;
}sRecordData_d;
/**
* \brief Structure to hold the information required for Encrypt and Decrypt message call back to encrypt the data.
*/
//typedef struct sCBEncDecMsg_d
//{
// //Length of data to be encrypted/decrypted
// uint16_t wInDataLength;
//
// ///Session Key OID
// uint16_t wSessionKeyOID;
//
//}sCBEncDecMsg_d;
/**
* \brief Structure to hold the information required change the server epoch state.
*/
typedef struct sCBStateTrn_d
{
///Handle to Record layer structure
hdl_t phRLHdl;
}sCBStateTrn_d;
/**
* \brief Initialise DTLS Record Layer.
*/
int32_t DtlsRL_Init(sRL_d* psRL);
/**
* \brief Adds record header and send data over transport layer.
*/
int32_t DtlsRL_Send(sRL_d* psRecordLayer,uint8_t* pbData,uint16_t wDataLen);
/**
* \brief Receives a record over transport layer, performs window check and remove the record header.
*/
int32_t DtlsRL_Recv(sRL_d* psRecordLayer,uint8_t* pbBuffer,uint16_t* pwLen);
/**
* \brief Frees memory held by dtls record layer.
*/
void DtlsRL_Close(sRL_d* psRL);
/**
* \brief Slides the window to highest set sequence number.
*/
void Dtls_SlideWindow(const sRL_d* PpsRecordLayer, eAuthState_d PeAuthState);
#endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH */
#endif //__DTLSRECORDLAYER_H__
/**
* @}
*/

View File

@@ -0,0 +1,79 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines APIs, types and data structures used in the
* DTLS Transport Layer.
*
* \addtogroup grOCP
* @{
*/
#ifndef __DTLSTL_H__
#define __DTLSTL_H__
#include "optiga/pal/pal_socket.h"
#include "optiga/dtls/OcpTransportLayer.h"
#include "optiga/dtls/OcpCommonIncludes.h"
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
/**
* \brief This function initializes transport layer communication structure.
*/
int32_t DtlsTL_Init(sTL_d* PpsTL);
/**
* \brief This function creates client port.
*/
int32_t DtlsTL_Connect(sTL_d* PpsTL);
/**
* \brief This function transmits the data to the server from which the data
* was received.
*/
int32_t DtlsTL_Send(const sTL_d* PpsTL,uint8_t* PpbBuffer,uint16_t PwLen);
/**
* \brief This function receives the data from the server.
*/
int32_t DtlsTL_Recv(const sTL_d* PpsTL,uint8_t* PpbBuffer,uint16_t* PpwLen);
/**
* \brief This function closes the UDP communication and releases all the resources.
*/
void DtlsTL_Disconnect(sTL_d* PpsTL);
#endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH */
#endif //__DTLSTL_H__
/**
* @}
*/

View File

@@ -0,0 +1,85 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file implements the APIs, types and data structures used in the
* for DTLS Windowing.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef _H_DTLS_WINDOWING_H_
#define _H_DTLS_WINDOWING_H_
#include <stdint.h>
#include "optiga/common/Util.h"
#include "optiga/dtls/OcpCommonIncludes.h"
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
/**
* \brief Structure for DTLS Windowing.
*/
typedef struct sWindow_d
{
///Sequence number
sUint64 sRecvSeqNumber;
///Higher Bound of window
sUint64 sHigherBound;
///Lower bound of window
sUint64 sLowerBound;
///Size of window, value valid through 32 to 64
uint8_t bWindowSize;
///Window Frame
sUint64 sWindowFrame;
///Pointer to callback to validate record
int32_t (*fValidateRecord)(const void*);
///Argument to be passed to callback, if any
void* pValidateArgs;
}sWindow_d;
/**
* \brief Structure for Sliding Windowing.
*/
typedef struct sSlideWindow_d
{
///Sequence number
sUint64 sClientSeqNumber;
///Pointer to DTLS windowing structure
sWindow_d* psWindow;
}sSlideWindow_d;
/**
* \brief Performs record replay detection and rejects the duplicated records.
*/
int32_t DtlsCheckReplay(sWindow_d *PpsWindow);
#endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH*/
#endif //_H_DTLS_WINDOWING_H_
/**
* @}
*/

View File

@@ -0,0 +1,75 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file HardwareCrypto.h
*
* \brief This file contains structures and prototypes of hardware crypto layer.
* \addtogroup grMutualAuth
* @{
*
*/
#ifndef __HWCRYPTO_H__
#define __HWCRYPTO_H__
#include "optiga/dtls/OcpCryptoLayer.h"
#include "optiga/common/MemoryMgmt.h"
/**
* \brief Structure for Hardware Crypto.
*/
typedef struct sHardwareCrypto_d
{
/// Session OID
uint16_t wSessionKeyOID;
}sHardwareCrypto_d;
/**
* \brief Initialises the Hardware Crypto Layer.
*/
int32_t HWCL_Init(sCL_d* PpsCL, const void* PpParam);
/**
* \brief Encrypts the input plain text using Security chip.
*/
int32_t HWCL_Encrypt(const sCL_d* PpsCL, const sbBlob_d* PpsBlobPlainText,sbBlob_d* PpsBlobCipherText,uint16_t PwLen);
/**
* \brief Decrypts the input cipher text using Security chip.
*/
int32_t HWCL_Decrypt(const sCL_d* PpsCL,const sbBlob_d* PpsBlobCipherText,sbBlob_d* PpsBlobPlainText,uint16_t PwLen);
/**
* \brief Closes the Crypto layer.
*/
void HWCL_Close(sCL_d* PpsCL);
#endif //__HWCRYPTO_H__
/**
* @}
*/

View File

@@ -0,0 +1,156 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines APIs, types and data structures used in the
* (D)TLS Message Layer implementation.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef __MSGLAYER_H__
#define __MSGLAYER_H__
#include <stdio.h>
#include "optiga/dtls/DtlsHandshakeProtocol.h"
#include "optiga/common/Datatypes.h"
#include "optiga/dtls/OcpCommon.h"
#include "optiga/cmd/CommandLib.h"
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
/****************************************************************************
*
* API Error Codes
*
****************************************************************************/
/// Successful execution
#define OCP_ML_OK 0x75268512
/// Failure in execution
#define OCP_ML_ERROR 0xF4350158
///Null Parameter(s)
#define OCP_ML_NULL_PARAM BASE_ERROR_MESSAGELAYER
///Zero Length input parameter(s)
#define OCP_ML_ZERO_LEN (BASE_ERROR_MESSAGELAYER + 1)
///Insufficient memory
#define OCP_ML_INSUFFICIENT_MEMORY (BASE_ERROR_MESSAGELAYER + 2)
///Invalid unix time
#define OCP_ML_INVALID_UNIXTIME (BASE_ERROR_MESSAGELAYER + 3)
///Invalid certificate type
#define OCP_ML_INVALID_CERTTYPE (BASE_ERROR_MESSAGELAYER + 4)
///Invalid certificate type
#define OCP_ML_MALLOC_FAILURE (BASE_ERROR_MESSAGELAYER + 5)
/****************************************************************************
*
* Definitions related to (D)TLS commands.
*
****************************************************************************/
/// @cond hidden
///Timeout expired
#define OCP_ML_TIMEOUT (OCP_ML_NULL_PARAM + 3)
///Length of Handshake message header
#define MSG_HEADER_LEN 12
///Over head length for command library
#define OVERHEAD_LEN 21 //APDU (4) + Message header len(12) + Tag enconding len(5)
//Macro to validate the time out
#define TIMEELAPSED(bStartTime,bTimeout) (((uint32_t)(pal_os_timer_get_time_in_milliseconds() - bStartTime) < (uint32_t)(bTimeout*1000))?TRUE:FALSE)
/// @endcond
/****************************************************************************
*
* Common data structures used across all functions.
*
****************************************************************************/
/**
* \brief Structure to hold the information required for Get message call back to allocate memory.
*/
typedef struct sCBGetMsg_d
{
///Indicate to allocate memory only for first time
uint8_t bRepeatCall;
///Pointer to the allocated memory where the message is stored
uint8_t* pbActualMsg;
///Size of the allocated memory
uint16_t dwMsgLen;
}sCBGetMsg_d;
/**
* \brief Structure to hold the information required for Message Layer.
*/
typedef struct sMessageLayer_d
{
///(D)TLS Session ID
uint16_t wSessionID;
///Maximum PMTU
uint16_t wMaxPmtu;
///Record Layer
sConfigRL_d* psConfigRL;
///Certificate Type used for Authentication
uint16_t wOIDDevCertificate;
///Callback function pointer to get unixtime
fGetUnixTime_d pfGetUnixTIme;
} sMessageLayer_d;
/**
* \brief Provide Handshake message using Command Library.<br>
*/
int32_t MsgLayer_FormMessage(eMsgType_d eMsgType,const sMessageLayer_d* PpsMessageLayer, sbBlob_d* PpsMessage);
/**
* \brief Process Handshake message using Command Library.<br>
*/
int32_t MsgLayer_ProcessMessage(eMsgType_d eMsgType,const sMessageLayer_d* PpsMessageLayer, sbBlob_d* PpsMessage);
/**
* \brief Encrypt the Data using Command Library.<br>
*/
int32_t MsgLayer_EncryptMessage(const sbBlob_d* PpsBlobPlainMsg, sbBlob_d* PpsBlobCipherMsg, uint16_t PwInDataLen, uint16_t PwSessionKeyOID);
/**
* \brief Decrypt the Data using Command Library.<br>
*/
int32_t MsgLayer_DecryptMessage(const sbBlob_d* PpsBlobCipherMsg, sbBlob_d* PpsBlobPlainMsg, uint16_t PwInDataLen, uint16_t PwSessionKeyOID);
#endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH*/
#endif //__MSGLAYER_H__
/**
* @}
*/

View File

@@ -0,0 +1,178 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines APIs, types and data structures used in the
* OCP configurations.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef __OCPCOMMON_H__
#define __OCPCOMMON_H__
#include "optiga/common/Datatypes.h"
#include "optiga/dtls/OcpRecordLayer.h"
#include "optiga/common/MemoryMgmt.h"
#include "optiga/dtls/OcpCommonIncludes.h"
#include "optiga/pal/pal_os_timer.h"
/// Successful execution
#define OCP_HL_OK 0x75236512
/// Failure in execution
#define OCP_HL_ERROR 0XF3CA3154
///Null Parameter(s)
#define OCP_HL_NULL_PARAM BASE_ERROR_HANDSHAKELAYER
///Length of input is zero
#define OCP_HL_LENZERO_ERROR (BASE_ERROR_HANDSHAKELAYER + 1)
///Maximum PMTU value
#define MAX_PMTU 1500
///Minimum PMTU Value
#define MIN_PMTU 296
///Buffer size to hold the received data
#define TLBUFFER_SIZE 1500
///Overhead length for encrypted message
#define ENCRYPTED_APP_OVERHEAD (UDP_RECORD_OVERHEAD + EXPLICIT_NOUNCE_LENGTH + MAC_LENGTH )
///Macro to get the Maximum length of the Application data which can be sent
#define MAX_APP_DATALEN(PhAppOCPCtx) ((((sAppOCPCtx_d*)PhAppOCPCtx)->sHandshake.wMaxPmtu) - ENCRYPTED_APP_OVERHEAD)
/****************************************************************************
*
* Common data structure used across all functions.
*
****************************************************************************/
///Function pointer to get the unix time
typedef int32_t (*fGetUnixTime_d)(uint32_t*);
/**
* \brief Enumeration to specify the mode of operation of OCP
*/
typedef enum eMode_d
{
///Client
eClient = 0x24,
///Server
eServer = 0x81
}eMode_d;
/**
* \brief Enumeration to specify the Protocol version
*/
typedef enum eProtVersion_d
{
///DTLS 1.2
eDTLS_1_2,
///TLS 1.2
eTLS_1_2
}eProtVersion_d;
/**
* \brief Enum for Mutual Authentication states
*/
typedef enum eAuthState_d
{
//Authentication parameters initialized
eAuthInitialised,
//Authentication started
eAuthStarted,
//Authentication is completed
eAuthCompleted,
//Authentication session is closed
eAuthSessionClosed
}eAuthState_d;
/**
* \brief Structure containing Handshake related data.
*/
typedef struct sHandshake_d
{
///Mode of operation,Client/Server
eMode_d eMode;
///Maximum PMTU
uint16_t wMaxPmtu;
///Pointer to Record Layer
sConfigRL_d* psConfigRL;
///Pointer to Logger
sLogger_d phLogger;
///To indicate fatal alert
bool_t fFatalError;
//Indicates status of Mutual Authentication
eAuthState_d eAuthState;
///Handle to OCP
hdl_t PhAppOCPCtx;
///Session OID
uint16_t wSessionOID;
///Certificate Type used for Authentication
uint16_t wOIDDevCertificate;
///Private key used for authentication
uint16_t wOIDDevPrivKey;
///Callback function pointer to get unixtime
fGetUnixTime_d pfGetUnixTIme;
}sHandshake_d;
/**
* \brief Enum for Flights
*/
typedef enum eFlight_d
{
///Flight 0
eFlight0 = 0,
///Flight 1
eFlight1 = 1,
///Flight 2
eFlight2 = 2,
///Flight 3
eFlight3 = 3,
///Flight 4
eFlight4 = 4,
///Flight 5
eFlight5 = 5,
///Flight 6
eFlight6 = 6,
///Default
eDefault
}eFlight_d;
///Function pointer to perform Handshake
typedef int32_t (*fPerformHandshake_d)(sHandshake_d*);
#endif //__OCPCOMMON_H__
/**
* @}
*/

View File

@@ -0,0 +1,43 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file includes the commonly used header files.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef _COMMONCONFIG_H_
#define _COMMONCONFIG_H_
#include "optiga/common/AuthLibSettings.h"
#include "optiga/dtls/BaseErrorCodes.h"
#include "optiga/Version.h"
#endif //_COMMONCONFIG_H_
/**
* @}
*/

View File

@@ -0,0 +1,114 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines APIs, types and data structures used in the
* OCP Crypto Layer.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef __OCPCRYPTOLAYER_H__
#define __OCPCRYPTOLAYER_H__
#include "optiga/common/Datatypes.h"
#include "optiga/common/Logger.h"
#include "optiga/dtls/OcpCommonIncludes.h"
/****************************************************************************
*
* Common data structure used across all functions.
*
****************************************************************************/
/// Failure in execution
#define OCP_CL_ERROR 0x51667F82
///Successful Execution
#define OCP_CL_OK 0x4C36F247
///Null paramter
#define OCP_CL_NULL_PARAM BASE_ERROR_CRYPTO_LAYER
///Malloc Failure in Crypto
#define OCP_CL_MALLOC_FAILURE (BASE_ERROR_CRYPTO_LAYER + 1)
///Zero Length Failure
#define OCP_CL_ZERO_LEN (BASE_ERROR_CRYPTO_LAYER + 2)
///Insufficient memory
#define OCP_CL_INSUFFICIENT_MEMORY (BASE_ERROR_CRYPTO_LAYER + 3)
/**
* \brief Structure containing Crypto Layer information.
*/
typedef struct sCL_d
{
///Handle to Crypto
hdl_t phCryptoHdl;
//Pointer to Logger
sLogger_d sLogger;
}sCL_d;
///Function pointer to Initialize Record Layer.
typedef int32_t (*fCLInit)(sCL_d* psCL, const void*);
///Function pointer for Record Layer Send
typedef int32_t (*fCLEncrypt)(const sCL_d* psCL, const sbBlob_d* PpsBlobPlainText,sbBlob_d* PpsBlobCipherText,uint16_t wLen);
///Function pointer for Record Layer Receive
typedef int32_t (*fCLDecrypt)(const sCL_d* psCL, const sbBlob_d* PpsBlobCipherText,sbBlob_d* PpsBlobPlainText,uint16_t wLen);
///Function pointer to close Record Layer
typedef void (*fCLClose)(sCL_d* psCL);
/**
* \brief Structure to configure Crypto Layer.
*/
typedef struct sConfigCL_d
{
///Function pointer to Init Crypto layer
fCLInit pfInit;
///Function pointer to Close Crypto layer
fCLClose pfClose;
///Function pointer to Encrypt data via Crypto layer
fCLEncrypt pfEncrypt;
///Function pointer to Decrypt data via Crypto layer
fCLDecrypt pfDecrypt;
///Crypto Handle
sCL_d sCL;
}sConfigCL_d;
#endif //__OCPCRYPTOLAYER_H__
/**
* @}
*/

View File

@@ -0,0 +1,190 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines APIs, types and data structures used in the
* OCP Record Layer.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef __OCPRECORDLAYER_H__
#define __OCPRECORDLAYER_H__
#include "optiga/dtls/OcpTransportLayer.h"
#include "optiga/dtls/OcpCryptoLayer.h"
#include "optiga/common/Logger.h"
/// Failure in execution
#define OCP_RL_ERROR 0x55667F82
/// Internal status for success.
#define OCP_RL_OK 0x297D9015
///Invalid record length
#define OCP_RL_INVALID_RECORD_LENGTH BASE_ERROR_RECORDLAYER
///Invalid record content type
#define OCP_RL_INVALID_CONTENTTYPE (BASE_ERROR_RECORDLAYER + 1)
///Invalid decrypt payload lenght
#define OCP_RL_INVALID_DEC_PAYLOAD_LEN (BASE_ERROR_RECORDLAYER + 2)
///Invalid protocol version
#define OCP_RL_INVALID_PROTOCOL_VERSION (BASE_ERROR_RECORDLAYER + 3)
///Incorrect epoch
#define OCP_RL_INCORRECT_EPOCH (BASE_ERROR_RECORDLAYER + 4)
///Record length mismatch
#define OCP_RL_RECORD_LEN_MISMATCH (BASE_ERROR_RECORDLAYER + 5)
///Bad record
#define OCP_RL_BAD_RECORD (BASE_ERROR_RECORDLAYER + 6)
/// No data
#define OCP_RL_NO_DATA (BASE_ERROR_RECORDLAYER + 7)
/// Data length is greater than PMTU
#define OCP_RL_LEN_GREATER_PMTU (BASE_ERROR_RECORDLAYER + 8)
///Invalid record instance
#define OCP_RL_INVALID_INSTANCE (BASE_ERROR_RECORDLAYER + 9)
///Alert record received
#define OCP_RL_ALERT_RECEIVED (BASE_ERROR_RECORDLAYER + 10)
///Alert record received
#define OCP_RL_APPDATA_RECEIVED (BASE_ERROR_RECORDLAYER + 11)
///Malloc Failure
#define OCP_RL_MALLOC_FAILURE (BASE_ERROR_RECORDLAYER + 12)
///Cipher Spec Content Spec
#define CONTENTTYPE_CIPHER_SPEC 0x14
///Alert Content Spec
#define CONTENTTYPE_ALERT 0x15
///Handshake Content Spec
#define CONTENTTYPE_HANDSHAKE 0x16
///Application Data Content Spec
#define CONTENTTYPE_APP_DATA 0x17
///UDP REcord overhead length
#define UDP_RECORD_OVERHEAD 41 //20(IP Header) + 8(UDP Header) + 13(RL Header)
///Length of the MAC generated for encrypted message
#define MAC_LENGTH 8
///Length of Explicit Nounce
#define EXPLICIT_NOUNCE_LENGTH 8
/****************************************************************************
*
* Common data structure used across all functions.
*
****************************************************************************/
/**
* \brief Structure containing Record Layer information.
*/
typedef struct sRL_d
{
///Handle to Record layer structure sRecordLayer_d
hdl_t phRLHdl;
///Pointer to Configured TL
sConfigTL_d* psConfigTL;
///Pointer to Configured Crypto
sConfigCL_d* psConfigCL;
///Structure that holds logger parameters
sLogger_d sLogger;
///Indicates if memory needs to be allocated or not
uint8_t bMemoryAllocated;
///Content Type
uint8_t bContentType;
///Indicate Multiple record received
uint8_t bMultipleRecord;
///Indicates if the send flight is retransmitted
bool_t fRetransmit;
///Indicates if the record received is encrypted or not
uint8_t bDecRecord;
///Indicates if the record received is Change cipher spec
uint8_t bRecvCCSRecord;
///pointer to a Next record
uint8_t* pNextRecord;
///Pointer to callback to change the server epoch state
Void (*fServerStateTrn)(const void*);
}sRL_d;
///Function pointer to Initialize Record Layer.
typedef int32_t (*fRLInit)(sRL_d* psRL);
///Function pointer for Record Layer Send
typedef int32_t (*fRLSend)(sRL_d* psRL, uint8_t* pbBuffer,uint16_t wLen);
///Function pointer for Record Layer Receive
typedef int32_t (*fRLRecv)(sRL_d* psRL,uint8_t* pbBuffer,uint16_t* pwLen);
///Function pointer to close Record Layer
typedef void (*fRLClose)(sRL_d* psRL);
/**
* \brief Structure to configure Record Layer.
*/
typedef struct sConfigRL_d
{
///Function pointer to Init RL
fRLInit pfInit;
///Function pointer to CloseRL
fRLClose pfClose;
///Function pointer to Send via RL
fRLSend pfSend;
///Function pointer to Receive via RL
fRLRecv pfRecv;
///Record Layer
sRL_d sRL;
}sConfigRL_d;
#endif //__OCPRECORDLAYER_H__
/**
* @}
*/

View File

@@ -0,0 +1,159 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines APIs, types and data structures used in the
* OCP Transport Layer.
*
* \addtogroup grMutualAuth
* @{
*/
#ifndef __OCPTRANSPORTLAYER_H__
#define __OCPTRANSPORTLAYER_H__
#include "optiga/common/Datatypes.h"
#include "optiga/common/Logger.h"
#include "optiga/dtls/OcpCommonIncludes.h"
///General error
#define OCP_TL_ERROR 0xF1267AB3
///Successful execution
#define OCP_TL_OK 0x72309781
///Null Parameter(S)
#define OCP_TL_NULL_PARAM BASE_ERROR_TRANSPORTLAYER
///Null Parameter(S)
#define OCP_TL_BINDING_FAILURE (BASE_ERROR_TRANSPORTLAYER + 1)
///NO Data received
#define OCP_TL_NO_DATA (BASE_ERROR_TRANSPORTLAYER + 2)
///Malloc failure
#define OCP_TL_MALLOC_FAILURE (BASE_ERROR_TRANSPORTLAYER + 3)
/****************************************************************************
*
* Common data structure used across all functions.
*
****************************************************************************/
/**
* \brief Enumeration to represent transport layer communication state
*/
typedef enum eConnectionState_d
{
///Connected to network
eConnected = 0x01,
///Disconnected from network
eDisconnected = 0x02
}eConnectionState_d;
/**
* \brief This structure contains Ethernet communication data
*/
typedef enum eReceiveCall_d
{
///Blocking Ethernet call
eBlocking = 0x10,
///Non Blocking Ethernet call
eNonBlocking = 0x20
}eReceiveCall_d;
/**
* \brief Structure holding Transport Layer Information.
*/
typedef struct sTL_d
{
///Handle to transport layer
hdl_t phTLHdl;
///Port Number
uint16_t wPort;
///IP Address
char_t* pzIpAddress;
///Transport Layer Timeout
uint16_t wTimeout;
///Connection state
eConnectionState_d eIsConnected;
///Call type Blocking or NonBlocking
eReceiveCall_d eCallType;
//Structure that holds logger parameters
sLogger_d sLogger;
}sTL_d;
///Function pointer for Transport Layer Init.
typedef int32_t (*fTLInit)(sTL_d* psTL);
///Function pointer for Transport Layer Connect.
typedef int32_t (*fTLConnect)(sTL_d* psTL);
///Function pointer for Transport Layer Disconnect
typedef void (*fTLDisconnect)(sTL_d* psTL);
///Function pointer for Transport Layer Send
typedef int32_t (*fTLSend)(const sTL_d* psTL,uint8_t* pbBuffer,uint16_t wLen);
///Function pointer for Transport Layer Receive
typedef int32_t (*fTLRecv)(const sTL_d* psTL,uint8_t* pbBuffer,uint16_t* pwLen);
/**
* \brief Structure to configure Transport Layer.
*/
typedef struct sConfigTL_d
{
///Function pointer to Init via TL
fTLInit pfInit;
///Function pointer to Send via TL
fTLSend pfSend;
///Function pointer to Receive via TL
fTLRecv pfRecv;
///Function pointer to Connect to TL
fTLConnect pfConnect;
///Function pointer to Disconnect from TL
fTLDisconnect pfDisconnect;
///Transport Layer
sTL_d sTL;
}sConfigTL_d;
#endif //__OCPTRANSPORTLAYER_H__
/**
* @}
*/

View File

@@ -0,0 +1,67 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file contains a UDP error codes.
*
*
* \addtogroup grMutualAuth
* @{
*
*/
#ifndef _UDPERRCODES_H_
#define _UDPERRCODES_H_
///Failure to allocate memory
#define E_COMMS_UDP_ALLOCATE_FAILURE 0x80000100
///Binding failure to a port
#define E_COMMS_UDP_BINDING_FAILURE 0x80000101
///No data present to send
#define E_COMMS_UDP_NO_DATA_TO_SEND 0x80000102
///No data received from the target
#define E_COMMS_UDP_NO_DATA_RECEIVED 0x80000103
///Failure to route the UDP packet
#define E_COMMS_UDP_ROUTING_FAILURE 0x80000104
///Failure to deallocate the memory
#define E_COMMS_UDP_DEALLOCATION_FAILURE 0x80000105
///Copy to the buffer failure
#define E_COMMS_UDP_COPY_BUFFER_FAILURE 0x80000106
///UDP connect failure
#define E_COMMS_UDP_CONNECT_FAILURE 0x80000107
#endif /* _UDPERRCODES_H_ */
/**
* @}
*/

View File

@@ -0,0 +1,104 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file ifx_i2c.h
*
* \brief This file defines the API prototype for IFX I2C protocol v1.65 wrapper.
*
* \addtogroup grIFXI2C
* @{
*/
#ifndef _IFXI2C_H_
#define _IFXI2C_H_
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************************************************************
* HEADER FILES
**********************************************************************************************************************/
#include "optiga/common/Datatypes.h"
#include "optiga/ifx_i2c/ifx_i2c_config.h"
/***********************************************************************************************************************
* MACROS
***********************************************************************************************************************/
/***********************************************************************************************************************
* ENUMS
***********************************************************************************************************************/
/** @brief IFX I2C Reset types */
typedef enum ifx_i2c_reset_type
{
/// Cold reset. Both reset pin and vdd pin are toggled low and then high
IFX_I2C_COLD_RESET = 0U,
/// Soft reset. 0x0000 is written to IFX-I2C Soft reset register
IFX_I2C_SOFT_RESET = 1U,
/// Warm reset. Only reset pin is toggled low and then high
IFX_I2C_WARM_RESET = 2U
} ifx_i2c_reset_type_t;
/***********************************************************************************************************************
* DATA STRUCTURES
***********************************************************************************************************************/
/***********************************************************************************************************************
* API PROTOTYPES
**********************************************************************************************************************/
/**
* \brief Initializes the IFX I2C protocol stack for a given context.
*/
host_lib_status_t ifx_i2c_open(ifx_i2c_context_t *p_ctx);
/**
* \brief Resets the I2C slave.
*/
host_lib_status_t ifx_i2c_reset(ifx_i2c_context_t *p_ctx, ifx_i2c_reset_type_t reset_type);
/**
* \brief Sends a command and receives a response for the command.
*/
host_lib_status_t ifx_i2c_transceive(ifx_i2c_context_t *p_ctx,const uint8_t* p_data, const uint16_t* p_data_length,
uint8_t* p_buffer, uint16_t* p_buffer_len);
/**
* \brief Closes the IFX I2C protocol stack for a given context.
*/
host_lib_status_t ifx_i2c_close(ifx_i2c_context_t *p_ctx);
/**
* \brief Sets the slave address of the target device.
*/
host_lib_status_t ifx_i2c_set_slave_address(ifx_i2c_context_t *p_ctx, uint8_t slave_address, uint8_t persistent);
#ifdef __cplusplus
}
#endif
#endif /* _IFXI2C_H_ */
/**
* @}
**/

View File

@@ -0,0 +1,312 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file ifx_i2c_config.h
*
* \brief This file defines the structures and macros for the Infineon I2C Protocol.
*
* \addtogroup grIFXI2C
* @{
*/
#ifndef _IFX_I2C_CONFIG_H_
#define _IFX_I2C_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************************************************************
* HEADER FILES
**********************************************************************************************************************/
// Protocol Stack Includes
#include <stdint.h>
#include "optiga/pal/pal_i2c.h"
#include "optiga/pal/pal_gpio.h"
#include "optiga/pal/pal_os_timer.h"
/***********************************************************************************************************************
* MACROS
**********************************************************************************************************************/
/** @brief I2C slave address of the Infineon device */
#define IFX_I2C_BASE_ADDR (0x30)
/** @brief Physical Layer: polling interval in microseconds */
#define PL_POLLING_INVERVAL_US (1000)
/** @brief Physical layer: maximal attempts */
#define PL_POLLING_MAX_CNT (200)
/** @brief Physical Layer: data register polling interval in microseconds */
#define PL_DATA_POLLING_INVERVAL_US (5000)
/** @brief Physical Layer: guard time interval in microseconds */
#define PL_GUARD_TIME_INTERVAL_US (50)
/** @brief Data link layer: maximum frame size */
#ifndef DL_MAX_FRAME_SIZE
#define DL_MAX_FRAME_SIZE (300)
#endif
/** @brief Data link layer: header size */
#define DL_HEADER_SIZE (5)
/** @brief Data link layer: maximum number of retries in case of transmission error */
#define DL_TRANS_REPEAT (3)
/** @brief Data link layer: Trans timeout in milliseconds*/
#define PL_TRANS_TIMEOUT_MS (10)
/** @brief Transport layer: Maximum exit timeout in seconds */
#define TL_MAX_EXIT_TIMEOUT (6)
/** @brief Reset low time for GPIO pin toggling */
#define RESET_LOW_TIME_MSEC (2000)
/** @brief Start up time */
#define STARTUP_TIME_MSEC (12000)
/** @brief Protocol Stack: Status codes for success */
#define IFX_I2C_STACK_SUCCESS (0x00)
/** @brief Protocol Stack: Status codes for error */
#define IFX_I2C_STACK_ERROR (0x01)
/** @brief Protocol Stack: Status codes busy */
#define IFX_I2C_STACK_BUSY (0x02)
/** @brief Protocol Stack: Memory insufficient */
#define IFX_I2C_STACK_MEM_ERROR (0x03)
/** @brief Protocol Stack: Fatal error. Used internal to IFX I2C Stack */
#define IFX_I2C_FATAL_ERROR (0x04)
/** @brief Offset of Datalink header in tx_frame_buffer */
#define IFX_I2C_DL_HEADER_OFFSET (0)
/** @brief Offset of Transport header in tx_frame_buffer */
#define IFX_I2C_TL_HEADER_OFFSET (IFX_I2C_DL_HEADER_OFFSET+3)
/** @brief Protocol Stack debug switch for physical layer (set to 0 or 1) */
#define IFX_I2C_LOG_PL 0
/** @brief Protocol Stack debug switch for data link layer (set to 0 or 1) */
#define IFX_I2C_LOG_DL 0
/** @brief Protocol Stack debug switch for transport layer (set to 0 or 1) */
#define IFX_I2C_LOG_TL 0
/** @brief Log ID number for physical layer */
#define IFX_I2C_LOG_ID_PL 0x00
/** @brief Log ID number for data link layer */
#define IFX_I2C_LOG_ID_DL 0x01
/** @brief Log ID number for transport layer */
#define IFX_I2C_LOG_ID_TL 0x02
/** @brief Log ID number for platform abstraction layer */
#define IFX_I2C_LOG_ID_PAL 0x04
/***********************************************************************************************************************
* ENUMS
***********************************************************************************************************************/
/***********************************************************************************************************************
* DATA STRUCTURES
***********************************************************************************************************************/
struct ifx_i2c_context;
/** @brief Event handler function prototype */
typedef void (*ifx_i2c_event_handler_t)(struct ifx_i2c_context* ctx, host_lib_status_t event, const uint8_t* data, uint16_t data_len);
/** @brief Physical layer structure */
typedef struct ifx_i2c_pl
{
// Physical Layer low level interface variables
/// Physical layer buffer
uint8_t buffer[DL_MAX_FRAME_SIZE+1];
/// Tx length
uint16_t buffer_tx_len;
/// Rx length
uint16_t buffer_rx_len;
/// Action on register, read/write
uint8_t register_action;
/// i2c read/i2c write
uint8_t i2c_cmd;
/// Retry counter
uint16_t retry_counter;
// Physical Layer high level interface variables
/// Action of frame. Tx/Rx
uint8_t frame_action;
/// Frame state
uint8_t frame_state ;
/// Pointer to data to be sent
uint8_t * p_tx_frame;
/// Length of data to be sent
uint16_t tx_frame_len;
// Upper layer handler
ifx_i2c_event_handler_t upper_layer_event_handler;
// Physical Layer negotiation/soft reset variables
/// Negotiation state
uint8_t negotiate_state;
/// Soft reset requested
uint8_t request_soft_reset;
} ifx_i2c_pl_t;
/** @brief Datalink layer structure */
typedef struct ifx_i2c_dl
{
// Data Link layer internal state variables
/// Datalink layer state
uint8_t state;
/// Tx sequence number
uint8_t tx_seq_nr;
// Rx sequence number
uint8_t rx_seq_nr;
/// Indicate only Rx required
uint8_t action_rx_only;
/// Retransmit counter
uint8_t retransmit_counter;
/// Error occured
uint8_t error;
/// Resynced
uint8_t resynced;
/// Timeout value
uint32_t data_poll_timeout;
/// Transmit buffer size
uint16_t tx_buffer_size;
/// Receive buffer size
uint16_t rx_buffer_size;
/// Pointer to main transmit buffers
uint8_t* p_tx_frame_buffer;
/// Pointer to main receive buffers
uint8_t* p_rx_frame_buffer;
///Start time of sending frame
uint32_t frame_start_time;
// Upper layer Event handler
ifx_i2c_event_handler_t upper_layer_event_handler;
} ifx_i2c_dl_t;
/** @brief Transport layer structure */
typedef struct ifx_i2c_tl
{
// Transport Layer state and buffer
/// Transport layer state
uint8_t state;
/// Pointer to packet provided by user
uint8_t* p_actual_packet;
/// Total received data
uint16_t total_recv_length;
/// Actual length of user provided packet
uint16_t actual_packet_length;
/// Offset till which data is sent from p_actual_packet
uint16_t packet_offset;
/// Maximum length of packet at transport layer
uint16_t max_packet_length;
/// Pointer to user provided receive buffer
uint8_t* p_recv_packet_buffer;
/// Length of receive buffer
uint16_t* p_recv_packet_buffer_length;
/// Start time of the transport layer API
uint32_t api_start_time;
///Chaining error coutn from slave
uint8_t chaining_error_count;
///Chaining error count for master
uint8_t master_chaining_error_count;
///State to check last chaining state
uint8_t previous_chaining;
/// transmission done
uint8_t transmission_completed;
/// Error event state
uint8_t error_event;
/// Upper layer event handler
ifx_i2c_event_handler_t upper_layer_event_handler;
} ifx_i2c_tl_t;
/** @brief IFX I2C context structure */
typedef struct ifx_i2c_context
{
/// I2C Slave address
uint8_t slave_address;
/// Frequency of i2c master
uint16_t frequency;
/// Data link layer frame size
uint16_t frame_size;
/// Pointer to pal gpio context for vdd
pal_gpio_t* p_slave_vdd_pin;
/// Pointer to pal gpio context for reset
pal_gpio_t* p_slave_reset_pin;
/// Pointer to pal i2c context
pal_i2c_t* p_pal_i2c_ctx;
/// Upper layer event handler
app_event_handler_t upper_layer_event_handler;
/// Upper layer context
void* p_upper_layer_ctx;
/// Pointer to upper layer rx buffer
uint8_t* p_upper_layer_rx_buffer;
/// Pointer to length of upper layer rx buffer
uint16_t* p_upper_layer_rx_buffer_len;
/// Protocol variables
/// ifx i2c wrapper apis state
uint8_t state;
/// ifx i2c wrapper api status
uint8_t status;
/// reset states
uint8_t reset_state;
/// type of reset
uint8_t reset_type;
/// init pal
uint8_t do_pal_init;
/// Transport layer context
ifx_i2c_tl_t tl;
/// Datalink layer context
ifx_i2c_dl_t dl;
/// Physical layer context
ifx_i2c_pl_t pl;
/// IFX I2C tx frame of max length
uint8_t tx_frame_buffer[DL_MAX_FRAME_SIZE];
/// IFX I2C rx frame of max length
uint8_t rx_frame_buffer[DL_MAX_FRAME_SIZE];
} ifx_i2c_context_t;
/***********************************************************************************************************************
* GLOBAL
***********************************************************************************************************************/
/** @brief IFX I2C Instance */
extern ifx_i2c_context_t ifx_i2c_context_0;
/***********************************************************************************************************************
* LOCAL ROUTINES
***********************************************************************************************************************/
/***********************************************************************************************************************
* API PROTOTYPES
**********************************************************************************************************************/
/**
* @}
**/
#ifdef __cplusplus
}
#endif
#endif /* _IFX_I2C_CONFIG_H_ */

View File

@@ -0,0 +1,117 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file ifx_i2c_data_link_layer.h
*
* \brief This file defines the API prototype for data link layer of the Infineon I2C Protocol Stack library.
*
* \addtogroup grIFXI2C
* @{
*/
#ifndef _IFX_I2C_DATA_LINK_LAYER_H_
#define _IFX_I2C_DATA_LINK_LAYER_H_
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************************************************************
* HEADER FILES
**********************************************************************************************************************/
#include "optiga/ifx_i2c/ifx_i2c_config.h"
/***********************************************************************************************************************
* MACROS
**********************************************************************************************************************/
/** @brief Error event propagated to upper layer */
#define IFX_I2C_DL_EVENT_ERROR (0x01)
/** @brief Transmit success event propagated to upper layer (bit field 1) */
#define IFX_I2C_DL_EVENT_TX_SUCCESS (0x02)
/** @brief Receive success event propagated to upper layer (bit field 3)*/
#define IFX_I2C_DL_EVENT_RX_SUCCESS (0x04)
/***********************************************************************************************************************
* ENUMS
**********************************************************************************************************************/
/***********************************************************************************************************************
* DATA STRUCTURES
***********************************************************************************************************************/
/***********************************************************************************************************************
* API PROTOTYPES
**********************************************************************************************************************/
/**
* @brief Function for initializing the module.
*
* Function initializes and enables the module and registers
* an event handler to receive events from this module.
* @attention This function must be called before using the module.
*
* @param[in,out] p_ctx Pointer to ifx i2c context.
* @param[in] handler Function pointer to the event handler of the upper layer.
*
* @retval IFX_I2C_STACK_SUCCESS If initialization was successful.
* @retval IFX_I2C_STACK_ERROR If the module is already initialized.
*/
host_lib_status_t ifx_i2c_dl_init(ifx_i2c_context_t *p_ctx,ifx_i2c_event_handler_t handler);
/**
* @brief Function for sending a frame.
*
* Asynchronous function to send a frame. The function returns immediately.
* One of the following events is propagated to the event handler registered
* with @ref ifx_i2c_dl_init.
*
* @param[in,out] p_ctx Pointer to ifx i2c context.
* @param[in] frame_len Frame length.
*
* @retval IFX_I2C_STACK_SUCCESS If function was successful.
* @retval IFX_I2C_STACK_ERROR If the module is busy.
*/
host_lib_status_t ifx_i2c_dl_send_frame(ifx_i2c_context_t *p_ctx,uint16_t frame_len);
/**
* @brief Function for receiving a frame.
*
* Asynchronous function to receive a frame. The function returns immediately.
* One of the following events is propagated to the event handler registered
* with @ref ifx_i2c_dl_init.
*
* @param[in,out] p_ctx Pointer to ifx i2c context.
*
* @retval IFX_I2C_STACK_SUCCESS If function was successful.
* @retval IFX_I2C_STACK_ERROR If the module is busy.
*/
host_lib_status_t ifx_i2c_dl_receive_frame(ifx_i2c_context_t *p_ctx);
#ifdef __cplusplus
}
#endif
#endif /* _IFX_I2C_DATA_LINK_LAYER_H_ */
/**
* @}
**/

View File

@@ -0,0 +1,123 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file ifx_i2c_physical_layer.h
*
* \brief This file defines the API prototype for physical layer of the Infineon I2C Protocol Stack library.
*
* \addtogroup grIFXI2C
* @{
*/
#ifndef _IFX_I2C_PHYSICAL_LAYER_H_
#define _IFX_I2C_PHYSICAL_LAYER_H_
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************************************************************
* HEADER FILES
**********************************************************************************************************************/
#include "optiga/ifx_i2c/ifx_i2c_config.h"
/***********************************************************************************************************************
* MACROS
**********************************************************************************************************************/
/***********************************************************************************************************************
* ENUMS
**********************************************************************************************************************/
/***********************************************************************************************************************
* DATA STRUCTURES
***********************************************************************************************************************/
/***********************************************************************************************************************
* API PROTOTYPES
**********************************************************************************************************************/
/**
* @brief Function for initializing the module.
*
* Function initializes and enables the module and registers
* an event handler to receive events from this module.
* @attention This function must be called before using the module.
*
* @param[in,out] p_ctx Pointer to ifx i2c context.
* @param[in] handler Function pointer to the event handler of the upper layer.
*
* @retval IFX_I2C_STACK_SUCCESS If initialization was successful.
* @retval IFX_I2C_STACK_ERROR If the module is already initialized.
*/
host_lib_status_t ifx_i2c_pl_init(ifx_i2c_context_t *p_ctx,ifx_i2c_event_handler_t handler);
/**
* @brief Function for sending a frame.
*
* Asynchronous function to send a frame. The function returns immediately.
* One of the following events is propagated to the event handler registered
* with @ref ifx_i2c_pl_init
*
* @param[in,out] p_ctx Pointer to ifx i2c context.
* @param[in] p_frame Buffer containing the frame.
* @param[in] frame_len Frame length.
*
* @retval IFX_I2C_STACK_SUCCESS If function was successful.
* @retval IFX_I2C_STACK_ERROR If the module is busy.
*/
host_lib_status_t ifx_i2c_pl_send_frame(ifx_i2c_context_t *p_ctx,uint8_t* p_frame, uint16_t frame_len);
/**
* @brief Function for receiving a frame.
*
* Asynchronous function to receive a frame. The function returns immediately.
* One of the following events is propagated to the event handler registered
* with @ref ifx_i2c_pl_init
*
* @param[in] p_ctx Pointer to ifx i2c context.
*
* @retval IFX_I2C_STACK_SUCCESS If function was successful.
* @retval IFX_I2C_STACK_ERROR If the module is busy.
*/
host_lib_status_t ifx_i2c_pl_receive_frame(ifx_i2c_context_t *p_ctx);
/**
* @brief Function for setting slave address.
*
* Synchronous function to set slave address.
*
* @param[in] p_ctx Pointer to ifx i2c context.
*\param[in] slave_address Holds new slave address[7 Bit] to be set.
* \param[in] storage_type Storage type.
*
* @retval IFX_I2C_STACK_SUCCESS If function was successful.
* @retval IFX_I2C_STACK_ERROR If setting slave address fails.
*/
host_lib_status_t ifx_i2c_pl_write_slave_address(ifx_i2c_context_t *p_ctx, uint8_t slave_address, uint8_t storage_type);
/**
* @}
**/
#ifdef __cplusplus
}
#endif
#endif /* _IFX_I2C_PHYSICAL_LAYER_H_ */

View File

@@ -0,0 +1,98 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file ifx_i2c_transport_layer.h
*
* \brief This file defines the API prototype for transport layer of the Infineon I2C Protocol Stack library.
*
* \addtogroup grIFXI2C
* @{
*/
#ifndef _IFX_I2C_TRANSPORT_LAYER_H_
#define _IFX_I2C_TRANSPORT_LAYER_H_
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************************************************************
* HEADER FILES
**********************************************************************************************************************/
#include "optiga/ifx_i2c/ifx_i2c_config.h"
#include "optiga/pal/pal_os_timer.h"
/***********************************************************************************************************************
* MACROS
**********************************************************************************************************************/
/***********************************************************************************************************************
* ENUMS
**********************************************************************************************************************/
/***********************************************************************************************************************
* DATA STRUCTURES
***********************************************************************************************************************/
/***********************************************************************************************************************
* API PROTOTYPES
**********************************************************************************************************************/
/**
* @brief Function for initializing the module.
*
* Function initializes and enables the module and registers
* an event handler to receive events from this module.
* @attention This function must be called before using the module.
*
* @param[in,out] p_ctx Pointer to ifx i2c context.
* @param[in] handler Function pointer to the event handler of the upper layer.
*
* @retval IFX_I2C_STACK_SUCCESS If initialization was successful.
* @retval IFX_I2C_STACK_ERROR If the module is already initialized.
*/
host_lib_status_t ifx_i2c_tl_init(ifx_i2c_context_t *p_ctx,ifx_i2c_event_handler_t handler);
/**
* @brief Function to transmit and receive a packet.
*
* Asynchronous function to send and receive a packet.
* The function returns immediately. One of the following events is
* propagated to the event handler registered with @ref ifx_i2c_tl_init
*
* @param[in,out] p_ctx Pointer to ifx i2c context.
* @param[in] p_packet Buffer containing the packet header.
* @param[in] packet_len Packet header length.
* @param[in] p_recv_packet Buffer containing the packet payload.
* @param[in] recv_packet_len Packet payload length.
*
* @retval IFX_I2C_STACK_SUCCESS If function was successful.
* @retval IFX_I2C_STACK_ERROR If the module is busy.
*/
host_lib_status_t ifx_i2c_tl_transceive(ifx_i2c_context_t *p_ctx,uint8_t* p_packet, uint16_t packet_len,
uint8_t* p_recv_packet, uint16_t* recv_packet_len);
/**
* @}
**/
#ifdef __cplusplus
}
#endif
#endif /* IFX_I2C_TRANSPORT_LAYER_H__ */

View File

@@ -0,0 +1,544 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
* \file
*
* \brief This file implements the prototype declarations of OPTIGA Crypt.
*
* \addtogroup grOptigaCrypt
* @{
*/
#ifndef _OPTIGA_CRYPT_H_
#define _OPTIGA_CRYPT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "optiga/common/Datatypes.h"
#include "optiga/cmd/CommandLib.h"
/**
* OPTIGA crypt module return values
*/
///OPTIGA crypt API execution is successful
#define OPTIGA_CRYPT_SUCCESS (0x0000)
///OPTIGA crypt module in busy state
#define OPTIGA_CRYPT_BUSY (0x0001)
///OPTIGA crypt API failed
#define OPTIGA_CRYPT_ERROR (0x0402)
///OPTIGA crypt API called with invalid inputs
#define OPTIGA_CRYPT_ERROR_INVALID_INPUT (0x0403)
///OPTIGA crypt API called with insufficient memory buffer
#define OPTIGA_CRYPT_ERROR_MEMORY_INSUFFICIENT (0x0404)
///OPTIGA crypt API called when, a request of same instance is already in service
#define OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE (0x0405)
/**
* \brief Typedef for Key IDs
* The KEY_STORE_ID_xxx holds only private key
*
* The SESSION_ID_xxx can hold private key, premaster secret(ECDH) and master secret(PRF).
* But only one at a time.
*/
typedef enum optiga_key_id
{
/// Key from key store (non-volatile)
OPTIGA_KEY_STORE_ID_E0F0 = 0xE0F0,
/// Key from key store (non-volatile)
OPTIGA_KEY_STORE_ID_E0F1 = 0xE0F1,
/// Key from key store (non-volatile)
OPTIGA_KEY_STORE_ID_E0F2 = 0xE0F2,
/// Key from key store (non-volatile)
OPTIGA_KEY_STORE_ID_E0F3 = 0xE0F3,
/// Key from Session context id 1 (volatile)
OPTIGA_SESSION_ID_E100 = 0xE100,
/// Key from Session context id 2 (volatile)
OPTIGA_SESSION_ID_E101 = 0xE101,
/// Key from Session context id 3 (volatile)
OPTIGA_SESSION_ID_E102 = 0xE102,
/// Key from Session context id 4 (volatile)
OPTIGA_SESSION_ID_E103 = 0xE103,
} optiga_key_id_t;
/**
* OPTIGA Random Generation types
*/
typedef enum optiga_rng_types
{
/// Generate Random data using TRNG
OPTIGA_RNG_TYPE_TRNG = 0x00,
/// Generate Random data using DRNG
OPTIGA_RNG_TYPE_DRNG = 0x01,
} optiga_rng_types_t;
typedef enum optiga_ecc_curve
{
//TBD: values to be aligned as per the specification
///
OPTIGA_ECC_NIST_P_256 = 0x03,
///
OPTIGA_ECC_NIST_P_384 = 0x04,
} optiga_ecc_curve_t;
typedef enum optiga_key_usage
{
/// This enables the private key for the signature generation as part of authentication commands
OPTIGA_KEY_USAGE_AUTHENTICATION = 0x01,
/// This enables the private key for the signature generation
OPTIGA_KEY_USAGE_SIGN = 0x10,
/// This enables the private key for key agreement (e.g. ecdh operations)
OPTIGA_KEY_USAGE_KEY_AGREEMENT = 0x20,
} optiga_key_usage_t;
/**
* \brief To specify the hash context information.
*/
typedef struct optiga_hash_context
{
///buffer to hold the context data
uint8_t * context_buffer;
///context length
uint16_t context_buffer_length;
///hashing algorithm
uint8_t hash_algo;
} optiga_hash_context_t;
/**
* \brief Specifies the hashing algorithm type in OPTIGA.
*/
typedef enum optiga_hash_type
{
/// Hash algorithm type SHA256
OPTIGA_HASH_TYPE_SHA_256 = 0xE2
} optiga_hash_type_t;
/** @brief Data is provided by host*/
#define OPTIGA_CRYPT_HOST_DATA (0x01)
/** @brief Data in internal to optiga OID */
#define OPTIGA_CRYPT_OID_DATA (0x00)
/**
* \brief To specify the data coming from the host for hashing.
*/
typedef struct hash_data_from_host
{
/// data for hashing
const uint8_t * buffer;
/// data length for hashing
uint32_t length;
} hash_data_from_host_t;
/**
* \brief To specify the data object for hashing.
*/
typedef struct hash_data_in_optiga
{
///OID of data object
uint16_t oid;
///Offset within the data object
uint16_t offset;
///Number of data bytes starting from the offset
uint16_t length;
} hash_data_in_optiga_t;
/**
* \brief To specifiy the Public Key details (key, size and algorithm)
*/
typedef struct public_key_from_host
{
/// Public Key
uint8_t * public_key;
/// Length of public key
uint16_t length;
/// Public key algorithm
uint8_t curve;
} public_key_from_host_t;
/**
* \brief To specify the OID which holds the shared secret.
*/
typedef struct key_from_opitga
{
///
uint16_t key_oid;
} optiga_shared_secret_t;
/**
* @brief Generates a random number.
*
* Generates the requested random stream of data for the user provided length.<br>
*
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>
*
*<b>API Details:</b>
* - Invokes optiga_cmd_get_random API, based on the input arguments to retrieve random data .<br>
*<br>
*
*<b>Notes:</b>
* - Error codes from lower layers will be returned as it is.<br>
* - The maximum value of the <b>random_data_length</b> parameter is size of buffer <b>random_data</b>.
* In case the value is greater than buffer size, memory corruption can occur.<br>
*
* \param[in] rng_type Type of random data generator.
* - The input must be from optiga_rng_type.
* - Argument check for rng_type is not done since OPTIGA will provide an error for invalid rng_type.
* \param[in,out] random_data Pointer to the buffer into which random data is stored, must not be NULL.
* \param[in] random_data_length Length of random data to be generated.
* - Range should be 8 - 256 bytes.
* - Length validation is not done, since OPTIGA will provide an error for invalid random_data_length.
*
* \retval OPTIGA_CRYPT_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_CRYPT_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing is used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_random(optiga_rng_types_t rng_type,
uint8_t * random_data,
uint16_t random_data_length);
/**
*
* @brief Initializes a hash context.
*
* Sets up a hash context and exports it.<br>
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>
*
*<b>API Details:</b><br>
* - Initializes a new hash context.<br>
* - Exports the hash context to caller.<br>
*
*<b>Notes:</b><br>
* - Error codes from lower layer will be returned as it is.<br>
* - User must save the output hash context for further usage as OPTIGA does not store it internally.<br>
*
*<br>
* \param[inout] hash_ctx Pointer to optiga_hash_context_t to store the hash context from OPTIGA
* - The input <b>hash_algo</b> in <b>hash_ctx</b> must be from optiga_hash_type.
*
* \retval OPTIGA_CRYPT_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_CRYPT_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing is used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_hash_start(optiga_hash_context_t * hash_ctx);
/**
*
* @brief Updates a hash context with the input data.
*
* Updates hashing for the given data and hash context then export the updated hash context.<br>
*
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>
* - optiga_hash_context_t from optiga_crypt_hash_start or optiga_crypt_hash_update must be available.
*
*<b>API Details:</b><br>
* - Update the input hash context.<br>
* - Exports the hash context to caller.<br>
*
*<b>Notes:</b><br>
* - Error codes from lower layer will be returned as it is.<br>
* - User must save the output hash context for further usage as OPTIGA does not store it internally.<br>
*
*<br>
* \param[in] hash_ctx Pointer to optiga_hash_context_t containing hash context from OPTIGA, must not be NULL
* \param[in] source_of_data_to_hash Data from host / Data in optiga. Must be one of the below
* - OPTIGA_CRYPT_HOST_DATA,if source of data is from Host.
* - OPTIGA_CRYPT_OID_DATA,if the source of data is from OPITGA.
* \param[in] data_to_hash Data for hashing either in hash_data_from_host or in hash_data_in_optiga
*
* \retval OPTIGA_CRYPT_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_CRYPT_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing is used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_hash_update(optiga_hash_context_t * hash_ctx,
uint8_t source_of_data_to_hash,
void * data_to_hash);
/**
*
* @brief Finalizes and exports the hash output.
*
* Finalizes the hash context and returns hash as output.<br>
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>
* - optiga_hash_context_t from optiga_crypt_hash_start or optiga_crypt_hash_update must be available.
*
*<b>API Details:</b><br>
* - Finalize the hash from the input hash context
* - Exports the finalized hash.
*
*<b>Notes:</b><br>
* - Error codes from lower layer will be returned as it is.<br>
* - hash context is not updated by this API. This can be used later to fulfill intermediate hash use-cases<br>
* - User must save the output hash context for further usage as OPTIGA does not store it internally.<br>
*
*<br>
* \param[in] hash_ctx Pointer to optiga_hash_context_t containing hash context from OPTIGA, must not be NULL
* \param[inout] hash_output Output Hash
*
* \retval OPTIGA_CRYPT_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_CRYPT_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing is used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_hash_finalize(optiga_hash_context_t * hash_ctx,
uint8_t * hash_output);
/**
*
* @brief Generates an key pair based on ECC curves.
*
* Generates an ECC key-pair based on the type of the key.<br>
*
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>
*
*<b>API Details:</b>
* - Generate an ECC key pair using OPTIGA.<br>
* - If export is requested, Exports the private key else stores it in the input private key OID.<br>
* - Exports the public key always.<br>
*<br>
*
*<b>Notes:</b>
* - Error codes from lower layers will be returned as it is.<br>
*
* \param[in] curve_id ECC curve id.
* \param[in] key_usage Key usage defined by optiga_key_usage_t.
* - Values from optiga_key_usage can be logically ORed and passed.<br>
* - It is ignored if export_private_key is FALSE (0).
* \param[in] export_private_key TRUE (1) - Exports both private key and public key to the host.<br>
* FALSE (0) - Exports only public key to the host. The input key_usage is ignored.
* \param[in] private_key Buffer to store private key or private key OID of OPTIGA, must not be NULL.
* - If export_private_key is TRUE, assign pointer to a buffer to store private key.
* - The size of the buffer must be sufficient enough to accommodate the key type and additional DER encoding formats.
* - If export_private_key is FALSE, assign pointer to variable of type optiga_key_id_t.
* \param[in,out] public_key Buffer to store public key, must not be NULL.
* \param[in] public_key_length Initially set as length of public_key, later updated as actual length of public_key.
*
* \retval OPTIGA_CRYPT_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_CRYPT_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing is used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_ecc_generate_keypair(optiga_ecc_curve_t curve_id,
uint8_t key_usage,
bool_t export_private_key,
void * private_key,
uint8_t * public_key,
uint16_t * public_key_length);
/**
*
* @brief Generates a signature for the given digest.
*
* Generates a signature for the given digest using private key stored in OPTIGA.<br>
*
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>.
*
*<b>API Details:</b>
* - Generated signature for the input digest.<br>
* - Exports the generated signature.<br>
*<br>
*
*<b>Notes:</b>
* - Error codes from lower layers will be returned as it is.<br>
*
* \param[in] digest Digest on which signature is generated.
* \param[in] digest_length Length of the input digest.
* \param[in] private_key Private key OID to generate signature.
* \param[in,out] signature Generated signature, must not be NULL.
* - The size of the buffer must be sufficient enough to accommodate the additional DER encoding formatting for R and S components of signature.
* \param[in] signature_length Length of signature.Intial value set as length of buffer, later updated as the actual length of generated signature.
*
* \retval OPTIGA_CRYPT_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_CRYPT_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing is used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_ecdsa_sign(uint8_t * digest,
uint8_t digest_length,
optiga_key_id_t private_key,
uint8_t * signature,
uint16_t * signature_length);
/**
*
* @brief Verifies the signature over the given digest.
*
* Verifies the signature over a given digest provided with the input data.<br>
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application.<br>
*
*<b>API Details:</b>
* - Verifies the signature over the given provided with the input data using public key.
*
*<b>Notes:</b>
* - Error codes from lower layers will be returned as it is to the application.<br>
*
* \param[in] digest Pointer to a given digest buffer, must not be NULL.
* \param[in] digest_length Length of digest
* \param[in] signature Pointer to a given signature buffer, must not be NULL.
* \param[in] signature_length Length of signature
* \param[in] public_key_source_type Public key from host / public key of certificate OID from OPTIGA. Value must be one of the below
* - OPTIGA_CRYPT_OID_DATA, if the public key is to used from the certificate data object from OPTIGA.
* - OPTIGA_CRYPT_HOST_DATA, if the public key is provided by host.
* \param[in] public_key Public key from host / public key of certificate OID. Value must be one of the below
* - For certificate OID, pointer OID value must be passed.
* - For Public key from host, pointer to public_key_from_host_t instance.
*
* \retval OPTIGA_CRYPT_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_CRYPT_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing is used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_ecdsa_verify(uint8_t * digest,
uint8_t digest_length,
uint8_t * signature,
uint16_t signature_length,
uint8_t public_key_source_type,
void * public_key);
/**
* @brief Calculates the shared secret using ECDH algorithm.
*
* Calculates the shared secret using ECDH algorithm.<br>
*
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application.<br>
* - There must be a secret available in the "session context / data object OID" provided as input parameter.<br>
*
*<b>API Details:</b>
* - Calculates the shared secret based on input private key object ID and public key.<br>
* - Based on user request(export_to_host), the shared secret can either be exported to the host or be stored in the acquired session object ID.<br>
*<br>
*
*<b>Notes:</b>
* - Error codes from lower layers will be returned as it is.<br>
* - The buffer size for shared secret should be appropriately provided by the user
* - If the user provides <b>private_key</b> as session based and <b>export_to_host</b> as FALSE,<br>
* then the shared secret generated will overwrite the private key stored in the session object ID
*
* \param[in] private_key Object ID of the private key stored in OPTIGA.<br>
* - Possible values are from the optiga_key_id_t <br>
* - Argument check for private_key is not done since OPTIGA will provide an error for invalid private_key.
* \param[in] public_key Pointer to the public key structure for shared secret generation with its properties, must not be NULL.<br>
* - Provide the inputs according to the structure type public_key_from_host_t
* \param[in] export_to_host TRUE (1) - Exports the generated shared secret to Host. <br>
* FALSE (0) - Stores the generated shared secret into the session object ID acquired by the instance.
* \param[in,out] shared_secret Pointer to the shared secret buffer, only if <b>export_to_host</b> is TRUE. <br>
* Otherwise supply NULL as input.
*
* \retval OPTIGA_CRYPT_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_CRYPT_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing is used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_ecdh(optiga_key_id_t private_key,
public_key_from_host_t * public_key,
bool_t export_to_host,
uint8_t * shared_secret);
/**
* @brief Derives a key.
*
* Derives a key using the secret stored in OPTIGA.<br>
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application.<br>
* - There must be a secret available in the "session context / data object OID" provided as input parameter.<br>
* - An instance of optiga_crypt_t must be created using the optiga_crypt_create API.
*
*<b>API Details:</b>
* - Derives a key using the secret stored in OPTIGA.
* - Provides the options to store the derived key into OPTIGA session context or export to the host.
* - It invokes the callback handler of the instance, when it is asynchronously completed.
*
*<b>Notes:</b>
* - At present, the minimum length of the output derived key is 16.
* - Error codes from lower layers will be returned as it is to the application.<br>
*
* \param[in] secret Object ID of the secret stored in OPTIGA.
* - OPTIGA_KEY_ID_SESSION_BASED from optiga_key_id_t, indicates the secret is available.
* in the session context acquired by the instance.
* - or any OPTIGA data object ID(16 bit OID) which holds the secret.
* \param[in] label Pointer to the label, can be NULL if not applicable.
* \param[in] label_length Length of the label.
* \param[in] seed Valid pointer to the seed, must not be NULL.
* \param[in] seed_length Length of the seed.
* \param[in] derived_key_length Length of derived key.
* \param[in] export_to_host TRUE (1) - Exports the derived key to Host. <br>
* FALSE (0) - Stores the derived key into the session object ID acquired by the instance.
* \param[in,out] derived_key Pointer to the valid buffer with a minimum size of derived_key_length,
* in case of exporting the key to host(<b>export_to_host= TRUE</b>). Otherwise set to NULL.
*
* \retval OPTIGA_CRYPT_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_CRYPT_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_CRYPT_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing is used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_tls_prf_sha256(uint16_t secret,
uint8_t * label,
uint16_t label_length,
uint8_t * seed,
uint16_t seed_length,
uint16_t derived_key_length,
bool_t export_to_host,
uint8_t * derived_key);
#ifdef __cplusplus
}
#endif
#endif //_OPTIGA_CRYPT_H_
/**
* @}
*/

View File

@@ -0,0 +1,210 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file defines APIs, types and data structures used in the
* OCP implementation.
*
* \addtogroup grOCP
* @{
*/
#ifndef __OCP_H__
#define __OCP_H__
/// @cond hidden
#ifndef _OPTIGA_EXPORTS_DLLEXPORT_H_
#define _OPTIGA_EXPORTS_DLLEXPORT_H_
#if defined(WIN32) || defined(_WIN32)
#ifdef OPTIGA_LIB_EXPORTS
#define LIBRARY_EXPORTS __declspec(dllexport)
#else
#define LIBRARY_EXPORTS __declspec(dllimport)
#endif // OPTIGA_LIB_EXPORTS
#else
#define LIBRARY_EXPORTS
#endif //WIN32
#endif /*_OPTIGA_EXPORTS_DLLEXPORT_H_*/
/// @endcond
#include "optiga/common/Datatypes.h"
#include "optiga/dtls/OcpCommon.h"
#include "optiga/dtls/OcpCommonIncludes.h"
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
/****************************************************************************
*
* API Error Codes
*
****************************************************************************/
/// Successful execution
#define OCP_LIB_OK 0x75282512
/// Failure in execution
#define OCP_LIB_ERROR 0xF3053159
/// Null Parameter(s)
#define OCP_LIB_NULL_PARAM BASE_ERROR_OCPLAYER
/// Unsupported Configuration
#define OCP_LIB_UNSUPPORTED_CONFIG (BASE_ERROR_OCPLAYER + 1)
/// Connection already exists
#define OCP_LIB_CONNECTION_ALREADY_EXISTS (BASE_ERROR_OCPLAYER + 2)
/// Session ID not available
#define OCP_LIB_SESSIONID_UNAVAILABLE (BASE_ERROR_OCPLAYER + 3)
/// Memory Allocation failure
#define OCP_LIB_MALLOC_FAILURE (BASE_ERROR_OCPLAYER + 4)
/// Unsupported PMTU Value
#define OCP_LIB_UNSUPPORTED_PMTU (BASE_ERROR_OCPLAYER + 5)
/// Unsupported Mode
#define OCP_LIB_UNSUPPORTED_MODE (BASE_ERROR_OCPLAYER + 6)
///Authentication not done
#define OCP_LIB_AUTHENTICATION_NOTDONE (BASE_ERROR_OCPLAYER + 7)
///Data Length is greater than the maximum length
#define OCP_LIB_INVALID_LEN (BASE_ERROR_OCPLAYER + 8)
///Data Length is equal to zero
#define OCP_LIB_LENZERO_ERROR (BASE_ERROR_OCPLAYER + 9)
///Memory is not sufficient
#define OCP_LIB_INSUFFICIENT_MEMORY (BASE_ERROR_OCPLAYER + 10)
///Invalid timeout value
#define OCP_LIB_INVALID_TIMEOUT (BASE_ERROR_OCPLAYER + 11)
///Timeout occured
#define OCP_LIB_TIMEOUT (BASE_ERROR_OCPLAYER + 12)
///requested operation not allowed
#define OCP_LIB_OPERATION_NOT_ALLOWED (BASE_ERROR_OCPLAYER + 13)
///Decryption failure
#define OCP_LIB_DECRYPT_FAILURE (BASE_ERROR_OCPLAYER + 14)
///No renegotiation supported
#define OCP_LIB_NO_RENEGOTIATE (BASE_ERROR_OCPLAYER + 15)
/****************************************************************************
*
* Common data structure used across all functions.
*
****************************************************************************/
/**
* \brief Enumeration for supported OCP Configurations
*/
typedef enum eConfiguration_d
{
///DTLS 1.2 protocol over UDP using Hardware crypto
eDTLS_12_UDP_HWCRYPTO = 0x85,
///TLS 1.2 protocol over TCP using Hardware crypto
eTLS_12_TCP_HWCRYPTO = 0x49
}eConfiguration_d;
/**
* \brief Structure to that hold network related information
*/
typedef struct sNetworkParams_d
{
///Port Number
uint16_t wPort;
///IP Address
char_t* pzIpAddress;
///Network Pmtu
uint16_t wMaxPmtu;
}sNetworkParams_d;
/**
* \brief Structure to Configure OCP Library
*/
typedef struct sConfigOCP_d
{
///Callback function pointer to get Unix time
fGetUnixTime_d pfGetUnixTIme;
///Network connection structure
sNetworkParams_d sNetworkParams;
///Mode of operation
eMode_d eMode;
///Configuration of mode
eConfiguration_d eConfiguration;
///Logger
sLogger_d sLogger;
///Certificate OID
uint16_t wOIDDevCertificate;
///Private key OID
uint16_t wOIDDevPrivKey;
}sAppOCPConfig_d;
/**
* \brief Initializes the OCP Library.
*/
LIBRARY_EXPORTS int32_t OCP_Init(const sAppOCPConfig_d* PpsAppOCPConfig,hdl_t* PphAppOCPCtx);
/**
* \brief Connect to server and performs a Handshake.
*/
LIBRARY_EXPORTS int32_t OCP_Connect(const hdl_t PhAppOCPCtx);
/**
* \brief Sends Application data.
*/
LIBRARY_EXPORTS int32_t OCP_Send(const hdl_t PhAppOCPCtx,const uint8_t* PpbData,uint16_t PwLen);
/**
* \brief Receives Application data.
*/
LIBRARY_EXPORTS int32_t OCP_Receive(const hdl_t PhAppOCPCtx,uint8_t* PpbData,uint16_t* PpwLen, uint16_t PwTimeout);
/**
* \brief Disconnects from server.
*/
LIBRARY_EXPORTS int32_t OCP_Disconnect(hdl_t PhAppOCPCtx);
#endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH*/
#endif //__OCP_H__
/**
* @}
*/

View File

@@ -0,0 +1,323 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
* \file
*
* \brief This file defines APIs, types and data structures used in the OPTIGA UTIL module.
*
* \addtogroup grOptigaUtil
* @{
*/
#ifndef _H_OPTIGA_UTIL_H_
#define _H_OPTIGA_UTIL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "optiga/common/Datatypes.h"
#include "optiga/cmd/CommandLib.h"
#include "optiga/common/AuthLibSettings.h"
///Requested operation completed without any error
#define INT_LIB_OK 0x75AB1C02
///Null parameter(s)
#define INT_LIB_NULL_PARAM 0x80002001
///Invalid data in response
#define INT_LIB_INVALID_RESPONSE (INT_LIB_NULL_PARAM + 1)
///Invalid access condition
#define INT_LIB_INVALID_AC (INT_LIB_NULL_PARAM + 2)
///Length of input is zero
#define INT_LIB_ZEROLEN_ERROR (INT_LIB_NULL_PARAM + 3)
///Invalid or unsupported parameter(s)
#define INT_LIB_INVALID_PARAM (INT_LIB_NULL_PARAM + 4)
///Invalid Length
#define INT_LIB_INVALID_LENGTH (INT_LIB_NULL_PARAM + 5)
///Malloc Failures
#define INT_LIB_MALLOC_FAILURE (INT_LIB_NULL_PARAM + 6)
///General error
#define INT_LIB_ERROR 0xFE5A5502
/// Option to only write the data object
#define OPTIGA_UTIL_WRITE_ONLY (0x00)
/// Option to erase and write the data object
#define OPTIGA_UTIL_ERASE_AND_WRITE (0x40)
/**
* OPTIGA util module return values
*/
///OPTIGA util API execution is successful
#define OPTIGA_UTIL_SUCCESS (0x0000)
///OPTIGA util module in busy state
#define OPTIGA_UTIL_BUSY (0x0001)
///OPTIGA util API failed
#define OPTIGA_UTIL_ERROR (0x0302)
///OPTIGA util API called with invalid inputs
#define OPTIGA_UTIL_ERROR_INVALID_INPUT (0x0303)
///OPTIGA util API called with insufficient memory buffer
#define OPTIGA_UTIL_ERROR_MEMORY_INSUFFICIENT (0x0304)
///OPTIGA util API called when, a request of same instance is already in service
#define OPTIGA_UTIL_ERROR_INSTANCE_IN_USE (0x0305)
/**
* \brief Typedef for OIDs
*/
typedef enum eOID_d
{
/// Global Life Cycle State
eLCS_G = 0xE0C0,
/// Global Security Status
eSECURITY_STATUS_G = 0xE0C1,
/// Coprocessor UID
eCOPROCESSOR_UID = 0xE0C2,
/// Global Life Cycle State
eSLEEP_MODE_ACTIVATION_DELAY = 0xE0C3,
/// Current limitation
eCURRENT_LIMITATION = 0xE0C4,
/// Security Event Counter
eSECURITY_EVENT_COUNTER = 0xE0C5,
/// Device Public Key Certificate issued by IFX
eDEVICE_PUBKEY_CERT_IFX = 0xE0E0,
/// Project-Specific device Public Key Certificate
eDEVICE_PUBKEY_CERT_PRJSPC_1 = 0xE0E1,
/// Project-Specific device Public Key Certificate
eDEVICE_PUBKEY_CERT_PRJSPC_2 = 0xE0E2,
/// Project-Specific device Public Key Certificate
eDEVICE_PUBKEY_CERT_PRJSPC_3 = 0xE0E3,
/// First Device Private Key
eFIRST_DEVICE_PRIKEY_1 = 0xE0F0,
/// First Device Private Key
eFIRST_DEVICE_PRIKEY_2 = 0xE0F1,
/// First Device Private Key
eFIRST_DEVICE_PRIKEY_3 = 0xE0F2,
/// First Device Private Key
eFIRST_DEVICE_PRIKEY_4 = 0xE0F3,
/// Application Life Cycle Status
eLCS_A = 0xF1C0,
/// Application Security Status
eSECURITY_STATUS_A = 0xF1C1,
/// Error codes
eERROR_CODES = 0xF1C2
} eOID_d;
/**
* @brief Initializes the communication with optiga.
*
* Initializes the communication with OPTIGA for the given instance. <br>
*
*<b>Pre Conditions:</b>
*
*<b>API Details:</b>
* - Initiate open application command to optiga.<br>
*<br>
*
*<b>Notes:</b><br>
* Initialisation flow example:
*
* optiga_comms_t optiga_comms = {(void*)&ifx_i2c_context_0, NULL, NULL, 0};
*
* static int32_t optiga_init(void)
* {
* int32_t status = (int32_t) OPTIGA_LIB_ERROR;
*
* do
* {
* status = optiga_util_open_application(&optiga_comms);
* if(OPTIGA_LIB_SUCCESS != status)
* {
* // optiga_util_open_application() failed
* break;
* }
*
* status = OPTIGA_LIB_SUCCESS;
* } while(0);
*
* return status;
* }
*
* \param[in] p_comms Pointer to the communication parameters initialised before
* - Error codes from lower layer will be returned as it is.<br>
*
* \retval OPTIGA_LIB_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_LIB_ERROR Error during function execurition
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_open_application(optiga_comms_t* p_comms);
/**
* @brief Reads data from optiga.
*
* Retrieves the requested data that is stored from the user provided data object.<br>
*
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>
*
*<b>API Details:</b>
* - Invokes optiga_cmd_get_data_object API, based on the input arguments to read the data from the data object.<br>
*<br>
*
*<b>Notes:</b>
* - Error codes from lower layers will be returned as it is.<br>
* - The maximum value of the <b>*bytes_to_read</b> parameter is size of buffer <b>p_buffer</b>. In case the value is greater than buffer size, memory corruption can occur.<br>
* - <b>*bytes_to_read</b> parameter is set to 0, in case any errors occurs while retrieving the data. initially contains the value of the user provided data length to be read. When the data is successfully retrieved, this value is updated with actual data length retrieved.<br>
* In case of any errors, the value is set to 0.<br>
*
* \param[in] optiga_oid OID of data object
* - It should be a valid data object, otherwise OPTIGA returns an error.<br>
* \param[in] offset Offset from within data object
* - It must be valid offset from within data object, otherwise OPTIGA returns an error.<br>
* \param[in,out] buffer Valid pointer to the buffer to which data is read
* \param[in,out] bytes_to_read Valid pointer to the length of data to be read from data object
* - When the data is successfully retrieved, it is updated with actual data length retrieved
*
* \retval OPTIGA_UTIL_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_UTIL_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_read_data(uint16_t optiga_oid,
uint16_t offset,
uint8_t * buffer,
uint16_t * bytes_to_read);
/**
* @brief Reads metadata of a data object from optiga.
*
* Reads the metadata of the user provided data object.<br>
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>
*
*<b>API Details:</b>
* - Invokes optiga_cmd_get_data_object API, based on the input arguments to read the metadata from the data object.<br>
*<br>
*
*<b>Notes:</b>
* - Error codes from lower layers will be returned as it is.<br>
* - The metadata returned will be in TLV format.<br>
* - The maximum value of the <b>*bytes_to_read</b> parameter is size of buffer <b>p_buffer</b>. In case the value is greater than buffer size, memory corruption can occur.<br>
*
* \param[in] optiga_oid OID of data object
* - It should be a valid data object, otherwise OPTIGA returns an error.<br>
* \param[in,out] buffer Valid pointer to the buffer to which metadata is read
* \param[in,out] bytes_to_read Valid pointer to the length of metadata to be read from data object
* - When the metadata is successfully retrieved, it is updated with actual metadata length retrieved
*
* \retval OPTIGA_UTIL_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_UTIL_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_UTIL_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_read_metadata(uint16_t optiga_oid,
uint8_t * buffer,
uint16_t * bytes_to_read);
/**
* @brief Writes data to optiga.
*
* Writes the data provided by the user into the specified data object.<br>
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>
*
*<b>API Details:</b>
* - Invokes optiga_cmd_set_data_object API, based on the input arguments to write the data to the data object.<br>
*<br>
*
*<b>Notes:</b>
* - Error codes from lower layers will be returned as it is.<br>
* - The maximum value of the <b>bytes_to_write parameter</b> is size of buffer <b>p_buffer</b>. In case the value is greater than buffer size, incorrect values can get written into the data object in OPTIGA.<br>
* - In case the write_type provided is other than <b>erase and write(0x00)</b> or <b>write only(0x40)</b>, the function returns OPTIGA_UTIL_ERROR.<br>
*
* \param[in] optiga_oid OID of data object
* - It should be a valid data object, otherwise OPTIGA returns an error.<br>
* \param[in] write_type Type of the write operation. Can be OPTIGA_UTIL_ERASE_AND_WRITE or OPTIGA_UTIL_WRITE_ONLY
* \param[in] offset Offset from within data object
* - It must be valid offset from within data object, otherwise OPTIGA returns an error.<br>
* \param[in,out] buffer Valid pointer to the buffer with user data to write
* \param[in] bytes_to_write Length of data to be written
*
* \retval OPTIGA_UTIL_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_UTIL_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_UTIL_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing used
* \retval OPTIGA_CMD_ERROR_MEMORY_INSUFFICIENT Length of the buffer to copy the metadata is less than actual length of metadata
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_write_data(uint16_t optiga_oid,
uint8_t write_type,
uint16_t offset,
uint8_t * buffer,
uint16_t bytes_to_write);
/**
* @brief Writes metadata for the user provided data object.
*
* Writes metadata for the user provided data object.
*
*<b>Pre Conditions:</b>
* - The application on OPTIGA must be opened using optiga_util_open_application before using this API.<br>
*
*<b>API Details:</b>
* - Invokes optiga_cmd_set_data_object API, based on the input arguments to write metadata to the data object.<br>
*<br>
*
*<b>Notes:</b>
* - Error codes from lower layers will be returned as it is.<br>
* - The maximum value of the <b>bytes_to_write</b> parameter is size of buffer <b>p_buffer</b>.
* In case the value is greater than buffer size, incorrect values can get written into the meta data of the data object in OPTIGA.<br>
* - The metadata to be written must be in TLV format <br>
*
* \param[in] optiga_oid OID of data object
* - It should be a valid data object, otherwise OPTIGA returns an error.<br>
* \param[in,out] buffer Valid pointer to the buffer with metadata to write
* \param[in] bytes_to_write Length of metadata to be written
*
* \retval OPTIGA_UTIL_SUCCESS Successful invocation of optiga cmd module
* \retval OPTIGA_UTIL_ERROR_INVALID_INPUT Wrong Input arguments provided
* \retval OPTIGA_UTIL_ERROR_INSTANCE_IN_USE Same instance with ongoing request servicing used
* \retval OPTIGA_DEVICE_ERROR Command execution failure in OPTIGA and the LSB indicates the error code.(Refer Solution Reference Manual)
*/
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_write_metadata(uint16_t optiga_oid,
uint8_t * buffer,
uint8_t bytes_to_write);
#ifdef __cplusplus
}
#endif
#endif //_H_OPTIGA_UTIL_H_
/**
* @}
*/

View File

@@ -0,0 +1,74 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file implements the prototype declarations of platform abstraction layer
*
* \addtogroup grPAL
* @{
*/
#ifndef _PAL_H_
#define _PAL_H_
/**********************************************************************************************************************
* HEADER FILES
*********************************************************************************************************************/
#include "optiga/common/Datatypes.h"
/**********************************************************************************************************************
* pal.h
*********************************************************************************************************************/
/**********************************************************************************************************************
* MACROS
*********************************************************************************************************************/
/// PAL API execution is successful
#define PAL_STATUS_SUCCESS (0x0000)
/// PAL API execution failed
#define PAL_STATUS_FAILURE (0x0001)
/// PAL I2C is busy
#define PAL_STATUS_I2C_BUSY (0x0002)
/**********************************************************************************************************************
* ENUMS
*********************************************************************************************************************/
/**
* \brief PAL return status.
*/
typedef uint16_t pal_status_t;
/**********************************************************************************************************************
* API Prototypes
*********************************************************************************************************************/
#endif /* _PAL_H_ */
/**
* @}
*/

View File

@@ -0,0 +1,93 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file implements the prototype declarations of pal gpio
*
* \addtogroup grPAL
* @{
*/
#ifndef _PAL_GPIO_H_
#define _PAL_GPIO_H_
/**********************************************************************************************************************
* HEADER FILES
*********************************************************************************************************************/
#include "optiga/pal/pal.h"
/**********************************************************************************************************************
* MACROS
*********************************************************************************************************************/
/**********************************************************************************************************************
* ENUMS
*********************************************************************************************************************/
/**********************************************************************************************************************
* DATA STRUCTURES
*********************************************************************************************************************/
/**
* \brief Structure defines the PAL GPIO configuration.
*/
typedef struct pal_gpio
{
/// Pointer to gpio platform specific context/structure
void* p_gpio_hw;
} pal_gpio_t;
/**********************************************************************************************************************
* API Prototypes
*********************************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Sets the gpio pin to high state.
*/
void pal_gpio_set_high(const pal_gpio_t* p_gpio_context);
/**
* \brief Sets the gpio pin to Low state.
*/
void pal_gpio_set_low(const pal_gpio_t* p_gpio_context);
#ifdef __cplusplus
}
#endif
#endif /* _PAL_GPIO_H_ */
/**
* @}
*/

View File

@@ -0,0 +1,107 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file implements the prototype declarations of pal i2c
*
* \addtogroup grPAL
* @{
*/
#ifndef _PAL_I2C_H_
#define _PAL_I2C_H_
/**********************************************************************************************************************
* HEADER FILES
*********************************************************************************************************************/
#include "optiga/pal/pal.h"
/**********************************************************************************************************************
* MACROS
*********************************************************************************************************************/
/// Event returned when I2C master completes execution
#define PAL_I2C_EVENT_SUCCESS (0x0000)
/// Event returned when I2C master operation fails
#define PAL_I2C_EVENT_ERROR (0x0001)
/// Event returned when lower level I2C bus is busy
#define PAL_I2C_EVENT_BUSY (0x0002)
/**********************************************************************************************************************
* ENUMS
*********************************************************************************************************************/
/**********************************************************************************************************************
* DATA STRUCTURES
*********************************************************************************************************************/
/** @brief PAL I2C context structure */
typedef struct pal_i2c
{
/// Pointer to I2C master platform specific context
void* p_i2c_hw_config;
/// I2C slave address
uint8_t slave_address;
/// Pointer to store the callers context information
void* upper_layer_ctx;
/// Pointer to store the callers handler
void* upper_layer_event_handler;
} pal_i2c_t;
/**********************************************************************************************************************
* API Prototypes
*********************************************************************************************************************/
/**
* @brief Initializes the I2C master.
*/
pal_status_t pal_i2c_init(const pal_i2c_t* p_i2c_context);
/**
* @brief Sets the I2C Master bitrate
*/
pal_status_t pal_i2c_set_bitrate(const pal_i2c_t* p_i2c_context, uint16_t bitrate);
//Dileep: "write on I2C bus" --> "write to I2C bus"
/**
* @brief Writes on I2C bus.
*/
pal_status_t pal_i2c_write(pal_i2c_t* p_i2c_context, uint8_t* p_data , uint16_t length);
/**
* @brief Reads from I2C bus.
*/
pal_status_t pal_i2c_read(pal_i2c_t* p_i2c_context, uint8_t* p_data , uint16_t length);
/**
* @brief De-initializes the I2C master.
*/
pal_status_t pal_i2c_deinit(const pal_i2c_t* p_i2c_context);
#endif /* _PAL_I2C_H_ */
/**
* @}
*/

View File

@@ -0,0 +1,64 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file implements the platform abstraction layer extern declarations for ifx i2c.
*
* \addtogroup grPAL
* @{
*/
#ifndef _PAL_IFX_I2C_CONFIG_H_
#define _PAL_IFX_I2C_CONFIG_H_
/**********************************************************************************************************************
* HEADER FILES
*********************************************************************************************************************/
#include "optiga/pal/pal.h"
#include "optiga/pal/pal_i2c.h"
#include "optiga/pal/pal_gpio.h"
/**********************************************************************************************************************
* MACROS
*********************************************************************************************************************/
/**********************************************************************************************************************
* ENUMS
*********************************************************************************************************************/
/**********************************************************************************************************************
* PAL extern definitions for IFX I2C
*********************************************************************************************************************/
extern pal_i2c_t optiga_pal_i2c_context_0;
extern pal_gpio_t optiga_vdd_0;
extern pal_gpio_t optiga_reset_0;
#endif /* _PAL_IFX_I2C_CONFIG_H_ */
/**
* @}
*/

View File

@@ -0,0 +1,79 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
* \file
*
* \brief This file implements the prototype declarations of pal os event
*
* \addtogroup grPAL
* @{
*/
#ifndef _PAL_OS_EVENT_H_
#define _PAL_OS_EVENT_H_
/**********************************************************************************************************************
* HEADER FILES
*********************************************************************************************************************/
#include "optiga/common/Datatypes.h"
#include "optiga/pal/pal.h"
/**********************************************************************************************************************
* MACROS
*********************************************************************************************************************/
/**********************************************************************************************************************
* ENUMS
*********************************************************************************************************************/
/**********************************************************************************************************************
* PAL extern definitions
*********************************************************************************************************************/
/**
* @brief typedef for Callback function when timer elapses.
*/
typedef void (*register_callback)(void*);
#ifdef PAL_OS_HAS_EVENT_INIT
/**
* @brief Platform specific event init function.
*/
pal_status_t pal_os_event_init(void);
#endif
/**
* @brief Callback registration function to trigger once when timer expires.
*/
void pal_os_event_register_callback_oneshot(register_callback callback, void* callback_args, uint32_t time_us);
#endif //_PAL_OS_EVENT_H_
/**
* @}
*/

View File

@@ -0,0 +1,78 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file pal_os_lock.h
*
* \brief This file provides the prototype declarations of PAL OS lock functionalities
*
* \addtogroup grPAL
* @{
*/
#ifndef _PAL_OS_LOCK_H_
#define _PAL_OS_LOCK_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "pal.h"
/**
* @brief Acquires a lock.
*
*<b>Pre-conditions:</b>
* None.<br>
*
*<b>API Details:</b>
* - Acquires the lock.<br>
*<br>
*
*
*/
pal_status_t pal_os_lock_acquire(void);
/**
* @brief Releases the lock.
*
*<b>Pre-conditions:</b>
* None.<br>
*
*<b>API Details:</b>
* - Releases the lock.<br>
*<br>
*
*
*/
void pal_os_lock_release(void);
#ifdef __cplusplus
}
#endif
#endif //_PAL_OS_LOCK_H_
/**
* @}
*/

View File

@@ -0,0 +1,77 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file implements the prototype declarations of pal os random functionalities
*
* \addtogroup grPAL
* @{
*/
#ifndef _PAL_OS_RANDOM_H_
#define _PAL_OS_RANDOM_H_
/**********************************************************************************************************************
* HEADER FILES
*********************************************************************************************************************/
#include "pal.h"
/**********************************************************************************************************************
* MACROS
*********************************************************************************************************************/
/**********************************************************************************************************************
* ENUMS
*********************************************************************************************************************/
/**********************************************************************************************************************
* DATA STRUCTURES
*********************************************************************************************************************/
/**********************************************************************************************************************
* API Prototypes
*********************************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Gets the random counter value.
*/
uint32_t pal_os_random_get_counter(void);
#ifdef __cplusplus
}
#endif
#endif /* _PAL_OS_RANDOM_H_ */
/**
* @}
*/

View File

@@ -0,0 +1,90 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file implements the prototype declarations of pal os timer functionalities.
*
* \addtogroup grPAL
* @{
*/
#ifndef _PAL_OS_TIMER_H_
#define _PAL_OS_TIMER_H_
/**********************************************************************************************************************
* HEADER FILES
*********************************************************************************************************************/
#include "optiga/pal/pal.h"
/*********************************************************************************************************************
* pal_os_timer.h
*********************************************************************************************************************/
/**********************************************************************************************************************
* MACROS
*********************************************************************************************************************/
/**********************************************************************************************************************
* ENUMS
*********************************************************************************************************************/
/**********************************************************************************************************************
* DATA STRUCTURES
*********************************************************************************************************************/
/**********************************************************************************************************************
* API Prototypes
*********************************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Gets tick count value in milliseconds
*/
uint32_t pal_os_timer_get_time_in_milliseconds(void);
/**
* @brief Waits or delay until the supplied milliseconds
*/
void pal_os_timer_delay_in_milliseconds(uint16_t milliseconds);
#ifdef __cplusplus
}
#endif
#endif /* _PAL_OS_TIMER_H_ */
/**
* @}
*/

View File

@@ -0,0 +1,198 @@
/**
* MIT License
*
* Copyright (c) 2018 Infineon Technologies AG
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
*
*
* \file
*
* \brief This file implements the prototype declarations of pal socket functionalities
* \addtogroup grPAL
* @{
*/
#ifndef _PAL_SOCKET_H_
#define _PAL_SOCKET_H_
/**********************************************************************************************************************
* HEADER FILES
*********************************************************************************************************************/
#ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH
#ifndef WIN32
#include "optiga/common/Datatypes.h"
#include "udp.h"
#include "inet.h"
#else
#include <winsock2.h>
#include "optiga/common/Datatypes.h"
#endif
#include "optiga/common/ErrorCodes.h"
#include "optiga/dtls/UDPErrorCodes.h"
/// @cond hidden
/**********************************************************************************************************************
* MACROS
*********************************************************************************************************************/
#ifndef WIN32
#define IPAddressParse(pzIpAddress, psIPAddress) (inet_aton(pzIpAddress, psIPAddress))
#else
#define IPAddressParse(pzIpAddress, psIPAddress) (1)
#endif
/// @endcond
/**********************************************************************************************************************
* ENUMS
*********************************************************************************************************************/
/**********************************************************************************************************************
* DATA STRUCTURES
*********************************************************************************************************************/
#ifndef WIN32
/**
* \brief Pointer type definition of pal socket receive event callback
*/
typedef void (*pal_socket_event_listener)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
ip_addr_t *addr, u16_t port);
#endif
/**
* \brief This structure contains socket communication data
*/
typedef enum eRecvMode_d
{
eBlock = 0x10,
eNonBlock = 0x20
}eRecvMode_d;
/**
* \brief This structure contains socket communication data
*/
#ifndef WIN32
typedef struct pal_socket
{
///UDP structure Tx
struct udp_pcb *pcbTx;
///UDP structure Rx
struct udp_pcb *pcbRx;
//Received IP address
ip_addr_t sIPAddress;
///Function pointer to hold receive callback
pal_socket_event_listener pfListen;
///Port for UDP communication
uint16_t wPort;
///Transport Layer Timeout
uint16_t wTimeout;
///Enumeration to indicate Blocking or Non blocking
uint8_t bMode;
} pal_socket_t;
#else
typedef struct pal_socket
{
///Received IP address
char* sIPAddress;
///Port for UDP communication
uint16_t wPort;
///Pointer to the socket for Receiving
SOCKET SocketHdl;
///IPv4 Socket address for Receiving
SOCKADDR_IN sSocketAddrIn;
///Transport Layer Timeout
uint16_t wTimeout;
///Enumeration to indicate Blocking or Non blocking
uint8_t bMode;
} pal_socket_t;
#endif
/**********************************************************************************************************************
* API Prototypes
*********************************************************************************************************************/
/**
* \brief Assign IP address
*/
#ifndef WIN32
int32_t pal_socket_assign_ip_address(const char* p_ip_address,void *p_input_ip_address);
#else
int32_t pal_socket_assign_ip_address(const char_t* p_ip_address,char** p_input_ip_address);
#endif
/**
* \brief Initializes the socket communication structure
*/
int32_t pal_socket_init(pal_socket_t* p_socket);
/**
* \brief Creates server port and bind
*/
int32_t pal_socket_open(pal_socket_t* p_socket,
uint16_t port);
/**
* \brief Creates a client port and connect
*/
int32_t pal_socket_connect(pal_socket_t* p_socket,
uint16_t port);
/**
* \brief Receive data from the client
*/
int32_t pal_socket_listen(pal_socket_t* p_socket, uint8_t *p_data,
uint32_t *p_length);
/**
* \brief Sends the data to the the client
*/
int32_t pal_socket_send(const pal_socket_t* p_socket, uint8_t *p_data,
uint32_t length);
/**
* \brief Closes the socket communication and release the udp port
*/
void pal_socket_close(pal_socket_t* p_socket);
#endif
#endif //_PAL_SOCKET_H_
/**
* @}
*/