C implementation of protocol

Signed-off-by: Mika Tammi <mikatammi@gmail.com>