The BlackRa1n jailbreak has just been released, but it requires you to update your iDevice to OS 3.1.2 before you can jailbreak it. PwnageTool is a utility that helps you solve this problem neatly. You can find the guide on how to jailbreak an iPhone 3GS or 3G running OS 3.1.2 using PwnageTool 3.1.4 on Mac OS X and then unlock it by yourself here.