Support encryption in AP mode

The main purpose of this patch set is to enable encryption in AP mode
Also one error case during join was added.