-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added demo framework, added NVM demo, run NVM demo in posix/tcp tests
- Loading branch information
Showing
14 changed files
with
242 additions
and
12 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "client_demo_driver.h" | ||
#include "client_nvm.h" | ||
|
||
int client_demo_driver(whClientContext* clientContext) | ||
{ | ||
int rc = 0; | ||
|
||
rc = client_nvm(clientContext); | ||
if (rc != 0) { | ||
return rc; | ||
} | ||
|
||
return rc; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef CLIENT_DEMO_DRIVER_H_ | ||
#define CLIENT_DEMO_DRIVER_H_ | ||
|
||
#include "wolfhsm/wh_client.h" | ||
|
||
int client_demo_driver(whClientContext* clientContext); | ||
|
||
#endif /* CLIENT_DEMO_DRIVER_H_ */ |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include "wolfhsm/wh_client.h" | ||
#include "wolfhsm/wh_error.h" | ||
|
||
/** | ||
* @brief Demonstrates use of client NVM API | ||
* @param clientContext an initialized client context | ||
* @return 0 on success, error code on failure | ||
*/ | ||
int client_nvm(whClientContext* clientContext) | ||
{ | ||
const int NUM_OBJECTS = 3; | ||
|
||
int32_t rc; | ||
int32_t serverRc; | ||
uint32_t availSize, reclaimSize; | ||
whNvmId availObjects, reclaimObjects; | ||
|
||
whNvmId objectIds[] = {1, 2, 3}; | ||
uint8_t labels[][6] = {"label1", "label2", "label3"}; | ||
uint8_t data[][6] = {"data1", "data2", "data3"}; | ||
uint8_t readData[6]; | ||
whNvmSize dataLen = 6; | ||
whNvmSize readLen; | ||
|
||
if (clientContext == NULL) { | ||
printf("Client context is NULL\n"); | ||
return WH_ERROR_BADARGS; | ||
} | ||
|
||
/* Initialize NVM */ | ||
rc = wh_Client_NvmInit(clientContext, &serverRc, NULL, NULL); | ||
if (rc != 0 || serverRc != 0) { | ||
printf("NVM Init failed with error code: %d, server error code: %d\n", | ||
rc, serverRc); | ||
return (rc != 0) ? rc : serverRc; | ||
} | ||
printf("NVM Initialized successfully\n"); | ||
|
||
/* Add multiple objects, reading back each one and comparing the data | ||
* against what we wrote */ | ||
for (int i = 0; i < NUM_OBJECTS; i++) { | ||
/* Add an object */ | ||
rc = wh_Client_NvmAddObject(clientContext, objectIds[i], | ||
WOLFHSM_NVM_ACCESS_ANY, | ||
WOLFHSM_NVM_FLAGS_ANY, sizeof(labels[i]), | ||
labels[i], dataLen, data[i], &serverRc); | ||
if (rc != 0 || serverRc != 0) { | ||
printf("Add Object %d failed with error code: %d, server error " | ||
"code: %d\n", | ||
objectIds[i], rc, serverRc); | ||
return (rc != 0) ? rc : serverRc; | ||
} | ||
printf("Object %d added successfully\n", objectIds[i]); | ||
|
||
/* Read the object data */ | ||
rc = wh_Client_NvmRead(clientContext, objectIds[i], 0, dataLen, | ||
&serverRc, &readLen, readData); | ||
if (rc != 0 || serverRc != 0) { | ||
printf("Read Object %d failed with error code: %d, server error " | ||
"code: %d\n", | ||
objectIds[i], rc, serverRc); | ||
return (rc != 0) ? rc : serverRc; | ||
} | ||
printf("Object %d read successfully: Data=%s\n", objectIds[i], | ||
readData); | ||
|
||
/* Ensure data we read matches data we wrote */ | ||
if (memcmp(data[i], readData, dataLen) != 0) { | ||
printf("Readback check failed for Object %d: Data read does not " | ||
"match data written\n", | ||
objectIds[i]); | ||
return WH_ERROR_ABORTED; | ||
} | ||
printf("Readback check passed for Object %d: Data read matches data " | ||
"written\n", | ||
objectIds[i]); | ||
} | ||
|
||
/* Get available objects */ | ||
rc = | ||
wh_Client_NvmGetAvailable(clientContext, &serverRc, &availSize, | ||
&availObjects, &reclaimSize, &reclaimObjects); | ||
if (rc != 0 || serverRc != 0) { | ||
printf("Get Available Objects failed with error code: %d, server error " | ||
"code: %d\n", | ||
rc, serverRc); | ||
return (rc != 0) ? rc : serverRc; | ||
} | ||
printf("Available Objects retrieved successfully: Available Size=%d, " | ||
"Available Objects=%d, Reclaim Size=%d, Reclaim Objects=%d\n", | ||
availSize, availObjects, reclaimSize, reclaimObjects); | ||
|
||
/* Delete one object */ | ||
rc = wh_Client_NvmDestroyObjects(clientContext, 1, objectIds, 0, NULL, | ||
&serverRc); | ||
if (rc != 0 || serverRc != 0) { | ||
printf("Delete Objects failed with error code: %d, server error code: " | ||
"%d\n", | ||
rc, serverRc); | ||
return (rc != 0) ? rc : serverRc; | ||
} | ||
printf("Objects deleted successfully\n"); | ||
|
||
/* Delete multiple objects */ | ||
rc = wh_Client_NvmDestroyObjects(clientContext, NUM_OBJECTS - 1, | ||
&objectIds[1], 0, NULL, &serverRc); | ||
if (rc != 0 || serverRc != 0) { | ||
printf("Delete Objects failed with error code: %d, server error code: " | ||
"%d\n", | ||
rc, serverRc); | ||
return (rc != 0) ? rc : serverRc; | ||
} | ||
printf("Objects deleted successfully\n"); | ||
|
||
/* Reclaim space */ | ||
rc = | ||
wh_Client_NvmDestroyObjects(clientContext, 0, NULL, 0, NULL, &serverRc); | ||
if (rc != 0 || serverRc != 0) { | ||
printf("Reclaim Objects failed with error code: %d, server error code: " | ||
"%d\n", | ||
rc, serverRc); | ||
return (rc != 0) ? rc : serverRc; | ||
} | ||
printf("Reclaimed space successfully\n"); | ||
|
||
/* Cleanup NVM */ | ||
rc = wh_Client_NvmCleanup(clientContext, &serverRc); | ||
if (rc != 0 || serverRc != 0) { | ||
printf( | ||
"NVM Cleanup failed with error code: %d, server error code: %d\n", | ||
rc, serverRc); | ||
return (rc != 0) ? rc : serverRc; | ||
} | ||
printf("NVM Cleaned up successfully\n"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef CLIENT_NVM_H_ | ||
#define CLIENT_NVM_H_ | ||
|
||
#include "wolfhsm/wh_client.h" | ||
|
||
int client_nvm(whClientContext* clientContext); | ||
|
||
#endif /* CLIENT_NVM_H_ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters