added the FSM code
Signed-off-by: timothy <timothy@timothy-linux.(none)>