Characterization of graphs with Hall index 2