From 2c79c15dc9aa4ec7eca454b793bf43a9a3ba85db Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 13 Jan 2019 12:05:18 +0100 Subject: Add NK_connect_with_path to C API NK_connect_with_path corresponds to NitrokeyManager::connect_with_path. --- NK_C_API.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'NK_C_API.h') diff --git a/NK_C_API.h b/NK_C_API.h index b1bdf1e..81da956 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -779,6 +779,14 @@ extern "C" { */ NK_C_API int NK_connect_with_ID(const char* id); + /** + * Connects to a device with the given path. The path is a USB device + * path as returned by hidapi. + * @param path the device path + * @return 1 on successful connection, 0 otherwise + */ + NK_C_API int NK_connect_with_path(const char* path); + /** * Blink red and green LED alternatively and infinitely (until device is reconnected). * @return command processing error code -- cgit v1.2.1 From 5d94dece0392ce0d5486097abf8918b6922f85d2 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 13 Jan 2019 12:05:37 +0100 Subject: Add NK_device_info, NK_list_devices and NK_free_device_info NK_list_devices corresponds to NitrokeyManager::list_devices. It returns a linked list of NK_device_info, which has to be freed using the NK_free_device_info function. --- NK_C_API.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'NK_C_API.h') diff --git a/NK_C_API.h b/NK_C_API.h index 81da956..f17098a 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -57,6 +57,29 @@ extern "C" { NK_STORAGE = 2 }; + /** + * The connection info for a Nitrokey device as a linked list. + */ + struct NK_device_info { + /** + * The model of the Nitrokey device. + */ + enum NK_device_model model; + /** + * The USB device path for NK_connect_with_path. + */ + char* path; + /** + * The serial number. + */ + char* serial_number; + /** + * The pointer to the next element of the linked list or null + * if this is the last element in the list. + */ + struct NK_device_info* next; + }; + /** * Stores the status of a Storage device. */ @@ -768,6 +791,19 @@ extern "C" { */ NK_C_API char* NK_list_devices_by_cpuID(); + /** + * Returns a linked list of all connected devices, or null if no devices + * are connected or an error occured. The linked list must be freed by + * calling NK_free_device_info. + * @return a linked list of all connected devices + */ + NK_C_API struct NK_device_info* NK_list_devices(); + + /** + * Free a linked list returned by NK_list_devices. + * @param the linked list to free or null + */ + NK_C_API void NK_free_device_info(struct NK_device_info* device_info); /** * Connects to the device with given ID. ID's list could be created with NK_list_devices_by_cpuID. -- cgit v1.2.1 From be6fd465ded13b4dd5b8ea10834a296efb8f1424 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 14 Jan 2019 19:03:53 +0100 Subject: Return -2 if an error occured in NK_get_progress_bar_value NK_get_progress_bar_value returns the progress value from 0 to 100 or -1 if there is no pending operation. In the previous implementation, it also returned zero if an error occurred, making it impossible to distinguish progress zero and an error. Therefore, we change the return value to -2 if an error occured. --- NK_C_API.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'NK_C_API.h') diff --git a/NK_C_API.h b/NK_C_API.h index b1bdf1e..43e5631 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -747,7 +747,8 @@ extern "C" { /** * Get progress value of current long operation. * Storage only - * @return int in range 0-100 or -1 if device is not busy + * @return int in range 0-100 or -1 if device is not busy or -2 if an + * error occured */ NK_C_API int NK_get_progress_bar_value(); -- cgit v1.2.1 From 46a94679152da263e3e805ec2073359ae60ce6ab Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 14 Jan 2019 20:52:25 +0100 Subject: Add NK_get_SD_usage_data function to C API The NK_get_SD_usage_data function returns the minimum and maximum write level for the SD card. This function cannot be tested due to the missing struct support in the Python tests. --- NK_C_API.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'NK_C_API.h') diff --git a/NK_C_API.h b/NK_C_API.h index b1bdf1e..2d05a15 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -128,6 +128,23 @@ extern "C" { bool stick_initialized; }; + /** + * Data about the usage of the SD card. + */ + struct NK_SD_usage_data { + /** + * The minimum write level, as a percentage of the total card + * size. + */ + uint8_t write_level_min; + /** + * The maximum write level, as a percentage of the total card + * size. + */ + uint8_t write_level_max; + }; + + struct NK_storage_ProductionTest{ uint8_t FirmwareVersion_au8[2]; uint8_t FirmwareVersionInternal_u8; @@ -736,6 +753,17 @@ extern "C" { */ NK_C_API int NK_get_status_storage(struct NK_storage_status* out); + /** + * Get SD card usage attributes. Usable during hidden volumes creation. + * If the command was successful (return value 0), the usage data is + * written to the output pointer’s target. The output pointer must + * not be null. + * Storage only + * @param out the output pointer for the usage data + * @return command processing error code + */ + NK_C_API int NK_get_SD_usage_data(struct NK_SD_usage_data* out); + /** * Get SD card usage attributes as string. * Usable during hidden volumes creation. -- cgit v1.2.1