[59fa7ab] | 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 |
|
---|
[8a64320e] | 29 | /**
|
---|
[59fa7ab] | 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 |
|
---|
[8a64320e] | 45 | #define DEVICE_CATEGORY_IEEE80211 "ieee80211"
|
---|
[59fa7ab] | 46 |
|
---|
| 47 | struct ieee80211_dev;
|
---|
| 48 | typedef struct ieee80211_dev ieee80211_dev_t;
|
---|
| 49 |
|
---|
| 50 | /** Initial channel frequency. */
|
---|
[8a64320e] | 51 | #define IEEE80211_FIRST_FREQ 2412
|
---|
[59fa7ab] | 52 |
|
---|
| 53 | /** Max supported channel frequency. */
|
---|
[8a64320e] | 54 | #define IEEE80211_MAX_FREQ 2472
|
---|
[59fa7ab] | 55 |
|
---|
[8a64320e] | 56 | /** Gap between IEEE80211 channels in MHz. */
|
---|
| 57 | #define IEEE80211_CHANNEL_GAP 5
|
---|
[59fa7ab] | 58 |
|
---|
[8a64320e] | 59 | /** Max AMPDU factor. */
|
---|
| 60 | #define IEEE80211_MAX_AMPDU_FACTOR 13
|
---|
[1dcc0b9] | 61 |
|
---|
[8a64320e] | 62 | /** Max authentication password length. */
|
---|
| 63 | #define IEEE80211_MAX_PASSW_LEN 64
|
---|
[1dcc0b9] | 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 |
|
---|
[59fa7ab] | 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 |
|
---|
[1dcc0b9] | 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 |
|
---|
[a931b7b] | 84 | typedef enum {
|
---|
| 85 | IEEE80211_TKIP_TX_MIC_OFFSET = 16,
|
---|
| 86 | IEEE80211_TKIP_RX_MIC_OFFSET = 24
|
---|
| 87 | } ieee80211_tkip_mic_offset_t;
|
---|
| 88 |
|
---|
[1dcc0b9] | 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 |
|
---|
[59fa7ab] | 97 | /** IEEE 802.11 callback functions. */
|
---|
| 98 | typedef struct {
|
---|
[8a64320e] | 99 | /** unction that is called at device initalization.
|
---|
| 100 | *
|
---|
| 101 | * This should get device into running state.
|
---|
| 102 | *
|
---|
[59fa7ab] | 103 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
[8a64320e] | 104 | *
|
---|
[cde999a] | 105 | * @return EOK if succeed, error code otherwise.
|
---|
[8a64320e] | 106 | *
|
---|
[59fa7ab] | 107 | */
|
---|
| 108 | int (*start)(struct ieee80211_dev *);
|
---|
| 109 |
|
---|
[8a64320e] | 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 | *
|
---|
[59fa7ab] | 115 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
[8a64320e] | 116 | *
|
---|
[cde999a] | 117 | * @return EOK if succeed, error code otherwise.
|
---|
[8a64320e] | 118 | *
|
---|
[59fa7ab] | 119 | */
|
---|
| 120 | int (*scan)(struct ieee80211_dev *);
|
---|
| 121 |
|
---|
[8a64320e] | 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 | *
|
---|
[59fa7ab] | 127 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
[8a64320e] | 128 | * @param buffer Buffer with data to be send.
|
---|
| 129 | * @param buffer_size Size of buffer.
|
---|
| 130 | *
|
---|
[cde999a] | 131 | * @return EOK if succeed, error code otherwise.
|
---|
[8a64320e] | 132 | *
|
---|
[59fa7ab] | 133 | */
|
---|
| 134 | int (*tx_handler)(struct ieee80211_dev *, void *, size_t);
|
---|
| 135 |
|
---|
[8a64320e] | 136 | /** Set device operating frequency to given value.
|
---|
| 137 | *
|
---|
[59fa7ab] | 138 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
[8a64320e] | 139 | * @param freq New device operating frequency.
|
---|
| 140 | *
|
---|
[cde999a] | 141 | * @return EOK if succeed, error code otherwise.
|
---|
[8a64320e] | 142 | *
|
---|
[59fa7ab] | 143 | */
|
---|
| 144 | int (*set_freq)(struct ieee80211_dev *, uint16_t);
|
---|
[1dcc0b9] | 145 |
|
---|
[8a64320e] | 146 | /** Callback to inform device about BSSID change.
|
---|
| 147 | *
|
---|
[1dcc0b9] | 148 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
[8a64320e] | 149 | * @param connected True if connected to new BSSID, otherwise false.
|
---|
| 150 | *
|
---|
[cde999a] | 151 | * @return EOK if succeed, error code otherwise.
|
---|
[8a64320e] | 152 | *
|
---|
[1dcc0b9] | 153 | */
|
---|
[053fc2b] | 154 | int (*bssid_change)(struct ieee80211_dev *, bool);
|
---|
[1dcc0b9] | 155 |
|
---|
[8a64320e] | 156 | /** Callback to setup encryption key in IEEE 802.11 device.
|
---|
| 157 | *
|
---|
[1dcc0b9] | 158 | * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
|
---|
[8a64320e] | 159 | * @param key_conf Key config structure.
|
---|
| 160 | * @param insert True to insert this key to device,
|
---|
| 161 | * false to remove it.
|
---|
| 162 | *
|
---|
[cde999a] | 163 | * @return EOK if succeed, error code otherwise.
|
---|
[8a64320e] | 164 | *
|
---|
[1dcc0b9] | 165 | */
|
---|
[8a64320e] | 166 | int (*key_config)(struct ieee80211_dev *,
|
---|
| 167 | ieee80211_key_config_t *key_conf, bool);
|
---|
[59fa7ab] | 168 | } ieee80211_ops_t;
|
---|
| 169 |
|
---|
| 170 | /* Initialization functions. */
|
---|
| 171 | extern ieee80211_dev_t *ieee80211_device_create(void);
|
---|
[8a64320e] | 172 | extern int ieee80211_device_init(ieee80211_dev_t *, ddf_dev_t *);
|
---|
| 173 | extern int ieee80211_init(ieee80211_dev_t *, ieee80211_ops_t *,
|
---|
| 174 | ieee80211_iface_t *, nic_iface_t *, ddf_dev_ops_t *);
|
---|
[59fa7ab] | 175 |
|
---|
| 176 | /* Getters & setters, queries & reports. */
|
---|
[8a64320e] | 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
|
---|
| 181 | ieee80211_query_current_op_mode(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);
|
---|
[59fa7ab] | 201 |
|
---|
| 202 | /* Worker functions. */
|
---|
[8a64320e] | 203 | extern int ieee80211_rx_handler(ieee80211_dev_t *, void *, size_t);
|
---|
[59fa7ab] | 204 |
|
---|
[8a64320e] | 205 | #endif
|
---|
[59fa7ab] | 206 |
|
---|
| 207 | /** @}
|
---|
| 208 | */
|
---|