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 | /**
|
---|
30 | * @addtogroup libieee80211
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /**
|
---|
34 | * @file ieee80211.h
|
---|
35 | * @brief Public header exposing IEEE 802.11 to drivers.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #ifndef LIB_IEEE80211_H
|
---|
39 | #define LIB_IEEE80211_H
|
---|
40 |
|
---|
41 | #include <ddf/driver.h>
|
---|
42 | #include <nic.h>
|
---|
43 | #include <ops/ieee80211.h>
|
---|
44 |
|
---|
45 | #define DEVICE_CATEGORY_IEEE80211 "ieee80211"
|
---|
46 |
|
---|
47 | struct ieee80211_dev;
|
---|
48 | typedef struct ieee80211_dev ieee80211_dev_t;
|
---|
49 |
|
---|
50 | /** Initial channel frequency. */
|
---|
51 | #define IEEE80211_FIRST_FREQ 2412
|
---|
52 |
|
---|
53 | /** Max supported channel frequency. */
|
---|
54 | #define IEEE80211_MAX_FREQ 2472
|
---|
55 |
|
---|
56 | /** Gap between IEEE80211 channels in MHz. */
|
---|
57 | #define IEEE80211_CHANNEL_GAP 5
|
---|
58 |
|
---|
59 | /** Max AMPDU factor. */
|
---|
60 | #define IEEE80211_MAX_AMPDU_FACTOR 13
|
---|
61 |
|
---|
62 | /** Max authentication password length. */
|
---|
63 | #define IEEE80211_MAX_PASSW_LEN 64
|
---|
64 |
|
---|
65 | /** IEEE 802.11 b/g supported data rates in units of 500 kb/s. */
|
---|
66 | static const uint8_t ieee80211bg_data_rates[] = {
|
---|
67 | 2, 4, 11, 12, 18, 22, 24, 36, 48, 72, 96, 108
|
---|
68 | };
|
---|
69 |
|
---|
70 | /** Device operating modes. */
|
---|
71 | typedef enum {
|
---|
72 | IEEE80211_OPMODE_ADHOC,
|
---|
73 | IEEE80211_OPMODE_MESH,
|
---|
74 | IEEE80211_OPMODE_AP,
|
---|
75 | IEEE80211_OPMODE_STATION
|
---|
76 | } ieee80211_operating_mode_t;
|
---|
77 |
|
---|
78 | /** Key flags. */
|
---|
79 | typedef enum {
|
---|
80 | IEEE80211_KEY_FLAG_TYPE_PAIRWISE = 0x01,
|
---|
81 | IEEE80211_KEY_FLAG_TYPE_GROUP = 0x02
|
---|
82 | } ieee80211_key_flags_t;
|
---|
83 |
|
---|
84 | typedef enum {
|
---|
85 | IEEE80211_TKIP_TX_MIC_OFFSET = 16,
|
---|
86 | IEEE80211_TKIP_RX_MIC_OFFSET = 24
|
---|
87 | } ieee80211_tkip_mic_offset_t;
|
---|
88 |
|
---|
89 | /** Key config structure. */
|
---|
90 | typedef struct {
|
---|
91 | uint8_t id;
|
---|
92 | uint8_t flags;
|
---|
93 | ieee80211_security_suite_t suite;
|
---|
94 | uint8_t data[32];
|
---|
95 | } ieee80211_key_config_t;
|
---|
96 |
|
---|
97 | /** IEEE 802.11 callback functions. */
|
---|
98 | typedef struct {
|
---|
99 | /** unction that is called at device initalization.
|
---|
100 | *
|
---|
101 | * This should get device into running state.
|
---|
102 | *
|
---|
103 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
104 | *
|
---|
105 | * @return EOK if succeed, error code otherwise.
|
---|
106 | *
|
---|
107 | */
|
---|
108 | errno_t (*start)(struct ieee80211_dev *);
|
---|
109 |
|
---|
110 | /** Scan neighborhood for networks.
|
---|
111 | *
|
---|
112 | * There should be implemented scanning of whole bandwidth.
|
---|
113 | * Incoming results are processed by IEEE 802.11 framework itself.
|
---|
114 | *
|
---|
115 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
116 | *
|
---|
117 | * @return EOK if succeed, error code otherwise.
|
---|
118 | *
|
---|
119 | */
|
---|
120 | errno_t (*scan)(struct ieee80211_dev *);
|
---|
121 |
|
---|
122 | /** Handler for TX frames to be send from device.
|
---|
123 | *
|
---|
124 | * This should be called for every frame that has to be send
|
---|
125 | * from IEEE 802.11 device.
|
---|
126 | *
|
---|
127 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
128 | * @param buffer Buffer with data to be send.
|
---|
129 | * @param buffer_size Size of buffer.
|
---|
130 | *
|
---|
131 | * @return EOK if succeed, error code otherwise.
|
---|
132 | *
|
---|
133 | */
|
---|
134 | errno_t (*tx_handler)(struct ieee80211_dev *, void *, size_t);
|
---|
135 |
|
---|
136 | /** Set device operating frequency to given value.
|
---|
137 | *
|
---|
138 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
139 | * @param freq New device operating frequency.
|
---|
140 | *
|
---|
141 | * @return EOK if succeed, error code otherwise.
|
---|
142 | *
|
---|
143 | */
|
---|
144 | errno_t (*set_freq)(struct ieee80211_dev *, uint16_t);
|
---|
145 |
|
---|
146 | /** Callback to inform device about BSSID change.
|
---|
147 | *
|
---|
148 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
149 | * @param connected True if connected to new BSSID, otherwise false.
|
---|
150 | *
|
---|
151 | * @return EOK if succeed, error code otherwise.
|
---|
152 | *
|
---|
153 | */
|
---|
154 | errno_t (*bssid_change)(struct ieee80211_dev *, bool);
|
---|
155 |
|
---|
156 | /** Callback to setup encryption key in IEEE 802.11 device.
|
---|
157 | *
|
---|
158 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
159 | * @param key_conf Key config structure.
|
---|
160 | * @param insert True to insert this key to device,
|
---|
161 | * false to remove it.
|
---|
162 | *
|
---|
163 | * @return EOK if succeed, error code otherwise.
|
---|
164 | *
|
---|
165 | */
|
---|
166 | errno_t (*key_config)(struct ieee80211_dev *,
|
---|
167 | ieee80211_key_config_t *key_conf, bool);
|
---|
168 | } ieee80211_ops_t;
|
---|
169 |
|
---|
170 | /* Initialization functions. */
|
---|
171 | extern ieee80211_dev_t *ieee80211_device_create(void);
|
---|
172 | extern errno_t ieee80211_device_init(ieee80211_dev_t *, ddf_dev_t *);
|
---|
173 | extern errno_t ieee80211_init(ieee80211_dev_t *, ieee80211_ops_t *,
|
---|
174 | ieee80211_iface_t *, nic_iface_t *, ddf_dev_ops_t *);
|
---|
175 |
|
---|
176 | /* Getters & setters, queries & reports. */
|
---|
177 | extern void *ieee80211_get_specific(ieee80211_dev_t *);
|
---|
178 | extern void ieee80211_set_specific(ieee80211_dev_t *, void *);
|
---|
179 | extern ddf_dev_t *ieee80211_get_ddf_dev(ieee80211_dev_t *);
|
---|
180 | extern ieee80211_operating_mode_t ieee80211_query_current_op_mode(
|
---|
181 | ieee80211_dev_t *);
|
---|
182 | extern uint16_t ieee80211_query_current_freq(ieee80211_dev_t *);
|
---|
183 | extern void ieee80211_query_bssid(ieee80211_dev_t *, nic_address_t *);
|
---|
184 | extern bool ieee80211_is_connected(ieee80211_dev_t *);
|
---|
185 | extern void ieee80211_report_current_op_mode(ieee80211_dev_t *,
|
---|
186 | ieee80211_operating_mode_t);
|
---|
187 | extern void ieee80211_report_current_freq(ieee80211_dev_t *, uint16_t);
|
---|
188 | extern uint16_t ieee80211_get_aid(ieee80211_dev_t *);
|
---|
189 | extern int ieee80211_get_pairwise_security(ieee80211_dev_t *);
|
---|
190 | extern bool ieee80211_is_ready(ieee80211_dev_t *);
|
---|
191 | extern void ieee80211_set_ready(ieee80211_dev_t *, bool);
|
---|
192 | extern bool ieee80211_query_using_key(ieee80211_dev_t *);
|
---|
193 | extern void ieee80211_setup_key_confirm(ieee80211_dev_t *, bool);
|
---|
194 |
|
---|
195 | extern bool ieee80211_is_data_frame(uint16_t);
|
---|
196 | extern bool ieee80211_is_mgmt_frame(uint16_t);
|
---|
197 | extern bool ieee80211_is_beacon_frame(uint16_t);
|
---|
198 | extern bool ieee80211_is_probe_response_frame(uint16_t);
|
---|
199 | extern bool ieee80211_is_auth_frame(uint16_t);
|
---|
200 | extern bool ieee80211_is_assoc_response_frame(uint16_t);
|
---|
201 |
|
---|
202 | /* Worker functions. */
|
---|
203 | extern errno_t ieee80211_rx_handler(ieee80211_dev_t *, void *, size_t);
|
---|
204 |
|
---|
205 | #endif
|
---|
206 |
|
---|
207 | /** @}
|
---|
208 | */
|
---|