Commit 35f95889 authored by Bruno Randolf's avatar Bruno Randolf

parse information elements on our own

parent 8d3227fa
......@@ -24,108 +24,6 @@
#include "util.h"
/* from mac80211/ieee80211_sta.c, modified */
void
ieee802_11_parse_elems(unsigned char *start, size_t len, struct packet_info *p)
{
int left = len;
unsigned char *pos = start;
while (left >= 2) {
u8 id, elen;
id = *pos++;
elen = *pos++;
left -= 2;
if (elen > left)
return;
switch (id) {
case WLAN_EID_SSID:
if (elen < MAX_ESSID_LEN-1) {
memcpy(p->wlan_essid, pos, elen);
p->wlan_essid[elen] = '\0';
} else {
memcpy(p->wlan_essid, pos, MAX_ESSID_LEN-1);
p->wlan_essid[MAX_ESSID_LEN-1] = '\0';
}
break;
#if 0
case WLAN_EID_SUPP_RATES:
elems->supp_rates = pos;
elems->supp_rates_len = elen;
break;
case WLAN_EID_FH_PARAMS:
elems->fh_params = pos;
elems->fh_params_len = elen;
break;
#endif
case WLAN_EID_DS_PARAMS:
p->wlan_channel = *pos;
break;
#if 0
case WLAN_EID_CF_PARAMS:
elems->cf_params = pos;
elems->cf_params_len = elen;
break;
case WLAN_EID_TIM:
elems->tim = pos;
elems->tim_len = elen;
break;
case WLAN_EID_IBSS_PARAMS:
elems->ibss_params = pos;
elems->ibss_params_len = elen;
break;
case WLAN_EID_CHALLENGE:
elems->challenge = pos;
elems->challenge_len = elen;
break;
#endif
case WLAN_EID_WPA:
if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
pos[2] == 0xf2) {
/* Microsoft OUI (00:50:F2) */
if (pos[3] == 1) {
/* OUI Type 1 - WPA IE */
p->wlan_wpa=1;
#if 0
} else if (elen >= 5 && pos[3] == 2) {
if (pos[4] == 0) {
elems->wmm_info = pos;
elems->wmm_info_len = elen;
} else if (pos[4] == 1) {
elems->wmm_param = pos;
elems->wmm_param_len = elen;
}
#endif
}
}
break;
case WLAN_EID_RSN:
//elems->rsn = pos;
//elems->rsn_len = elen;
p->wlan_rsn = 1;
break;
#if 0
case WLAN_EID_ERP_INFO:
elems->erp_info = pos;
elems->erp_info_len = elen;
break;
case WLAN_EID_EXT_SUPP_RATES:
elems->ext_supp_rates = pos;
elems->ext_supp_rates_len = elen;
break;
#endif
default:
break;
}
left -= elen;
pos += elen;
}
}
/* from mac80211/ieee80211_i.c, slightly modified */
/**
......
......@@ -18,11 +18,6 @@
#define _IEEE80211_UTIL_H_
struct packet_info;
void
ieee802_11_parse_elems(unsigned char *start, size_t len, struct packet_info *pkt);
int
ieee80211_frame_duration(int phymode, size_t len, int rate, int short_preamble,
int ackcts, int shortslot, char qos_class, int retries);
......
......@@ -531,8 +531,8 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
p->wlan_bintval = le16toh(bc->bintval);
DEBUG("TSF %u\n BINTVAL %u", p->wlan_tsf, p->wlan_bintval);
ieee802_11_parse_elems(bc->ie,
len - hdrlen - 4 /* FCS */, p);
wlan_parse_information_elements(bc->ie,
len - hdrlen - sizeof(struct wlan_frame_beacon) - 4 /* FCS */, p);
DEBUG("ESSID %s \n", p->wlan_essid );
DEBUG("CHAN %d \n", p->wlan_channel );
cap_i = le16toh(bc->capab);
......@@ -546,7 +546,7 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
case WLAN_FRAME_PROBE_REQ:
p->pkt_types |= PKT_TYPE_PROBE;
ieee802_11_parse_elems((*buf + hdrlen),
wlan_parse_information_elements((*buf + hdrlen),
len - hdrlen - 4 /* FCS */, p);
p->wlan_mode = WLAN_MODE_PROBE;
break;
......
......@@ -21,6 +21,7 @@
#include <string.h>
#include "util.h"
#include "main.h"
#include "wlan80211.h"
......@@ -323,6 +324,47 @@ mcs_index_to_rate(int mcs, int ht20, int lgi)
return 0;
}
void
wlan_parse_information_elements(unsigned char *buf, int len, struct packet_info *p) {
while (len > 2) {
struct information_element* ie = (struct information_element*)buf;
DEBUG("------ IE %d len %d t len %d\n", ie->id, ie->len, len);
switch (ie->id) {
case WLAN_IE_ID_SSID:
if (ie->len < WLAN_MAX_SSID_LEN-1) {
memcpy(p->wlan_essid, ie->var, ie->len);
p->wlan_essid[ie->len] = '\0';
} else {
memcpy(p->wlan_essid, ie->var, WLAN_MAX_SSID_LEN-1);
p->wlan_essid[WLAN_MAX_SSID_LEN-1] = '\0';
}
break;
case WLAN_IE_ID_DSSS_PARAM:
p->wlan_channel = *ie->var;
break;
case WLAN_IE_ID_RSN:
p->wlan_rsn = 1;
break;
case WLAN_IE_ID_VENDOR:
if (ie->len >= 4 &&
ie->var[0] == 0x00 && ie->var[1] == 0x50 && ie->var[2] == 0xf2 && /* Microsoft OUI (00:50:F2) */
ie->var[3] == 1) { /* OUI Type 1 - WPA IE */
p->wlan_wpa=1;
}
break;
}
buf += (ie->len + 2);
len -= (ie->len + 2);
}
}
const char*
kilo_mega_ize(unsigned int val) {
......
......@@ -134,6 +134,11 @@ rate_index_to_rate(int idx);
int
mcs_index_to_rate(int mcs, int ht20, int lgi);
struct packet_info;
void
wlan_parse_information_elements(unsigned char *buf, int len, struct packet_info *p);
const char*
kilo_mega_ize(unsigned int val);
......
......@@ -124,4 +124,19 @@ struct wlan_frame_beacon {
#define WLAN_CAPAB_DEL_BLKACK 0x4000
#define WLAN_CAPAB_IMM_BLKACK 0x8000
/*** information elements ***/
struct information_element {
u_int8_t id;
u_int8_t len;
unsigned char var[0];
};
/* only the information element IDs we are interested in */
#define WLAN_IE_ID_SSID 0
#define WLAN_IE_ID_DSSS_PARAM 3
#define WLAN_IE_ID_RSN 48
#define WLAN_IE_ID_VENDOR 221
#define WLAN_MAX_SSID_LEN 34
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment