60 lines
2.8 KiB
C
60 lines
2.8 KiB
C
/* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
|
source code may only be used and distributed under the Widevine Master
|
|
License Agreement. */
|
|
|
|
#ifndef OEMCRYPTO_TA_OEMCRYPTO_SESSION_TABLE_H_
|
|
#define OEMCRYPTO_TA_OEMCRYPTO_SESSION_TABLE_H_
|
|
|
|
#include "OEMCryptoCENC.h"
|
|
#include "oemcrypto_config_interface.h"
|
|
#include "oemcrypto_session.h"
|
|
|
|
typedef struct SessionTable {
|
|
OEMCryptoSession sessions[MAX_NUMBER_OF_SESSIONS];
|
|
uint32_t first_free_session;
|
|
uint32_t next_free_session[MAX_NUMBER_OF_SESSIONS];
|
|
bool is_free[MAX_NUMBER_OF_SESSIONS];
|
|
} SessionTable;
|
|
|
|
/* Initializes the session table for future OpenSession calls. Returns
|
|
OEMCrypto_ERROR_INIT_FAILED if the session table has already been initialized
|
|
and OEMCrypto_SUCCESS otherwise. */
|
|
OEMCryptoResult InitializeSessionTable(void);
|
|
|
|
/* Gets the max number of sessions. */
|
|
uint32_t MaxNumberOfSessions(void);
|
|
|
|
/* Gets the number of open sessions. Returns OEMCrypto_ERROR_SYSTEM_INVALIDATED
|
|
if the session table has not been initialized and OEMCrypto_SUCCESS
|
|
otherwise.
|
|
Caller retains ownership of |num_open_sessions| and it must not be NULL. */
|
|
OEMCryptoResult NumberOfOpenSessions(uint32_t* num_open_sessions);
|
|
|
|
/* Attempts to grab an open entry in the session table and set |index| to the
|
|
entry position. Returns OEMCrypto_ERROR_SYSTEM_INVALIDATED if the session
|
|
table has not been initialized and OEMCrypto_ERROR_TOO_MANY_SESSIONS if there
|
|
are no sessions left to grab. Returns OEMCrypto_SUCCESS otherwise.
|
|
Caller retains ownership of |index| and it must not be NULL. */
|
|
OEMCryptoResult GrabSession(uint32_t* index);
|
|
|
|
/* Sets session to the session at |index| in the session table if it is free.
|
|
Returns OEMCrypto_ERROR_SYSTEM_INVALIDATED if the session table has not been
|
|
initialized and OEMCrypto_ERROR_INVALID_SESSION if the session has not been
|
|
grabbed or if the index is invalid. Returns OEMCrypto_SUCCESS otherwise.
|
|
Caller retains ownership of |session| and it must not be NULL. */
|
|
OEMCryptoResult GetSession(uint32_t index, OEMCryptoSession** session);
|
|
|
|
/* Given a non-free session |index|, attempts to free it so it can be reused.
|
|
Returns OEMCrypto_ERROR_SYSTEM_INVALIDATED if the session table has not been
|
|
initialized and OEMCrypto_ERROR_INVALID_SESSION if the session has not been
|
|
grabbed or if the index is invalid. Returns OEMCrypto_SUCCESS otherwise. */
|
|
OEMCryptoResult FreeSession(uint32_t index);
|
|
|
|
/* Clears and cleans up the session table. The session table must be
|
|
reinitialized to be used. Returns OEMCrypto_ERROR_TERMINATE_FAILED if the
|
|
table has not been initialized or if there are any active sessions still.
|
|
Returns OEMCrypto_SUCCESS otherwise. */
|
|
OEMCryptoResult TerminateSessionTable(void);
|
|
|
|
#endif /* OEMCRYPTO_TA_OEMCRYPTO_SESSION_TABLE_H_ */
|