proto_80211_mac_hdr: correct header comment
[netsniff-ng.git] / src / proto_80211_mac_hdr.c
blob2e44a041f32957919803a502702e20f321074170
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Daniel Borkmann <borkmann@iogearbox.net>
4 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>, Deutsche Flugsicherung GmbH
5 * Subject to the GPL, version 2.
6 */
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <netinet/in.h> /* for ntohs() */
11 #include <asm/byteorder.h>
13 #include "proto.h"
14 #include "protos.h"
15 #include "dissector_80211.h"
16 #include "built_in.h"
17 #include "pkt_buff.h"
18 #include "oui.h"
20 /* Note: Fields are encoded in little-endian! */
21 struct ieee80211_frm_ctrl {
22 union {
23 u16 frame_control;
24 #if defined(__LITTLE_ENDIAN_BITFIELD)
25 /* Correct order here ... */
26 __extension__ u16 proto_version:2,
27 type:2,
28 subtype:4,
29 to_ds:1,
30 from_ds:1,
31 more_frags:1,
32 retry:1,
33 power_mgmt:1,
34 more_data:1,
35 wep:1,
36 order:1;
37 #elif defined(__BIG_ENDIAN_BITFIELD)
38 __extension__ u16 subtype:4,
39 type:2,
40 proto_version:2,
41 order:1,
42 wep:1,
43 more_data:1,
44 power_mgmt:1,
45 retry:1,
46 more_frags:1,
47 from_ds:1,
48 to_ds:1;
49 #else
50 # error "Adjust your <asm/byteorder.h> defines"
51 #endif
53 /* TODO: delete if use structs below*/
54 u16 duration;
55 } __packed;
57 /* Management Frame start */
58 /* Note: Fields are encoded in little-endian! */
59 struct ieee80211_mgmt {
60 u16 duration;
61 u8 da[6];
62 u8 sa[6];
63 u8 bssid[6];
64 u16 seq_ctrl;
65 } __packed;
67 struct ieee80211_mgmt_auth {
68 u16 auth_alg;
69 u16 auth_transaction;
70 u16 status_code;
71 /* possibly followed by Challenge text */
72 u8 variable[0];
73 } __packed;
75 struct ieee80211_mgmt_deauth {
76 u16 reason_code;
77 } __packed;
79 struct ieee80211_mgmt_assoc_req {
80 u16 capab_info;
81 u16 listen_interval;
82 /* followed by SSID and Supported rates */
83 u8 variable[0];
84 } __packed;
86 struct ieee80211_mgmt_assoc_resp {
87 u16 capab_info;
88 u16 status_code;
89 u16 aid;
90 /* followed by Supported rates */
91 u8 variable[0];
92 } __packed;
94 struct ieee80211_mgmt_reassoc_resp {
95 u16 capab_info;
96 u16 status_code;
97 u16 aid;
98 /* followed by Supported rates */
99 u8 variable[0];
100 } __packed;
102 struct ieee80211_mgmt_reassoc_req {
103 u16 capab_info;
104 u16 listen_interval;
105 u8 current_ap[6];
106 /* followed by SSID and Supported rates */
107 u8 variable[0];
108 } __packed;
110 struct ieee80211_mgmt_disassoc {
111 u16 reason_code;
112 } __packed;
114 struct ieee80211_mgmt_probe_req {
115 } __packed;
117 struct ieee80211_mgmt_beacon {
118 u8 timestamp[8];
119 u16 beacon_int;
120 u16 capab_info;
121 /* followed by some of SSID, Supported rates,
122 * FH Params, DS Params, CF Params, IBSS Params, TIM */
123 u8 variable[0];
124 } __packed;
126 struct ieee80211_mgmt_probe_resp {
127 u8 timestamp[8];
128 u16 beacon_int;
129 u16 capab_info;
130 /* followed by some of SSID, Supported rates,
131 * FH Params, DS Params, CF Params, IBSS Params, TIM */
132 u8 variable[0];
133 } __packed;
134 /* Management Frame end */
136 /* Control Frame start */
137 /* Note: Fields are encoded in little-endian! */
138 struct ieee80211_ctrl {
139 } __packed;
141 struct ieee80211_ctrl_rts {
142 u16 duration;
143 u8 da[6];
144 u8 sa[6];
145 } __packed;
147 struct ieee80211_ctrl_cts {
148 u16 duration;
149 u8 da[6];
150 } __packed;
152 struct ieee80211_ctrl_ack {
153 u16 duration;
154 u8 da[6];
155 } __packed;
157 struct ieee80211_ctrl_ps_poll {
158 u16 aid;
159 u8 bssid[6];
160 u8 sa[6];
161 } __packed;
163 struct ieee80211_ctrl_cf_end {
164 u16 duration;
165 u8 bssid[6];
166 u8 sa[6];
167 } __packed;
169 struct ieee80211_ctrl_cf_end_ack {
170 u16 duration;
171 u8 bssid[6];
172 u8 sa[6];
173 } __packed;
174 /* Control Frame end */
176 /* Data Frame start */
177 /* Note: Fields are encoded in little-endian! */
178 struct ieee80211_data {
179 } __packed;
181 /* TODO: Extend */
182 /* Control Frame end */
184 static const char *frame_control_types[] = {
185 "Management", /* 00 */
186 "Control", /* 01 */
187 "Data", /* 10 */
188 "Reserved", /* 11 */
191 static void ieee80211(struct pkt_buff *pkt)
193 struct ieee80211_frm_ctrl *frm_ctrl =
194 (struct ieee80211_frm_ctrl *) pkt_pull(pkt, sizeof(*frm_ctrl));
195 if (frm_ctrl == NULL)
196 return;
198 tprintf(" [ 802.11 Frame Control (0x%04x), Duration/ID (%u) ]\n",
199 le16_to_cpu(frm_ctrl->frame_control), le16_to_cpu(frm_ctrl->duration));
200 tprintf("\t [ Proto Version (%u), ", frm_ctrl->proto_version);
201 tprintf("Type (%u, %s), ", frm_ctrl->type, frame_control_types[frm_ctrl->type]);
202 tprintf("Subtype (%u)", frm_ctrl->subtype /*XXX*/);
203 tprintf("%s%s",
204 frm_ctrl->to_ds ? ", Frame goes to DS" : "",
205 frm_ctrl->from_ds ? ", Frame comes from DS" : "");
206 tprintf("%s", frm_ctrl->more_frags ? ", More Fragments" : "");
207 tprintf("%s", frm_ctrl->retry ? ", Frame is retransmitted" : "");
208 tprintf("%s", frm_ctrl->power_mgmt ? ", In Power Saving Mode" : "");
209 tprintf("%s", frm_ctrl->more_data ? ", More Data" : "");
210 tprintf("%s", frm_ctrl->wep ? ", Needs WEP" : "");
211 tprintf("%s", frm_ctrl->order ? ", Order" : "");
212 tprintf(" ]\n");
214 // pkt_set_proto(pkt, &ieee802_lay2, ntohs(eth->h_proto));
217 static void ieee80211_less(struct pkt_buff *pkt)
219 tprintf("802.11 frame (more on todo)");
222 struct protocol ieee80211_ops = {
223 .key = 0,
224 .print_full = ieee80211,
225 .print_less = ieee80211_less,
228 EXPORT_SYMBOL(ieee80211_ops);