[ab365c4] | 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>
|
---|
[56c0930] | 43 | #include <nic.h>
|
---|
[ab365c4] | 44 |
|
---|
| 45 | /** Initial channel frequency. */
|
---|
[56c0930] | 46 | #define IEEE80211_FIRST_FREQ 2412
|
---|
[ab365c4] | 47 |
|
---|
| 48 | /** Max supported channel frequency. */
|
---|
[56c0930] | 49 | #define IEEE80211_MAX_FREQ 2472
|
---|
[ab365c4] | 50 |
|
---|
| 51 | /* Gap between IEEE80211 channels in MHz. */
|
---|
| 52 | #define IEEE80211_CHANNEL_GAP 5
|
---|
| 53 |
|
---|
[56c0930] | 54 | #define IEEE80211_FRAME_CTRL_FRAME_TYPE 0x000C
|
---|
| 55 | #define IEEE80211_FRAME_CTRL_DATA_FRAME 0x0008
|
---|
| 56 |
|
---|
[ab365c4] | 57 | struct ieee80211_dev;
|
---|
| 58 |
|
---|
| 59 | /** Device operating modes. */
|
---|
| 60 | typedef enum {
|
---|
| 61 | IEEE80211_OPMODE_ADHOC,
|
---|
| 62 | IEEE80211_OPMODE_MESH,
|
---|
| 63 | IEEE80211_OPMODE_AP,
|
---|
| 64 | IEEE80211_OPMODE_STATION
|
---|
| 65 | } ieee80211_operating_mode_t;
|
---|
| 66 |
|
---|
| 67 | /** IEEE 802.11 functions. */
|
---|
| 68 | typedef struct {
|
---|
| 69 | int (*start)(struct ieee80211_dev *);
|
---|
| 70 | int (*scan)(struct ieee80211_dev *);
|
---|
[56c0930] | 71 | int (*tx_handler)(struct ieee80211_dev *, void *, size_t);
|
---|
[ab365c4] | 72 | } ieee80211_ops_t;
|
---|
| 73 |
|
---|
| 74 | /** IEEE 802.11 WiFi device structure. */
|
---|
| 75 | typedef struct ieee80211_dev {
|
---|
| 76 | /** Backing DDF device. */
|
---|
| 77 | ddf_dev_t *ddf_dev;
|
---|
| 78 |
|
---|
| 79 | /** Pointer to implemented IEEE 802.11 operations. */
|
---|
| 80 | ieee80211_ops_t *ops;
|
---|
| 81 |
|
---|
| 82 | /** Pointer to driver specific data. */
|
---|
| 83 | void *driver_data;
|
---|
[56c0930] | 84 |
|
---|
| 85 | /** Current operating frequency. */
|
---|
| 86 | uint16_t current_freq;
|
---|
| 87 |
|
---|
| 88 | /** Current operating mode. */
|
---|
| 89 | ieee80211_operating_mode_t current_op_mode;
|
---|
| 90 |
|
---|
| 91 | /* TODO: Probably to be removed later - nic.open function is now
|
---|
| 92 | * executed multiple times, have to find out reason and fix it.
|
---|
| 93 | */
|
---|
| 94 | /** Indicates whether driver has already started. */
|
---|
| 95 | bool started;
|
---|
[ab365c4] | 96 | } ieee80211_dev_t;
|
---|
| 97 |
|
---|
[56c0930] | 98 | /** IEEE 802.11 header structure. */
|
---|
| 99 | typedef struct {
|
---|
| 100 | uint16_t frame_ctrl; /**< Little Endian value! */
|
---|
| 101 | uint16_t duration_id; /**< Little Endian value! */
|
---|
| 102 | uint8_t address1[ETH_ADDR];
|
---|
| 103 | uint8_t address2[ETH_ADDR];
|
---|
| 104 | uint8_t address3[ETH_ADDR];
|
---|
| 105 | uint16_t seq_ctrl; /**< Little Endian value! */
|
---|
| 106 | uint8_t address4[ETH_ADDR];
|
---|
| 107 | } __attribute__((packed)) __attribute__ ((aligned(2))) ieee80211_header_t;
|
---|
| 108 |
|
---|
| 109 | extern bool ieee80211_is_data_frame(ieee80211_header_t *header);
|
---|
[ab365c4] | 110 | extern int ieee80211_device_init(ieee80211_dev_t *ieee80211_dev,
|
---|
| 111 | void *driver_data, ddf_dev_t *ddf_dev);
|
---|
| 112 | extern int ieee80211_init(ieee80211_dev_t *ieee80211_dev,
|
---|
| 113 | ieee80211_ops_t *ieee80211_ops);
|
---|
| 114 |
|
---|
| 115 | #endif /* LIBNET_IEEE80211_H */
|
---|
| 116 |
|
---|
| 117 | /** @}
|
---|
| 118 | */
|
---|