Which layer of Earth is composed primarily of iron and nickel and is responsible for generating Earth's magnetic field?