1 | /*
|
---|
2 | * Copyright (c) 2015 Jan Kolarik
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup libnet
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /** @file ieee80211.h
|
---|
34 | *
|
---|
35 | * IEEE 802.11 interface definition.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #ifndef LIBNET_IEEE80211_H
|
---|
39 | #define LIBNET_IEEE80211_H
|
---|
40 |
|
---|
41 | #include <ddf/driver.h>
|
---|
42 | #include <sys/types.h>
|
---|
43 | #include <nic.h>
|
---|
44 |
|
---|
45 | /** Initial channel frequency. */
|
---|
46 | #define IEEE80211_FIRST_FREQ 2412
|
---|
47 |
|
---|
48 | /** Max supported channel frequency. */
|
---|
49 | #define IEEE80211_MAX_FREQ 2472
|
---|
50 |
|
---|
51 | /* Gap between IEEE80211 channels in MHz. */
|
---|
52 | #define IEEE80211_CHANNEL_GAP 5
|
---|
53 |
|
---|
54 | struct ieee80211_dev;
|
---|
55 |
|
---|
56 | /** Device operating modes. */
|
---|
57 | typedef enum {
|
---|
58 | IEEE80211_OPMODE_ADHOC,
|
---|
59 | IEEE80211_OPMODE_MESH,
|
---|
60 | IEEE80211_OPMODE_AP,
|
---|
61 | IEEE80211_OPMODE_STATION
|
---|
62 | } ieee80211_operating_mode_t;
|
---|
63 |
|
---|
64 | /** IEEE 802.11 frame types. */
|
---|
65 | typedef enum {
|
---|
66 | IEEE80211_MGMT_FRAME = 0x0,
|
---|
67 | IEEE80211_CTRL_FRAME = 0x4,
|
---|
68 | IEEE80211_DATA_FRAME = 0x8,
|
---|
69 | IEEE80211_EXT_FRAME = 0xC
|
---|
70 | } ieee80211_frame_type_t;
|
---|
71 |
|
---|
72 | /** IEEE 802.11 frame subtypes. */
|
---|
73 | typedef enum {
|
---|
74 | IEEE80211_MGMT_ASSOC_REQ_FRAME = 0x00,
|
---|
75 | IEEE80211_MGMT_ASSOC_RESP_FRAME = 0x10,
|
---|
76 | IEEE80211_MGMT_REASSOC_REQ_FRAME = 0x20,
|
---|
77 | IEEE80211_MGMT_REASSOC_RESP_FRAME = 0x30,
|
---|
78 | IEEE80211_MGMT_PROBE_REQ_FRAME = 0x40,
|
---|
79 | IEEE80211_MGMT_PROBE_RESP_FRAME = 0x50,
|
---|
80 | IEEE80211_MGMT_BEACON_FRAME = 0x80,
|
---|
81 | IEEE80211_MGMT_DIASSOC_FRAME = 0xA0,
|
---|
82 | IEEE80211_MGMT_AUTH_FRAME = 0xB0,
|
---|
83 | IEEE80211_MGMT_DEAUTH_FRAME = 0xC0,
|
---|
84 | } ieee80211_frame_subtype_t;
|
---|
85 |
|
---|
86 | /** IEEE 802.11 information element types. */
|
---|
87 | typedef enum {
|
---|
88 | IEEE80211_SSID_IE = 0, /**< Target SSID. */
|
---|
89 | IEEE80211_RATES_IE = 1, /**< Supported data rates. */
|
---|
90 | IEEE80211_CHANNEL_IE = 3, /**< Current channel number. */
|
---|
91 | IEEE80211_EXT_RATES_IE = 50 /**< Extended data rates. */
|
---|
92 | } ieee80211_ie_type_t;
|
---|
93 |
|
---|
94 | /** IEEE 802.11 functions. */
|
---|
95 | typedef struct {
|
---|
96 | int (*start)(struct ieee80211_dev *);
|
---|
97 | int (*scan)(struct ieee80211_dev *);
|
---|
98 | int (*tx_handler)(struct ieee80211_dev *, void *, size_t);
|
---|
99 | int (*set_freq)(struct ieee80211_dev *, uint16_t);
|
---|
100 | } ieee80211_ops_t;
|
---|
101 |
|
---|
102 | /** IEEE 802.11 WiFi device structure. */
|
---|
103 | typedef struct ieee80211_dev {
|
---|
104 | /** Backing DDF device. */
|
---|
105 | ddf_dev_t *ddf_dev;
|
---|
106 |
|
---|
107 | /** Pointer to implemented IEEE 802.11 operations. */
|
---|
108 | ieee80211_ops_t *ops;
|
---|
109 |
|
---|
110 | /** Pointer to driver specific data. */
|
---|
111 | void *driver_data;
|
---|
112 |
|
---|
113 | /** Current operating frequency. */
|
---|
114 | uint16_t current_freq;
|
---|
115 |
|
---|
116 | /** Current operating mode. */
|
---|
117 | ieee80211_operating_mode_t current_op_mode;
|
---|
118 |
|
---|
119 | /** BSSIDs we listen to. */
|
---|
120 | uint8_t bssid_mask[ETH_ADDR];
|
---|
121 |
|
---|
122 | /* TODO: Probably to be removed later - nic.open function is now
|
---|
123 | * executed multiple times, have to find out reason and fix it.
|
---|
124 | */
|
---|
125 | /** Indicates whether driver has already started. */
|
---|
126 | bool started;
|
---|
127 | } ieee80211_dev_t;
|
---|
128 |
|
---|
129 | /** IEEE 802.11 management header structure. */
|
---|
130 | typedef struct {
|
---|
131 | uint16_t frame_ctrl; /**< Little Endian value! */
|
---|
132 | uint16_t duration_id; /**< Little Endian value! */
|
---|
133 | uint8_t dest_addr[ETH_ADDR];
|
---|
134 | uint8_t src_addr[ETH_ADDR];
|
---|
135 | uint8_t bssid[ETH_ADDR];
|
---|
136 | uint16_t seq_ctrl; /**< Little Endian value! */
|
---|
137 | } __attribute__((packed)) __attribute__ ((aligned(2))) ieee80211_mgmt_header_t;
|
---|
138 |
|
---|
139 | /** IEEE 802.11 data header structure. */
|
---|
140 | typedef struct {
|
---|
141 | uint16_t frame_ctrl; /**< Little Endian value! */
|
---|
142 | uint16_t duration_id; /**< Little Endian value! */
|
---|
143 | uint8_t address1[ETH_ADDR];
|
---|
144 | uint8_t address2[ETH_ADDR];
|
---|
145 | uint8_t address3[ETH_ADDR];
|
---|
146 | uint16_t seq_ctrl; /**< Little Endian value! */
|
---|
147 | uint8_t address4[ETH_ADDR];
|
---|
148 | uint16_t qos_ctrl; /**< Little Endian value! */
|
---|
149 | } __attribute__((packed)) __attribute__ ((aligned(2))) ieee80211_data_header_t;
|
---|
150 |
|
---|
151 | /** IEEE 802.11 information element header. */
|
---|
152 | typedef struct {
|
---|
153 | uint8_t element_id;
|
---|
154 | uint8_t length;
|
---|
155 | } __attribute__((packed)) __attribute__ ((aligned(2))) ieee80211_ie_header_t;
|
---|
156 |
|
---|
157 | /** IEEE 802.11 authentication frame body. */
|
---|
158 | typedef struct {
|
---|
159 | uint16_t auth_alg; /**< Little Endian value! */
|
---|
160 | uint16_t auth_trans_no; /**< Little Endian value! */
|
---|
161 | uint16_t status; /**< Little Endian value! */
|
---|
162 | } __attribute__((packed)) __attribute__ ((aligned(2))) ieee80211_auth_body_t;
|
---|
163 |
|
---|
164 | typedef struct {
|
---|
165 | uint8_t bssid[ETH_ADDR];
|
---|
166 | uint16_t auth_alg;
|
---|
167 | } __attribute__((packed)) __attribute__ ((aligned(2))) ieee80211_auth_data_t;
|
---|
168 |
|
---|
169 | extern int ieee80211_device_init(ieee80211_dev_t *ieee80211_dev,
|
---|
170 | void *driver_data, ddf_dev_t *ddf_dev);
|
---|
171 | extern int ieee80211_init(ieee80211_dev_t *ieee80211_dev,
|
---|
172 | ieee80211_ops_t *ieee80211_ops);
|
---|
173 | extern int ieee80211_probe_request(ieee80211_dev_t *ieee80211_dev);
|
---|
174 | extern int ieee80211_probe_auth(ieee80211_dev_t *ieee80211_dev);
|
---|
175 |
|
---|
176 | #endif /* LIBNET_IEEE80211_H */
|
---|
177 |
|
---|
178 | /** @}
|
---|
179 | */
|
---|