What is the relation between AES and PTK in WPA2 wifi I know that modern wpa2 wifis use AES key to encrypt data.

a client who has the password, can obtain psk/pmk use it for handshaking . 

so what is the purpose of ptk, and   how AES key is generated?
WPA2 uses either a password or a pre-shared key to create the PMK.

Specifically, the PMK comes from:


If there is a PSK, the PMK is the PSK
A PSK is either a 256-bit key or derived from a passphrase
If a passphrase is used, it generates the PSK using the AP SSID as the salt: PSK = PBKDF2(HMAC−SHA1, Passphrase, SSID, 4096, 256)
If there is no PSK, the PMK is derived using 802.1x EAP exchange, usually RADIUS


Once both the client and AP have the same PMK, they prove to eachother they have matching keys using a 4-way handshake, which is also used to derive the PTK by adding a nonce from each party.

Specifically, the 4-way handshake does the following:


Confirm the client’s knowledge of the PMK
Confirm the AP's knowledge of the PMK
Derive a new and unique PTK
Install encryption and integrity keys
Encrypt transport of the AP generated GTK to the client
Confirm cipher suite selection


The PMK, nonces, and handshake MAC addresses are run through a PRF based on HMAC-SHA1 to derive the 512-bit PTK. During the handshake the AP also transmits the 256-bit GTK, or Group Temporal Key, to the client. The PTK and GTK are split into several components, some of which are used as AES keys for different types of network traffic, and some of which are integrity keys.


KCK = PTK bits 0-127, the key confirmation key
KEK = PTK bits 128-255, the key encryption key
TEK = PTK bits 256-383, the temporal encryption key for unicast traffic
TMK = PTK bits 384-511, the temporal MIC keys for TKIP
GEK = GTK bits 0-127, the group encryption key for multicast traffic
GIK = GTK bits 128-255, the group integrity key for TKIP


When WPA2 is used the cipher is CCMP, which is an AES-CTR based mode with a CBC message authentication, and thus the TKIP integrity keys are not used