Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------------------------------------------------------------*/
- /*
- * Parse, and display the results of a WPA or WPA2 IE.
- *
- */
- static inline void
- iw_print_ie_wpa(unsigned char * iebuf,
- int buflen)
- {
- int ielen = iebuf[1] + 2;
- int offset = 2; /* Skip the IE id, and the length. */
- unsigned char wpa1_oui[3] = {0x00, 0x50, 0xf2};
- unsigned char wpa2_oui[3] = {0x00, 0x0f, 0xac};
- unsigned char * wpa_oui;
- int i;
- uint16_t ver = 0;
- uint16_t cnt = 0;
- if(ielen > buflen)
- ielen = buflen;
- #ifdef DEBUG
- /* Debugging code. In theory useless, because it's debugged ;-) */
- printf("IE raw value %d [%02X", buflen, iebuf[0]);
- for(i = 1; i < buflen; i++)
- printf(":%02X", iebuf[i]);
- printf("]\n");
- #endif
- switch(iebuf[0])
- {
- case 0x30: /* WPA2 */
- /* Check if we have enough data */
- if(ielen < 4)
- {
- iw_print_ie_unknown(iebuf, buflen);
- return;
- }
- wpa_oui = wpa2_oui;
- break;
- case 0xdd: /* WPA or else */
- wpa_oui = wpa1_oui;
- /* Not all IEs that start with 0xdd are WPA.
- * So check that the OUI is valid. Note : offset==2 */
- if((ielen < 8)
- || (memcmp(&iebuf[offset], wpa_oui, 3) != 0)
- || (iebuf[offset + 3] != 0x01))
- {
- iw_print_ie_unknown(iebuf, buflen);
- return;
- }
- /* Skip the OUI type */
- offset += 4;
- break;
- default:
- return;
- }
- /* Pick version number (little endian) */
- ver = iebuf[offset] | (iebuf[offset + 1] << 8);
- offset += 2;
- if(iebuf[0] == 0xdd)
- printf("WPA Version %d\n", ver);
- if(iebuf[0] == 0x30)
- printf("IEEE 802.11i/WPA2 Version %d\n", ver);
- /* From here, everything is technically optional. */
- /* Check if we are done */
- if(ielen < (offset + 4))
- {
- /* We have a short IE. So we should assume TKIP/TKIP. */
- printf(" Group Cipher : TKIP\n");
- printf(" Pairwise Cipher : TKIP\n");
- return;
- }
- /* Next we have our group cipher. */
- if(memcmp(&iebuf[offset], wpa_oui, 3) != 0)
- {
- printf(" Group Cipher : Proprietary\n");
- }
- else
- {
- printf(" Group Cipher :");
- iw_print_value_name(iebuf[offset+3],
- iw_ie_cypher_name, IW_IE_CYPHER_NUM);
- printf("\n");
- }
- offset += 4;
- /* Check if we are done */
- if(ielen < (offset + 2))
- {
- /* We don't have a pairwise cipher, or auth method. Assume TKIP. */
- printf(" Pairwise Ciphers : TKIP\n");
- return;
- }
- /* Otherwise, we have some number of pairwise ciphers. */
- cnt = iebuf[offset] | (iebuf[offset + 1] << 8);
- offset += 2;
- printf(" Pairwise Ciphers (%d) :", cnt);
- if(ielen < (offset + 4*cnt))
- return;
- for(i = 0; i < cnt; i++)
- {
- if(memcmp(&iebuf[offset], wpa_oui, 3) != 0)
- {
- printf(" Proprietary");
- }
- else
- {
- iw_print_value_name(iebuf[offset+3],
- iw_ie_cypher_name, IW_IE_CYPHER_NUM);
- }
- offset+=4;
- }
- printf("\n");
- /* Check if we are done */
- if(ielen < (offset + 2))
- return;
- /* Now, we have authentication suites. */
- cnt = iebuf[offset] | (iebuf[offset + 1] << 8);
- offset += 2;
- printf(" Authentication Suites (%d) :", cnt);
- if(ielen < (offset + 4*cnt))
- return;
- for(i = 0; i < cnt; i++)
- {
- if(memcmp(&iebuf[offset], wpa_oui, 3) != 0)
- {
- printf(" Proprietary");
- }
- else
- {
- iw_print_value_name(iebuf[offset+3],
- iw_ie_key_mgmt_name, IW_IE_KEY_MGMT_NUM);
- }
- offset+=4;
- }
- printf("\n");
- /* Check if we are done */
- if(ielen < (offset + 1))
- return;
- /* Otherwise, we have capabilities bytes.
- * For now, we only care about preauth which is in bit position 1 of the
- * first byte. (But, preauth with WPA version 1 isn't supposed to be
- * allowed.) 8-) */
- if(iebuf[offset] & 0x01)
- {
- printf(" Preauthentication Supported\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment