Now, you can jailbreak your iPhone 3GS (Old Bootrom) on iOS 4.0.2 using the unofficial release of PwangeTool, As you know, you don't need to update to iOS 4.0.2 as the iPhone dev team announced with PDF which close security holes on all Apple devices! but in case you already upgrade to iOS 4.0.2 and can't downgrade so here's a quick guide to jailbreak your iPhone 3GS on iOS 4.0.2 below,
Step 1: Download and iTunes 9.2.1 from Here, and the Original iOS 4.0.2 from Here
Step 2: Start iTunes, Sync your iPhone with your PC or Mac and backup all your data by Right click on your iPhone and click on "Backup"
Step 3: Now, Download the UnOfficial PwnageTool from Here
Step 4: Launch PwnageTool you have just Downloaded, Then choose your Device and Click on the blue arrow
Step 6: When PwnageTool asks you “Do you have an iPhone contract that would activate normally through iTunes?” Click "No"
Step 8: After choosing your Options, Check on Build and Hit the Blue arrow
Step 10: PwnageTool will now create the custom .ipsw file for your iPhone which will be jailbroken.
Step 12: iTunes now should ask you about the .ipsw file, head up it to the created custom firmware by PwnageTool
In case you want to jailbreak iPhone 3G on iOS 4.0.2 you can use Redsn0w for both Windows and Mac by following the guide posted here.After done with the jailbreak, then you can follow the step by step guide posted here to unlock any device using Ultrasn0w 1.0-1.