If you have already jailbreak your iPhone using JailbreakMe, which is I posted previously. For those who have not jailbreak their iPhone and don’t know about JailbreakMe yet; JailBreakMe 2.0 is tool to jailbreak all iPhone running iOS 4.0.1 and below, also any iPad on iOS 3.2.1 and below. The great thing about JailBreakMe you can jailbreak your device simply by visiting the official website, not need PC or Mac, just internet and Safari.
Visit Video Tutorial To Jailbreak iPhone Using JailbreakMe For iOS 4.0.0 Or 4.0.1

After your iPhone is fully jailbroken, you can go to the following link to unlock your iPhone 3GS and 3GS running iOS 4.O.1 and 4.0 at whatever baseband:
