chardev: use a state machine for socket connection state