state machine for packets