Defect and impurity properties of hexagonal boron nitride: A first-principles calculation