+void clr_dbg(char *param){
+ usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_CLR_DBG, 0, 0, NULL, 0, 5000);
+}
+
+void set_secret(char *hex_string){
+ uint8_t buffer[(strlen(hex_string) + 1) / 2];
+ size_t i = 0, length = 0;
+ int8_t t;
+
+ memset(buffer, 0, (strlen(hex_string) + 1) / 2);
+
+ while (hex_string[i]) {
+ t = hex_to_int(hex_string[i]);
+ if (t == -1){
+ break;
+ }
+ if (i & 1) {
+ buffer[length++] |= t;
+ } else {
+ buffer[length] |= t << 4;
+ }
+ }
+
+ usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_SECRET, length * 8, 0, (char*)buffer, length, 5000);
+}
+
+void inc_counter(char *param){
+ usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_INC_COUNTER, 0, 0, NULL, 0, 5000);
+}
+
+void get_counter(char *param){
+ uint32_t counter;
+ int cnt;
+ cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_COUNTER, 0, 0, (char*)&counter, 4, 5000);
+ if (cnt == 4) {
+ printf("internal counter = %"PRId32"\n", counter);
+ } else {
+ fprintf(stderr, "Error: reading %d bytes for counter, expecting 4\n", cnt);
+ }
+}
+
+void reset_counter(char *param){
+ usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_RESET_COUNTER, 0, 0, NULL, 0, 5000);
+}
+
+void get_reset_counter (char *param){
+ uint8_t counter;
+ int cnt;
+ cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_RESET_COUNTER, 0, 0, (char*)&counter, 1, 5000);
+ if (cnt == 1) {
+ printf("internal reset counter = %"PRId8"\n", counter);
+ } else {
+ fprintf(stderr, "Error: reading %d bytes for reset counter, expecting 1\n", cnt);
+ }
+}
+
+void get_digits(char *param){
+ uint8_t digits;
+ int cnt;
+ cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_DIGITS, 0, 0, (char*)&digits, 1, 5000);
+ if (cnt == 1) {
+ printf("digits = %"PRId8"\n", digits);
+ } else {
+ fprintf(stderr, "Error: reading %d bytes for reset counter, expecting 1\n", cnt);
+ }
+}
+
+void set_digits(char *param){
+ long d;
+ d = strtol(param, NULL, 10);
+ if (d > 9 || d < 6) {
+ fprintf(stderr, "Error: <digits> must be in range 6, 7, 8 or 9\n");
+ return;
+ }
+ usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_SET_DIGITS, d, 0, NULL, 0, 5000);
+}
+
+void get_token(char *param){
+ char token[10];
+ int cnt;
+ cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_TOKEN, 0, 0, token, 9, 5000);
+ if (cnt < 9 ) {
+ token[cnt] = '\0';
+ printf("token = %s\n", token);
+ } else {
+ fprintf(stderr, "Error: reading %d bytes for token, expecting max. 9\n", cnt);
+ }
+}
+