wlantest: Move Mgmt and Data frame processing into their own files
[mech_eap.git] / wlantest / rx_data.c
1 /*
2  * Received Data frame processing
3  * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "utils/includes.h"
16
17 #include "utils/common.h"
18 #include "common/ieee802_11_defs.h"
19 #include "wlantest.h"
20
21
22 static const char * data_stype(u16 stype)
23 {
24         switch (stype) {
25         case WLAN_FC_STYPE_DATA:
26                 return "DATA";
27         case WLAN_FC_STYPE_DATA_CFACK:
28                 return "DATA-CFACK";
29         case WLAN_FC_STYPE_DATA_CFPOLL:
30                 return "DATA-CFPOLL";
31         case WLAN_FC_STYPE_DATA_CFACKPOLL:
32                 return "DATA-CFACKPOLL";
33         case WLAN_FC_STYPE_NULLFUNC:
34                 return "NULLFUNC";
35         case WLAN_FC_STYPE_CFACK:
36                 return "CFACK";
37         case WLAN_FC_STYPE_CFPOLL:
38                 return "CFPOLL";
39         case WLAN_FC_STYPE_CFACKPOLL:
40                 return "CFACKPOLL";
41         case WLAN_FC_STYPE_QOS_DATA:
42                 return "QOSDATA";
43         case WLAN_FC_STYPE_QOS_DATA_CFACK:
44                 return "QOSDATA-CFACK";
45         case WLAN_FC_STYPE_QOS_DATA_CFPOLL:
46                 return "QOSDATA-CFPOLL";
47         case WLAN_FC_STYPE_QOS_DATA_CFACKPOLL:
48                 return "QOSDATA-CFACKPOLL";
49         case WLAN_FC_STYPE_QOS_NULL:
50                 return "QOS-NULL";
51         case WLAN_FC_STYPE_QOS_CFPOLL:
52                 return "QOS-CFPOLL";
53         case WLAN_FC_STYPE_QOS_CFACKPOLL:
54                 return "QOS-CFACKPOLL";
55         }
56         return "??";
57 }
58
59
60 void rx_data(struct wlantest *wt, const u8 *data, size_t len)
61 {
62         const struct ieee80211_hdr *hdr;
63         u16 fc;
64
65         if (len < 24)
66                 return;
67
68         hdr = (const struct ieee80211_hdr *) data;
69         fc = le_to_host16(hdr->frame_control);
70         wt->rx_data++;
71
72         switch (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) {
73         case 0:
74                 wpa_printf(MSG_EXCESSIVE, "DATA %s%s%s IBSS DA=" MACSTR " SA="
75                            MACSTR " BSSID=" MACSTR,
76                            data_stype(WLAN_FC_GET_STYPE(fc)),
77                            fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
78                            fc & WLAN_FC_ISWEP ? " Prot" : "",
79                            MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
80                            MAC2STR(hdr->addr3));
81                 break;
82         case WLAN_FC_FROMDS:
83                 wpa_printf(MSG_EXCESSIVE, "DATA %s%s%s FromDS DA=" MACSTR
84                            " BSSID=" MACSTR " SA=" MACSTR,
85                            data_stype(WLAN_FC_GET_STYPE(fc)),
86                            fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
87                            fc & WLAN_FC_ISWEP ? " Prot" : "",
88                            MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
89                            MAC2STR(hdr->addr3));
90                 break;
91         case WLAN_FC_TODS:
92                 wpa_printf(MSG_EXCESSIVE, "DATA %s%s%s ToDS BSSID=" MACSTR
93                            " SA=" MACSTR " DA=" MACSTR,
94                            data_stype(WLAN_FC_GET_STYPE(fc)),
95                            fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
96                            fc & WLAN_FC_ISWEP ? " Prot" : "",
97                            MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
98                            MAC2STR(hdr->addr3));
99                 break;
100         case WLAN_FC_TODS | WLAN_FC_FROMDS:
101                 wpa_printf(MSG_EXCESSIVE, "DATA %s%s%s WDS RA=" MACSTR " TA="
102                            MACSTR " DA=" MACSTR " SA=" MACSTR,
103                            data_stype(WLAN_FC_GET_STYPE(fc)),
104                            fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
105                            fc & WLAN_FC_ISWEP ? " Prot" : "",
106                            MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
107                            MAC2STR(hdr->addr3),
108                            MAC2STR((const u8 *) (hdr + 1)));
109                 break;
110         }
111 }