75 KineticClient * client;
78 KineticSession * session;
79 KineticSession * adminSession;
81 uint8_t hmacKeyData[1024];
84 int64_t newClusterVersion;
87 char deviceLogName[64];
91 uint8_t keyData[1024];
92 uint8_t tagData[1024];
93 uint8_t newVersionData[1024];
94 uint8_t versionData[1024];
98 #define OPT_MIN OPT_NOOP
105 struct UtilConfig * cfg);
107 struct UtilConfig * cfg);
109 struct UtilConfig * cfg,
112 const char * version,
122 printf(
"Usage: %s --<cmd> [options...]\n", exec);
123 printf(
"%s --help\n", exec);
127 " [--host <ip|hostname>] [--port <port>] [--clusterversion <clusterversion>]\n", exec);
128 printf(
"%s --put --key <key> --value <value>"
129 " [--host <ip|hostname>] [--port <port>] [--clusterversion <clusterversion>]\n", exec);
130 printf(
"%s --get --key <key>"
131 " [--host <ip|hostname>] [--port <port>] [--clusterversion <clusterversion>]\n", exec);
132 printf(
"%s --getnext --key <key>"
133 " [--host <ip|hostname>] [--port <port>] [--clusterversion <clusterversion>]\n", exec);
134 printf(
"%s --getprevious --key <key>"
135 " [--host <ip|hostname>] [--port <port>] [--clusterversion <clusterversion>]\n", exec);
136 printf(
"%s --delete --key <key>"
137 " [--host <ip|hostname>] [--port <port>] [--clusterversion <clusterversion>]\n", exec);
140 printf(
"%s --getlog --logtype <utilizations|temperatures|capacities|configuration|statistics|messages|limits>"
141 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
142 printf(
"%s --getdevicespecificlog --devicelogname <name|ID>"
143 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
144 printf(
"%s --setclusterversion --newclusterversion <newclusterversion>"
145 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
146 printf(
"%s --seterasepin --pin <oldpin> --newpin <newerasepin>"
147 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
148 printf(
"%s --instanterase --pin <erasepin>"
149 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
150 printf(
"%s --secureerase --pin <erasepin>"
151 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
152 printf(
"%s --setlockpin --pin <oldpin>> <--newpin <newpin>"
153 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
154 printf(
"%s --lockdevice --pin <lockpin>"
155 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
156 printf(
"%s --unlockdevice --pin <lockpin>"
157 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
158 printf(
"%s --setacl --file <acl_json_file>"
159 " [--host <ip|hostname>] [--tlsport <tlsport>] [--clusterversion <clusterversion>]\n", exec);
160 printf(
"%s --updatefirmware --file <file> --pin <pin>"
161 " [--host <ip|hostname>] [--port <port>] [--clusterversion <clusterversion>] \n", exec);
167 int main(
int argc,
char** argv)
169 struct UtilConfig cfg;
170 memset(&cfg, 0,
sizeof(cfg));
175 fprintf(stderr,
"No operation specified!\n");
183 .logLevel = cfg.logLevel,
186 if (cfg.client == NULL) {
187 fprintf(stderr,
"Failed creating a client instance!\n");
194 fprintf(stderr,
"Failed connecting to host %s:%d (status: %s)\n",
195 cfg.config.host, cfg.config.port,
201 cfg.adminConfig.useSsl =
true;
204 fprintf(stderr,
"Failed connecting to host %s:%d (status: %s)\n",
205 cfg.config.host, cfg.config.port,
214 fprintf(stderr,
"Failed executing operation!\n");
240 printf(
"Device Utilizations:\n");
242 printf(
" %s: %.2f %%\n",
249 printf(
"Device Capacities:\n");
255 printf(
"Device Temperatures:\n");
257 printf(
" %s: current=%.1f, min=%.1f, max=%.1f, target=%.1f\n",
265 printf(
"Device Configuration:\n");
278 printf(
" interface: %s\n", iface->
name);
280 memset(buf, 0,
sizeof(buf));
282 printf(
" MAC: %s\n", buf);
283 memset(buf, 0,
sizeof(buf));
285 printf(
" ipv4Address: %s\n", buf);
286 memset(buf, 0,
sizeof(buf));
288 printf(
" ipv6Address: %s\n", buf);
295 printf(
"Device Statistics:\n");
297 printf(
" %s: count=%llu, bytes=%llu\n",
305 printf(
"Device Log Messages:\n"); {
308 printf(
" %s\n", msgs);
314 printf(
"Device Limits:\n");
329 fprintf(stderr,
"Unknown log type! (%d)\n", type);
341 str =
"loglevel";
break;
347 str =
"tlsport";
break;
349 str =
"identity";
break;
353 str =
"value";
break;
355 str =
"clusterversion";
break;
359 str =
"hmackey";
break;
361 str =
"newclusterversion";
break;
365 str =
"newpin";
break;
367 str =
"logtype";
break;
375 str =
"delete";
break;
377 str =
"getnext";
break;
379 str =
"getprevious";
break;
381 str =
"getlog";
break;
383 str =
"getdevicespecificlog";
break;
385 str =
"seterasepin";
break;
387 str =
"instanterase";
break;
389 str =
"secureerase";
break;
391 str =
"setlockpin";
break;
393 str =
"lockdevice";
break;
395 str =
"unlockdevice";
break;
397 str =
"setclusterversion";
break;
399 str =
"setacl";
break;
401 str =
"updatefirmware";
break;
404 str =
"<UNKNOWN OPTION>";
break;
414 struct UtilConfig * cfg)
425 printf(
"NoOp operation completed successfully."
426 " Kinetic Device is alive and well!\n"); }
432 printf(
"Put operation completed successfully."
433 " Your data has been stored!\n");
441 printf(
"Get executed successfully.\n");
449 printf(
"GetNext executed successfully.\n");
457 printf(
"GetPrevious executed successfully.\n");
465 printf(
"Delete executed successfully. The entry has been destroyed!\n");
473 printf(
"GetLog executed successfully.\n"
474 "The device log info has been retrieved!\n");
480 if (strlen(cfg->deviceLogName) == 0) {
481 fprintf(stderr,
"Device-specific log type requires '--devicelogname' to be set!\n");
484 tmpArray.
data = (uint8_t*)cfg->deviceLogName;
485 tmpArray.
len = strlen(cfg->deviceLogName);
488 printf(
"GetDeviceSpecificLog executed successfully."
489 "The device-specific device log info has been retrieved!\n");
490 printf(
"Device-Specific Log Info:\n");
493 printf(
" %s\n", dev);
497 fprintf(stderr,
"The specified device-specific log '%s' was not found on the device!\n", cfg->deviceLogName);
507 printf(
"SetErasePin executed successfully.\n"
508 "The kinetic device erase pin has been changed!\n"); }
515 printf(
"InstantErase executed successfully.\n"
516 "The kinetic device has been erased!\n"); }
523 printf(
"SecureErase executed successfully.\n"
524 "The kinetic device has been erased!\n"); }
532 printf(
"SetLockPin executed successfully.\n"
533 "The kinetic device lock/unlock pin has been changed!\n"); }
540 printf(
"LockDevice executed successfully.\n"
541 "The kinetic device is now locked!\n"); }
548 printf(
"UnlockDevice executed successfully.\n"
549 "The kinetic device is now unlocked!\n"); }
555 printf(
"SetClusterVersion executed successfully.\n"
556 "The kinetic device's cluster version has been updated!\n"); }
562 printf(
"SetACL executed successfully.\n"
563 "The kinetic device ACLs have been replaced!\n"); }
569 printf(
"SecureErase executed successfully.\n"
570 "The kinetic device has been restored to empty status!\n"); }
574 fprintf(stderr,
"Specified operation '%d' is invalid!\n",
581 fprintf(stderr,
"\nERROR: Operation '%s' failed with status '%s'\n",
589 const char* version,
KineticAlgorithm algorithm,
bool force,
const char* value)
599 .algorithm = algorithm,
608 struct UtilConfig * cfg)
617 int64_t clusterVersion;
621 char deviceLogName[64];
635 .hmacKey =
"asdfasdf",
636 .logType =
"utilizations",
638 .tag =
"SomeTagValue",
645 struct option long_options[] = {
652 {
"put", no_argument, 0,
OPT_PUT},
653 {
"get", no_argument, 0,
OPT_GET},
671 {
"host", required_argument, 0,
OPT_HOST},
672 {
"port", required_argument, 0,
OPT_PORT},
677 {
"file", required_argument, 0,
OPT_FILE},
679 {
"pin", required_argument, 0,
OPT_PIN},
683 {
"key", required_argument, 0,
OPT_KEY},
684 {
"value", required_argument, 0,
OPT_VALUE},
691 int option, optionIndex = 0;
692 while ((option = getopt_long(argc, argv,
"?lhptics:", long_options, &optionIndex)) != -1) {
696 if (long_options[optionIndex].flag != 0) {
break;}
700 opts.logLevel = atoi(optarg);
703 strncpy(opts.host, optarg,
sizeof(opts.host));
706 opts.port = atoi(optarg);
709 opts.tlsPort = atoi(optarg);
712 opts.identity = atoi(optarg);
715 strncpy(opts.hmacKey, optarg,
sizeof(opts.hmacKey)-1);
718 strncpy(opts.key, optarg,
sizeof(opts.key)-1);
721 strncpy(opts.value, optarg,
sizeof(opts.value)-1);
724 opts.clusterVersion = (int64_t)atol(optarg);
727 cfg->newClusterVersion = (int64_t)atol(optarg);
730 strncpy(cfg->file, optarg,
sizeof(cfg->file)-1);
733 strncpy(cfg->pin, optarg,
sizeof(cfg->pin)-1);
736 strncpy(cfg->newPin, optarg,
sizeof(cfg->newPin)-1);
739 strncpy(opts.logType, optarg,
sizeof(opts.logType)-1);
742 strncpy(cfg->deviceLogName, optarg,
sizeof(cfg->deviceLogName)-1);
762 if ((
int)opts.opID == 0) {
766 fprintf(stderr,
"Multiple operations specified!\n");
779 cfg->logLevel = opts.logLevel;
784 .clusterVersion = opts.clusterVersion,
785 .identity = opts.identity,
788 memcpy(cfg->hmacKeyData, opts.hmacKey, strlen(opts.hmacKey));
789 strncpy(cfg->config.host, opts.host,
sizeof(cfg->config.host)-1);
792 cfg->adminConfig = cfg->config;
793 cfg->adminConfig.port = opts.tlsPort;
794 cfg->adminConfig.useSsl =
true;
798 opts.key, opts.tag, opts.version, opts.algorithm, opts.force, opts.value);
800 cfg->opID = opts.opID;
803 if (strcmp(
"utilizations", opts.logType) == 0) {
806 else if (strcmp(
"temperatures", opts.logType) == 0) {
809 else if (strcmp(
"capacities", opts.logType) == 0) {
812 else if (strcmp(
"configuration", opts.logType) == 0) {
815 else if (strcmp(
"statistics", opts.logType) == 0) {
818 else if (strcmp(
"messages", opts.logType) == 0) {
821 else if (strcmp(
"limits", opts.logType) == 0) {
825 fprintf(stderr,
"Invalid log info type: %s\n", opts.logType);
Structure for handling generic arrays of bytes.
void PrintUsage(const char *exec)
uint32_t maxIdentityCount
static int ParseOptions(const int argc, char **const argv, struct UtilConfig *cfg)
KineticStatus KineticClient_CreateSession(KineticSessionConfig *const config, KineticClient *const client, KineticSession **session)
Creates a session with the Kinetic Device per specified configuration.
KineticStatus KineticAdminClient_SetLockPin(KineticSession *const session, ByteArray old_pin, ByteArray new_pin)
Sets the lock PIN of the Kinetic Device.
Structure used to specify the configuration for a session.
KineticStatus KineticClient_GetPrevious(KineticSession *const session, KineticEntry *const entry, KineticCompletionClosure *closure)
Executes a GETPREVIOUS operation to retrieve the next entry from the Kinetic Device.
KineticStatus KineticAdminClient_UnlockDevice(KineticSession *const session, ByteArray pin)
Executes an UNLOCK operation to unlock the Kinetic device.
#define KINETIC_OBJ_SIZE
Max object/value size.
KineticMessageType messageType
#define KINETIC_MAX_KEY_LEN
Max key length.
uint32_t maxOutstandingWriteRequests
char * protocolCompilationDate
KineticLogInfo_Capacity * capacity
Log info network interface entry.
KineticStatus KineticClient_NoOp(KineticSession *const session)
Executes a NOOP operation to test whether the Kinetic Device is operational.
KineticLogInfo_Configuration * configuration
KineticStatus KineticClient_Delete(KineticSession *const session, KineticEntry *const entry, KineticCompletionClosure *closure)
Executes a DELETE operation to delete an entry from the Kinetic Device.
KineticAlgorithm
Enumeration of encryption/checksum key algorithms.
uint32_t maxOutstandingReadRequests
ByteArray array
ByteArray holding allocated array w/length = allocated size.
KineticStatus KineticAdminClient_SetACL(KineticSession *const session, const char *ACLPath)
Executes a SECURITY operation, setting one or more ACLs.
KineticLogInfo_Limits * limits
KineticStatus KineticAdminClient_SetErasePin(KineticSession *const session, ByteArray old_pin, ByteArray new_pin)
Sets the erase PIN of the Kinetic Device.
const char * Kinetic_GetStatusDescription(KineticStatus status)
Provides a string representation for a KineticStatus code.
KineticLogInfo_Type
Log info type.
The requested object does not exist.
ByteBuffer ByteBuffer_Create(void *data, size_t max_len, size_t used)
Base log info structure which is allocated by client and passed to KineticAdminClient_GetLog.
KineticStatus KineticAdminClient_GetDeviceSpecificLog(KineticSession *const session, ByteArray name, KineticLogInfo **info, KineticCompletionClosure *closure)
Executes a GETLOG operation to retrieve device-specific log info from the Kinetic Device via name/key...
KineticLogInfo_Interface * interfaces
KineticLogInfo_Device * device
#define KINETIC_PORT
Default kinetic port.
KineticStatus KineticAdminClient_InstantErase(KineticSession *const session, ByteArray pin)
Executes an InstantErase operation to erase all data from the Kinetic device.
KineticStatus KineticAdminClient_UpdateFirmware(KineticSession *const session, char const *const fw_path)
Executes a Firmware Download operation to update the firmware on the Kinetic device.
size_t len
Number of bytes in the data field.
#define KINETIC_TLS_PORT
Default kinetic TLS port.
KineticStatus KineticAdminClient_SecureErase(KineticSession *const session, ByteArray pin)
Executes a SecureErase command to erase all data from the Kinetic device.
KineticLogInfo_Utilization * utilizations
KineticLogInfo_Statistics * statistics
const char * logFile
Path to log file. Specify 'stdout' to log to STDOUT or NULL to disable logging.
KineticLogInfo_Temperature * temperatures
ByteBuffer key
Key associated with the object stored on disk.
uint8_t * data
Pointer to an allocated array of data bytes.
const char * KineticMessageType_GetName(KineticMessageType type)
Provides a string representation for a Kinetic message type.
KineticStatus KineticAdminClient_LockDevice(KineticSession *const session, ByteArray pin)
Executes a LOCK operation to lock the Kinetic device.
uint64_t nominalCapacityInBytes
static void PrintLogInfo(KineticLogInfo_Type type, KineticLogInfo *info)
Status not available (no reponse/status available)
ByteArray ByteArray_Create(void *data, size_t len)
char * protocolSourceHash
static const char * GetOptString(OptionID opt_id)
KineticStatus KineticClient_Get(KineticSession *const session, KineticEntry *const entry, KineticCompletionClosure *closure)
Executes a GET operation to retrieve an entry from the Kinetic Device.
KineticStatus
Kinetic status codes.
KineticStatus KineticClient_Put(KineticSession *const session, KineticEntry *const entry, KineticCompletionClosure *closure)
Executes a PUT operation to store/update an entry on the Kinetic Device.
uint32_t maxKeyRangeCount
static void ConfigureEntry(struct UtilConfig *cfg, const char *key, const char *tag, const char *version, KineticAlgorithm algorithm, bool force, const char *value)
Configuration values for the KineticClient connection.
static KineticStatus ExecuteOperation(struct UtilConfig *cfg)
KineticClient * KineticClient_Init(KineticClientConfig *config)
Initializes the Kinetic API and configures logging.
size_t bytesUsed
Reflects the number of bytes used from the array
KineticStatus KineticClient_GetNext(KineticSession *const session, KineticEntry *const entry, KineticCompletionClosure *closure)
Executes a GETNEXT operation to retrieve the next entry from the Kinetic Device.
static void PrintEntry(KineticEntry *entry)
int main(int argc, char **argv)
KineticStatus KineticAdminClient_SetClusterVersion(KineticSession *const session, int64_t version)
Updates the cluster version of the Kinetic Device.
ByteBuffer ByteBuffer_CreateAndAppendCString(void *data, size_t max_len, const char *value)
KineticStatus KineticAdminClient_GetLog(KineticSession *const session, KineticLogInfo_Type type, KineticLogInfo **info, KineticCompletionClosure *closure)
Executes a GETLOG operation to retrieve specific configuration and/or operational data from the Kinet...
ByteBuffer value
Value data associated with the key.