Nitrokey / nitrokey-pro-firmware

Firmware for the Nitrokey Pro device
GNU General Public License v3.0
118 stars 21 forks source link

[HSM] Add debugging functions #18

Open FlorianUekermann opened 8 years ago

FlorianUekermann commented 8 years ago

Adds two simple functions for debugging.

Debugf works exactly like printf. Debug takes an array of bytes and a length. Example code on device:

Debugf("Hello world %d", 123)

Output on host:

$python debug.py
Hello world 123

Debugging is disabled by default. Both functions do nothing unless debugging in is enabled by uncommenting line 8 in debug.h (this should be done via make target at some point)

To try it uncomment line 8 in src/inc/debug.h and run "python debug.py" in the repository root. Then plug in the Nitrokey HSM. You should see this as soon as the device is done with the basic setup:

Entering loop after USB startup

This code should have no side effects and be compatible with the master branch as well. As long as pyusb is installed it should work on every OS ('apt-get install python-usb'). More extensive documentation in debug.py and debug.h.

Don't use floating point math (that means don't print them either).

szszszsz commented 8 years ago

Hi @MaVo159 ! We should add guards also to interface creation, so it would not be available in release binary even when nothing is printed there. Additional interfaces could make device blocked on VM environments.

FlorianUekermann commented 8 years ago

That is definitely the plan. I would like to wait with that until I have time to merge the two branches though, since I'll need to do something more elegant for the device descriptor anyway. Unless there are immediate plans to release a new version firmware version of course. I wouldn't expect VM problems, because this is not an HID interface. Or have you encountered VMs that don't forward devices for other reasons.

szszszsz commented 8 years ago

OK! As for VMs I have not heard about other block causes, just blind guess.