2014-03-26 21:35:52 +01:00
|
|
|
#include "ac.h"
|
|
|
|
#include "ac_session.h"
|
2014-04-06 17:02:31 +02:00
|
|
|
#include "ac_wlans.h"
|
2014-03-26 21:35:52 +01:00
|
|
|
|
|
|
|
/* */
|
2014-04-06 17:02:31 +02:00
|
|
|
static void ac_ieee80211_mgmt_probe_request_packet(struct ac_session_data_t* sessiondata, uint8_t radioid, const struct ieee80211_header_mgmt* mgmt, int mgmtlength) {
|
2014-04-02 22:40:04 +02:00
|
|
|
int ielength;
|
|
|
|
struct ieee80211_ie_items ieitems;
|
|
|
|
|
|
|
|
/* Parsing Information Elements */
|
|
|
|
ielength = mgmtlength - (sizeof(struct ieee80211_header) + sizeof(mgmt->proberequest));
|
|
|
|
if (ieee80211_retrieve_information_elements_position(&ieitems, &mgmt->proberequest.ie[0], ielength)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2014-04-06 17:02:31 +02:00
|
|
|
static void ac_ieee80211_mgmt_authentication_packet(struct ac_session_data_t* sessiondata, uint8_t radioid, const struct ieee80211_header_mgmt* mgmt, int mgmtlength) {
|
2014-04-02 22:40:04 +02:00
|
|
|
int ielength;
|
|
|
|
struct ieee80211_ie_items ieitems;
|
2014-04-06 17:02:31 +02:00
|
|
|
struct ac_station* station;
|
2014-04-02 22:40:04 +02:00
|
|
|
|
|
|
|
/* Parsing Information Elements */
|
2014-04-06 17:02:31 +02:00
|
|
|
ielength = mgmtlength - (sizeof(struct ieee80211_header) + sizeof(mgmt->authetication));
|
|
|
|
if (ieee80211_retrieve_information_elements_position(&ieitems, &mgmt->authetication.ie[0], ielength)) {
|
2014-04-02 22:40:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-06 17:02:31 +02:00
|
|
|
/* Create station */
|
|
|
|
station = ac_stations_create_station(sessiondata->session, radioid, mgmt->bssid, mgmt->sa);
|
|
|
|
|
|
|
|
/* */
|
|
|
|
if (station->wlan->macmode == CAPWAP_ADD_WLAN_MACMODE_LOCAL) {
|
|
|
|
/* TODO */
|
|
|
|
} else if (station->wlan->macmode == CAPWAP_ADD_WLAN_MACMODE_SPLIT) {
|
|
|
|
/* TODO */
|
|
|
|
}
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2014-04-06 17:02:31 +02:00
|
|
|
static void ac_ieee80211_mgmt_association_request_packet(struct ac_session_data_t* sessiondata, uint8_t radioid, const struct ieee80211_header_mgmt* mgmt, int mgmtlength) {
|
2014-04-02 22:40:04 +02:00
|
|
|
int ielength;
|
|
|
|
struct ieee80211_ie_items ieitems;
|
2014-04-06 17:02:31 +02:00
|
|
|
struct ac_station* station;
|
2014-04-02 22:40:04 +02:00
|
|
|
|
|
|
|
/* Parsing Information Elements */
|
2014-04-06 17:02:31 +02:00
|
|
|
ielength = mgmtlength - (sizeof(struct ieee80211_header) + sizeof(mgmt->associationrequest));
|
|
|
|
if (ieee80211_retrieve_information_elements_position(&ieitems, &mgmt->associationrequest.ie[0], ielength)) {
|
2014-04-02 22:40:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-06 17:02:31 +02:00
|
|
|
/* Get station */
|
|
|
|
station = ac_stations_get_station(sessiondata->session, radioid, mgmt->bssid, mgmt->sa);
|
|
|
|
|
|
|
|
/* */
|
|
|
|
if (station->wlan->macmode == CAPWAP_ADD_WLAN_MACMODE_LOCAL) {
|
|
|
|
/* TODO */
|
|
|
|
} else if (station->wlan->macmode == CAPWAP_ADD_WLAN_MACMODE_SPLIT) {
|
|
|
|
/* TODO */
|
|
|
|
}
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2014-04-06 17:02:31 +02:00
|
|
|
static void ac_ieee80211_mgmt_reassociation_request_packet(struct ac_session_data_t* sessiondata, uint8_t radioid, const struct ieee80211_header_mgmt* mgmt, int mgmtlength) {
|
2014-04-02 22:40:04 +02:00
|
|
|
int ielength;
|
|
|
|
struct ieee80211_ie_items ieitems;
|
|
|
|
|
|
|
|
/* Parsing Information Elements */
|
2014-04-06 17:02:31 +02:00
|
|
|
ielength = mgmtlength - (sizeof(struct ieee80211_header) + sizeof(mgmt->reassociationrequest));
|
|
|
|
if (ieee80211_retrieve_information_elements_position(&ieitems, &mgmt->reassociationrequest.ie[0], ielength)) {
|
2014-04-02 22:40:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2014-04-06 17:02:31 +02:00
|
|
|
static void ac_ieee80211_mgmt_disassociation_packet(struct ac_session_data_t* sessiondata, uint8_t radioid, const struct ieee80211_header_mgmt* mgmt, int mgmtlength) {
|
2014-04-02 22:40:04 +02:00
|
|
|
int ielength;
|
|
|
|
struct ieee80211_ie_items ieitems;
|
|
|
|
|
|
|
|
/* Parsing Information Elements */
|
2014-04-06 17:02:31 +02:00
|
|
|
ielength = mgmtlength - (sizeof(struct ieee80211_header) + sizeof(mgmt->disassociation));
|
|
|
|
if (ieee80211_retrieve_information_elements_position(&ieitems, &mgmt->disassociation.ie[0], ielength)) {
|
2014-04-02 22:40:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2014-04-06 17:02:31 +02:00
|
|
|
static void ac_ieee80211_mgmt_deauthentication_packet(struct ac_session_data_t* sessiondata, uint8_t radioid, const struct ieee80211_header_mgmt* mgmt, int mgmtlength) {
|
2014-04-02 22:40:04 +02:00
|
|
|
int ielength;
|
2014-04-06 17:02:31 +02:00
|
|
|
const uint8_t* stationaddress;
|
2014-04-02 22:40:04 +02:00
|
|
|
struct ieee80211_ie_items ieitems;
|
|
|
|
|
|
|
|
/* Parsing Information Elements */
|
2014-04-06 17:02:31 +02:00
|
|
|
ielength = mgmtlength - (sizeof(struct ieee80211_header) + sizeof(mgmt->deauthetication));
|
|
|
|
if (ieee80211_retrieve_information_elements_position(&ieitems, &mgmt->deauthetication.ie[0], ielength)) {
|
2014-04-02 22:40:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-06 17:02:31 +02:00
|
|
|
/* Get station address */
|
|
|
|
stationaddress = (memcmp(mgmt->bssid, mgmt->sa, MACADDRESS_EUI48_LENGTH) ? mgmt->sa : mgmt->da);
|
|
|
|
|
|
|
|
/* Delete station */
|
|
|
|
ac_stations_delete_station(sessiondata->session, stationaddress);
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2014-04-06 17:02:31 +02:00
|
|
|
static void ac_ieee80211_mgmt_packet(struct ac_session_data_t* sessiondata, uint8_t radioid, const struct ieee80211_header_mgmt* mgmt, int mgmtlength, uint16_t framecontrol_subtype) {
|
2014-04-02 22:40:04 +02:00
|
|
|
switch (framecontrol_subtype) {
|
|
|
|
case IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_PROBE_REQUEST: {
|
|
|
|
if (mgmtlength >= (sizeof(struct ieee80211_header) + sizeof(mgmt->proberequest))) {
|
2014-04-06 17:02:31 +02:00
|
|
|
ac_ieee80211_mgmt_probe_request_packet(sessiondata, radioid, mgmt, mgmtlength);
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_AUTHENTICATION: {
|
|
|
|
if (mgmtlength >= (sizeof(struct ieee80211_header) + sizeof(mgmt->authetication))) {
|
2014-04-06 17:02:31 +02:00
|
|
|
ac_ieee80211_mgmt_authentication_packet(sessiondata, radioid, mgmt, mgmtlength);
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_ASSOCIATION_REQUEST: {
|
|
|
|
if (mgmtlength >= (sizeof(struct ieee80211_header) + sizeof(mgmt->associationrequest))) {
|
2014-04-06 17:02:31 +02:00
|
|
|
ac_ieee80211_mgmt_association_request_packet(sessiondata, radioid, mgmt, mgmtlength);
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_REASSOCIATION_REQUEST: {
|
|
|
|
if (mgmtlength >= (sizeof(struct ieee80211_header) + sizeof(mgmt->reassociationrequest))) {
|
2014-04-06 17:02:31 +02:00
|
|
|
ac_ieee80211_mgmt_reassociation_request_packet(sessiondata, radioid, mgmt, mgmtlength);
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_DISASSOCIATION: {
|
|
|
|
if (mgmtlength >= (sizeof(struct ieee80211_header) + sizeof(mgmt->disassociation))) {
|
2014-04-06 17:02:31 +02:00
|
|
|
ac_ieee80211_mgmt_disassociation_packet(sessiondata, radioid, mgmt, mgmtlength);
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_DEAUTHENTICATION: {
|
|
|
|
if (mgmtlength >= (sizeof(struct ieee80211_header) + sizeof(mgmt->deauthetication))) {
|
2014-04-06 17:02:31 +02:00
|
|
|
ac_ieee80211_mgmt_deauthentication_packet(sessiondata, radioid, mgmt, mgmtlength);
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IEEE80211_FRAMECONTROL_MGMT_SUBTYPE_ACTION: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2014-04-06 17:02:31 +02:00
|
|
|
void ac_ieee80211_packet(struct ac_session_data_t* sessiondata, uint8_t radioid, const uint8_t* buffer, int length) {
|
2014-04-02 22:40:04 +02:00
|
|
|
const struct ieee80211_header* header;
|
|
|
|
uint16_t framecontrol;
|
|
|
|
uint16_t framecontrol_type;
|
|
|
|
uint16_t framecontrol_subtype;
|
|
|
|
|
2014-03-26 21:35:52 +01:00
|
|
|
ASSERT(sessiondata != NULL);
|
2014-04-06 17:02:31 +02:00
|
|
|
ASSERT(IS_VALID_RADIOID(radioid));
|
2014-03-26 21:35:52 +01:00
|
|
|
ASSERT(buffer != NULL);
|
2014-04-02 22:40:04 +02:00
|
|
|
ASSERT(length >= sizeof(struct ieee80211_header));
|
|
|
|
|
|
|
|
/* Get type frame */
|
|
|
|
header = (const struct ieee80211_header*)buffer;
|
|
|
|
framecontrol = __le16_to_cpu(header->framecontrol);
|
|
|
|
framecontrol_type = IEEE80211_FRAME_CONTROL_GET_TYPE(framecontrol);
|
|
|
|
framecontrol_subtype = IEEE80211_FRAME_CONTROL_GET_SUBTYPE(framecontrol);
|
|
|
|
|
|
|
|
/* Parsing frame */
|
|
|
|
if (framecontrol_type == IEEE80211_FRAMECONTROL_TYPE_MGMT) {
|
2014-04-06 17:02:31 +02:00
|
|
|
ac_ieee80211_mgmt_packet(sessiondata, radioid, (const struct ieee80211_header_mgmt*)buffer, length, framecontrol_subtype);
|
2014-04-02 22:40:04 +02:00
|
|
|
}
|
2014-03-26 21:35:52 +01:00
|
|
|
}
|