Photon exchange and entanglement formation during transmission through a rectangular quantum barrier