Frame synchronization for variable-length packets