nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #ifndef HAVE_PACKET_H
2 #define HAVE_PACKET_H
3  
4 #include <inttypes.h>
5  
6 #include "osdep/byteorder.h"
7 #include "mac_addr.h"
8  
9 #define IEEE80211_TYPE_BEACON 0x80
10 #define IEEE80211_TYPE_DATA 0x08
11 #define IEEE80211_TYPE_QOSDATA 0x88
12 #define IEEE80211_TYPE_AUTH 0xB0
13 #define IEEE80211_TYPE_PROBEREQ 0x40
14 #define IEEE80211_TYPE_PROBERES 0x50
15 #define IEEE80211_TYPE_DEAUTH 0xC0
16 #define IEEE80211_TYPE_DISASSOC 0xA0
17 #define IEEE80211_TYPE_ASSOCREQ 0x00
18 #define IEEE80211_TYPE_ASSOCRES 0x10
19 #define IEEE80211_TYPE_ACTION 0xD0
20 #define IEEE80211_TYPE_CTS 0xC4
21  
22 #define DEFAULT_BEACON_INTERVAL 0x64
23 #define DEFAULT_11B_RATES "\x01\x04\x82\x84\x8b\x96"
24 #define DEFAULT_11G_RATES "\x32\x08\x0c\x12\x18\x24\x30\x48\x60\x6c"
25 #define DEFAULT_WPA_TKIP_TAG "\xDD\x18\x00\x50\xF2\x01\x01\x00\x00\x50\xF2\x02\x01\x00\x00\x50\xF2\x02\x01\x00\x00\x50\xF2\x02\x00\x00"
26 #define DEFAULT_WPA_AES_TAG "\xDD\x18\x00\x50\xF2\x01\x01\x00\x00\x50\xF2\x04\x01\x00\x00\x50\xF2\x04\x01\x00\x00\x50\xF2\x02\x00\x00"
27  
28 #define AUTH_ALGORITHM_OPEN 0x0000
29 #define AUTH_STATUS_SUCCESS 0x0000
30 #define AUTH_DEFAULT_DURATION 314
31  
32 #define DEAUTH_REASON_UNSPEC 0x0001
33 #define DEAUTH_REASON_LEAVING 0x0003
34 #define DISASSOC_REASON_APFULL 0x0005
35 #define DISASSOC_REASON_LEAVING 0x0008
36  
37 #define DEFAULT_LISTEN_INTERVAL 0x0001
38  
39 #define BEACON_TAGTYPE_SSID 0x00
40 #define BEACON_TAGTYPE_MESHID 0x72
41  
42 #define LLC_SNAP 0xAA
43 #define LLC_UNNUMBERED 0x03
44  
45 #define RSN_TYPE_KEY 0x03
46 #define RSN_DESCRIPTOR_KEY 0x02
47  
48 #define MESH_ACTION_CATEGORY 0x0D
49 #define MESH_ACTION_PATHSEL 0x01
50 #define MESH_TAG_PREQ 0x82
51 #define MESH_TAG_PREP 0x83
52  
53 #define MAX_PACKET_SIZE 2048
54  
55 struct packet {
56 unsigned char data[MAX_PACKET_SIZE];
57 unsigned int len;
58 };
59  
60 struct ieee_hdr {
61 uint8_t type;
62 uint8_t flags;
63 uint16_t duration;
64 struct ether_addr addr1;
65 struct ether_addr addr2;
66 struct ether_addr addr3;
67 uint16_t frag_seq;
68 } __attribute__((packed));
69  
70 struct beacon_fixed {
71 uint64_t timestamp;
72 uint16_t interval;
73 uint16_t capabilities;
74 } __attribute__((packed));
75  
76 struct auth_fixed {
77 uint16_t algorithm;
78 uint16_t seq;
79 uint16_t status;
80 } __attribute__((packed));
81  
82 struct assoc_fixed {
83 uint16_t capabilities;
84 uint16_t interval;
85 } __attribute__((packed));
86  
87 struct llc_header {
88 uint8_t dsap;
89 uint8_t ssap;
90 uint8_t control;
91 uint8_t encap[3];
92 uint16_t type;
93 } __attribute__((packed));
94  
95 struct rsn_auth {
96 uint8_t version;
97 uint8_t type;
98 uint16_t length;
99 uint8_t descriptor;
100 uint16_t key_info;
101 uint16_t key_length;
102 uint64_t replay_counter;
103 uint8_t nonce[32];
104 uint8_t key_iv[16];
105 uint64_t key_rsc;
106 uint64_t key_id;
107 uint8_t key_mic[16];
108 uint16_t wpa_length;
109 } __attribute__((packed));
110  
111 struct action_fixed {
112 uint8_t category;
113 uint8_t action_code;
114 uint8_t tag;
115 uint8_t taglen;
116 } __attribute__((packed));
117  
118 struct mesh_preq {
119 uint8_t flags;
120 uint8_t hop_count;
121 uint8_t ttl;
122 uint32_t discovery_id;
123 struct ether_addr originator;
124 uint32_t orig_seq;
125 uint32_t lifetime;
126 uint32_t metric;
127 uint8_t target_count;
128 uint8_t target_flags;
129 struct ether_addr target;
130 uint32_t target_seq;
131 } __attribute__((packed));
132  
133 struct mesh_prep {
134 uint8_t flags;
135 uint8_t hop_count;
136 uint8_t ttl;
137 struct ether_addr target;
138 uint32_t target_seq;
139 uint32_t lifetime;
140 uint32_t metric;
141 struct ether_addr originator;
142 uint32_t orig_seq;
143 } __attribute__((packed));
144  
145 struct cts {
146 uint8_t type;
147 uint8_t flags;
148 uint16_t duration;
149 struct ether_addr dest;
150 } __attribute__((packed));
151  
152 //dsflags: 'a' = AdHoc, Beacon 'f' = From DS 't' = To DS 'w' = WDS (intra DS)
153 //Set recv to SE_NULLMAC if you don't create WDS packets. (its ignored anyway)
154 void create_ieee_hdr(struct packet *pkt, uint8_t type, char dsflags, uint16_t duration, struct ether_addr destination, struct ether_addr source, struct ether_addr bssid_or_transm, struct ether_addr recv, uint8_t fragment);
155  
156 struct ether_addr *get_bssid(struct packet *pkt);
157  
158 struct ether_addr *get_source(struct packet *pkt);
159  
160 struct ether_addr *get_destination(struct packet *pkt);
161  
162 struct ether_addr *get_transmitter(struct packet *pkt);
163  
164 struct ether_addr *get_receiver(struct packet *pkt);
165  
166 //encryption: 'n' = None 'w' = WEP 't' = TKIP (WPA) 'a' = AES (WPA2)
167 //If bitrate is 54, you'll get an bg network, b only otherwise
168 struct packet create_beacon(struct ether_addr bssid, char *ssid, uint8_t channel, char encryption, unsigned char bitrate, char adhoc);
169  
170 struct packet create_auth(struct ether_addr bssid, struct ether_addr client, uint16_t seq);
171  
172 struct packet create_probe(struct ether_addr source, char *ssid, unsigned char bitrate);
173  
174 struct packet create_deauth(struct ether_addr destination, struct ether_addr source, struct ether_addr bssid);
175  
176 struct packet create_disassoc(struct ether_addr destination, struct ether_addr source, struct ether_addr bssid);
177  
178 //Capabilities and SSID should match AP, so just copy them from one of its beacon frames
179 struct packet create_assoc_req(struct ether_addr client, struct ether_addr bssid, uint16_t capabilities, char *ssid, unsigned char bitrate);
180  
181 struct packet create_cts(struct ether_addr destination, uint16_t duration);
182  
183 //Copy SSID or MeshID from Beacon Frame into String. Must free afterwards! Returns NULL on Errors (no beacon frame, no SSID tag found)
184 //SSID len is also reported, because on hidden SSIDs, strlen() doesn't work, since the SSID is all NULLBYTES!
185 //If you don't need that info, set ssidlen to NULL!
186 char *get_ssid(struct packet *pkt, unsigned char *ssidlen);
187 char *get_meshid(struct packet *pkt, unsigned char *meshidlen);
188  
189 uint16_t get_capabilities(struct packet *pkt);
190  
191 //Append data to packet
192 void append_data(struct packet *pkt, unsigned char *data, int len);
193  
194 //Adds LLC header to a packet created with create_ieee_hdr(). You can use this to build unencrypted data frames or EAP packets.
195 void add_llc_header(struct packet *pkt, uint16_t llc_type);
196  
197 //Adds EAP/WPA packet behind the LLC Header to create WPA Login packets
198 void add_eapol(struct packet *pkt, uint16_t wpa_length, uint8_t *wpa_element, uint8_t wpa_1or2, uint8_t rsn_version, uint64_t rsn_replay);
199  
200 void increase_seqno(struct packet *pkt);
201 uint16_t get_seqno(struct packet *pkt);
202 //If pkt is NULL in set_seqno, the sequence number for the next call to create_ieee_hdr will be seqno + 1!
203 void set_seqno(struct packet *pkt, uint16_t seqno);
204  
205 uint8_t get_fragno(struct packet *pkt);
206 void set_fragno(struct packet *pkt, uint8_t frag, int last_frag);
207  
208 #endif