The variable state is not a global function. So its value needs to be returned from each function which might alter the state. For now only two states exist: WAIT_RST, WAIT_CMD FIXME: Probably there is a more elegant way to do that