In any Pokemon version game (not for 4th generation games) you go to the questionnaire in the Pokemart and type in link together with all.
To get it for the Diamond/Pearl/Platinum game, go to the third floor of Jublife City's TV station, and then go to the man at the bottom. He'll ask you what you think of TV. Say "Everyone" and "Happy", and then say "Wifi" and "Connection". Now get Mystery Gift on the main menu. In HeartGold/SoulSilver, it is automatically unlocked once you start and save a new game file.