[59fa7ab] | 1 | /*
|
---|
| 2 | * Copyright (c) 2014 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 | /** @file htc.h
|
---|
| 30 | *
|
---|
[8a64320e] | 31 | * Definitions of the Atheros HTC (Host Target Communication) technology
|
---|
[59fa7ab] | 32 | * for communication between host (PC) and target (device firmware).
|
---|
| 33 | *
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef ATHEROS_HTC_H
|
---|
[8a64320e] | 37 | #define ATHEROS_HTC_H
|
---|
[59fa7ab] | 38 |
|
---|
| 39 | #include <ieee80211.h>
|
---|
[fb1007ef] | 40 | #include <fibril_synch.h>
|
---|
[59fa7ab] | 41 | #include <usb/dev/driver.h>
|
---|
[8d2dd7f2] | 42 | #include <stddef.h>
|
---|
| 43 | #include <stdint.h>
|
---|
[59fa7ab] | 44 | #include <nic.h>
|
---|
| 45 | #include "ath.h"
|
---|
| 46 |
|
---|
[8a64320e] | 47 | #define HTC_RTS_THRESHOLD 2304
|
---|
| 48 | #define HTC_RATES_MAX_LENGTH 30
|
---|
[59fa7ab] | 49 |
|
---|
[8a64320e] | 50 | /** HTC message IDs.
|
---|
| 51 | *
|
---|
[59fa7ab] | 52 | */
|
---|
| 53 | typedef enum {
|
---|
| 54 | HTC_MESSAGE_READY = 1,
|
---|
| 55 | HTC_MESSAGE_CONNECT_SERVICE,
|
---|
[8a64320e] | 56 | HTC_MESSAGE_CONNECT_SERVICE_RESPONSE,
|
---|
| 57 | HTC_MESSAGE_SETUP_COMPLETE,
|
---|
| 58 | HTC_MESSAGE_CONFIG
|
---|
[59fa7ab] | 59 | } htc_message_id_t;
|
---|
| 60 |
|
---|
[8a64320e] | 61 | /** HTC response message status codes.
|
---|
| 62 | *
|
---|
[59fa7ab] | 63 | */
|
---|
| 64 | typedef enum {
|
---|
[8a64320e] | 65 | HTC_SERVICE_SUCCESS = 0,
|
---|
| 66 | HTC_SERVICE_NOT_FOUND,
|
---|
| 67 | HTC_SERVICE_FAILED,
|
---|
| 68 | HTC_SERVICE_NO_RESOURCES,
|
---|
| 69 | HTC_SERVICE_NO_MORE_EP
|
---|
[59fa7ab] | 70 | } htc_response_status_code_t;
|
---|
| 71 |
|
---|
[8a64320e] | 72 | /** HTC operating mode definition.
|
---|
| 73 | *
|
---|
[59fa7ab] | 74 | */
|
---|
| 75 | typedef enum {
|
---|
| 76 | HTC_OPMODE_ADHOC = 0,
|
---|
| 77 | HTC_OPMODE_STATION = 1,
|
---|
| 78 | HTC_OPMODE_MESH = 2,
|
---|
| 79 | HTC_OPMODE_AP = 6
|
---|
| 80 | } htc_operating_mode_t;
|
---|
| 81 |
|
---|
[8a64320e] | 82 | /** HTC data type indicator.
|
---|
| 83 | *
|
---|
[1dcc0b9] | 84 | */
|
---|
| 85 | typedef enum {
|
---|
| 86 | HTC_DATA_AMPDU = 1,
|
---|
| 87 | HTC_DATA_NORMAL = 2,
|
---|
| 88 | HTC_DATA_BEACON = 3,
|
---|
| 89 | HTC_DATA_MGMT = 4
|
---|
| 90 | } htc_data_type_t;
|
---|
| 91 |
|
---|
[8a64320e] | 92 | /** HTC endpoint numbers.
|
---|
| 93 | *
|
---|
[59fa7ab] | 94 | */
|
---|
| 95 | typedef struct {
|
---|
[8a64320e] | 96 | int ctrl_endpoint;
|
---|
[59fa7ab] | 97 | int wmi_endpoint;
|
---|
| 98 | int beacon_endpoint;
|
---|
| 99 | int cab_endpoint;
|
---|
| 100 | int uapsd_endpoint;
|
---|
| 101 | int mgmt_endpoint;
|
---|
| 102 | int data_be_endpoint;
|
---|
| 103 | int data_bk_endpoint;
|
---|
| 104 | int data_video_endpoint;
|
---|
| 105 | int data_voice_endpoint;
|
---|
| 106 | } htc_pipes_t;
|
---|
| 107 |
|
---|
[8a64320e] | 108 | /** HTC device data.
|
---|
| 109 | *
|
---|
[59fa7ab] | 110 | */
|
---|
| 111 | typedef struct {
|
---|
[8a64320e] | 112 | /** WMI message sequence number */
|
---|
| 113 | uint16_t sequence_number;
|
---|
[a35b458] | 114 |
|
---|
[59fa7ab] | 115 | /** HTC endpoints numbers */
|
---|
| 116 | htc_pipes_t endpoints;
|
---|
[a35b458] | 117 |
|
---|
[59fa7ab] | 118 | /** Lock for receiver */
|
---|
| 119 | fibril_mutex_t rx_lock;
|
---|
[a35b458] | 120 |
|
---|
[59fa7ab] | 121 | /** Lock for transmitter */
|
---|
| 122 | fibril_mutex_t tx_lock;
|
---|
[a35b458] | 123 |
|
---|
[59fa7ab] | 124 | /** Pointer to related IEEE 802.11 device */
|
---|
| 125 | ieee80211_dev_t *ieee80211_dev;
|
---|
[a35b458] | 126 |
|
---|
[59fa7ab] | 127 | /** Pointer to Atheros WiFi device structure */
|
---|
| 128 | ath_t *ath_device;
|
---|
| 129 | } htc_device_t;
|
---|
| 130 |
|
---|
[8a64320e] | 131 | /** HTC frame header structure.
|
---|
| 132 | *
|
---|
[59fa7ab] | 133 | */
|
---|
| 134 | typedef struct {
|
---|
[8a64320e] | 135 | uint8_t endpoint_id;
|
---|
| 136 | uint8_t flags;
|
---|
| 137 | uint16_t payload_length; /**< Big Endian value! */
|
---|
| 138 | uint8_t control_bytes[4];
|
---|
[59fa7ab] | 139 | } __attribute__((packed)) htc_frame_header_t;
|
---|
| 140 |
|
---|
[8a64320e] | 141 | /** HTC management TX frame header structure.
|
---|
| 142 | *
|
---|
[59fa7ab] | 143 | */
|
---|
| 144 | typedef struct {
|
---|
| 145 | uint8_t node_idx;
|
---|
| 146 | uint8_t vif_idx;
|
---|
| 147 | uint8_t tidno;
|
---|
| 148 | uint8_t flags;
|
---|
| 149 | uint8_t key_type;
|
---|
| 150 | uint8_t keyix;
|
---|
| 151 | uint8_t cookie;
|
---|
| 152 | uint8_t pad;
|
---|
| 153 | } __attribute__((packed)) htc_tx_management_header_t;
|
---|
| 154 |
|
---|
[8a64320e] | 155 | /** HTC data TX frame header structure.
|
---|
| 156 | *
|
---|
[1dcc0b9] | 157 | */
|
---|
| 158 | typedef struct {
|
---|
| 159 | uint8_t data_type;
|
---|
| 160 | uint8_t node_idx;
|
---|
| 161 | uint8_t vif_idx;
|
---|
| 162 | uint8_t tidno;
|
---|
[8a64320e] | 163 | uint32_t flags; /**< Big Endian value! */
|
---|
[1dcc0b9] | 164 | uint8_t key_type;
|
---|
| 165 | uint8_t keyix;
|
---|
| 166 | uint8_t cookie;
|
---|
| 167 | uint8_t pad;
|
---|
| 168 | } __attribute__((packed)) htc_tx_data_header_t;
|
---|
| 169 |
|
---|
[8a64320e] | 170 | /** HTC ready message structure.
|
---|
| 171 | *
|
---|
[59fa7ab] | 172 | */
|
---|
| 173 | typedef struct {
|
---|
[8a64320e] | 174 | uint16_t message_id; /**< Big Endian value! */
|
---|
| 175 | uint16_t credits; /**< Big Endian value! */
|
---|
| 176 | uint16_t credit_size; /**< Big Endian value! */
|
---|
[a35b458] | 177 |
|
---|
[8a64320e] | 178 | uint8_t max_endpoints;
|
---|
[59fa7ab] | 179 | uint8_t pad;
|
---|
| 180 | } __attribute__((packed)) htc_ready_msg_t;
|
---|
| 181 |
|
---|
[8a64320e] | 182 | /** HTC service message structure.
|
---|
| 183 | *
|
---|
[59fa7ab] | 184 | */
|
---|
| 185 | typedef struct {
|
---|
[8a64320e] | 186 | uint16_t message_id; /**< Big Endian value! */
|
---|
| 187 | uint16_t service_id; /**< Big Endian value! */
|
---|
| 188 | uint16_t connection_flags; /**< Big Endian value! */
|
---|
[a35b458] | 189 |
|
---|
[59fa7ab] | 190 | uint8_t download_pipe_id;
|
---|
| 191 | uint8_t upload_pipe_id;
|
---|
| 192 | uint8_t service_meta_length;
|
---|
| 193 | uint8_t pad;
|
---|
| 194 | } __attribute__((packed)) htc_service_msg_t;
|
---|
| 195 |
|
---|
[8a64320e] | 196 | /** HTC service response message structure.
|
---|
| 197 | *
|
---|
[59fa7ab] | 198 | */
|
---|
| 199 | typedef struct {
|
---|
[8a64320e] | 200 | uint16_t message_id; /**< Big Endian value! */
|
---|
| 201 | uint16_t service_id; /**< Big Endian value! */
|
---|
| 202 | uint8_t status;
|
---|
| 203 | uint8_t endpoint_id;
|
---|
| 204 | uint16_t max_message_length; /**< Big Endian value! */
|
---|
| 205 | uint8_t service_meta_length;
|
---|
| 206 | uint8_t pad;
|
---|
[59fa7ab] | 207 | } __attribute__((packed)) htc_service_resp_msg_t;
|
---|
| 208 |
|
---|
[8a64320e] | 209 | /** HTC credits config message structure.
|
---|
| 210 | *
|
---|
[59fa7ab] | 211 | */
|
---|
| 212 | typedef struct {
|
---|
[8a64320e] | 213 | uint16_t message_id; /**< Big Endian value! */
|
---|
| 214 | uint8_t pipe_id;
|
---|
| 215 | uint8_t credits;
|
---|
[59fa7ab] | 216 | } __attribute__((packed)) htc_config_msg_t;
|
---|
| 217 |
|
---|
[8a64320e] | 218 | /** HTC new virtual interface message.
|
---|
| 219 | *
|
---|
[59fa7ab] | 220 | */
|
---|
| 221 | typedef struct {
|
---|
[8a64320e] | 222 | uint8_t index;
|
---|
[59fa7ab] | 223 | uint8_t op_mode;
|
---|
| 224 | uint8_t addr[ETH_ADDR];
|
---|
| 225 | uint8_t ath_cap;
|
---|
[8a64320e] | 226 | uint16_t rts_thres; /**< Big Endian value! */
|
---|
[59fa7ab] | 227 | uint8_t pad;
|
---|
| 228 | } __attribute__((packed)) htc_vif_msg_t;
|
---|
| 229 |
|
---|
[8a64320e] | 230 | /** HTC new station message.
|
---|
| 231 | *
|
---|
[59fa7ab] | 232 | */
|
---|
| 233 | typedef struct {
|
---|
| 234 | uint8_t addr[ETH_ADDR];
|
---|
| 235 | uint8_t bssid[ETH_ADDR];
|
---|
[8a64320e] | 236 | uint8_t sta_index;
|
---|
[59fa7ab] | 237 | uint8_t vif_index;
|
---|
| 238 | uint8_t is_vif_sta;
|
---|
[a35b458] | 239 |
|
---|
[8a64320e] | 240 | uint16_t flags; /**< Big Endian value! */
|
---|
| 241 | uint16_t ht_cap; /**< Big Endian value! */
|
---|
| 242 | uint16_t max_ampdu; /**< Big Endian value! */
|
---|
[a35b458] | 243 |
|
---|
[59fa7ab] | 244 | uint8_t pad;
|
---|
| 245 | } __attribute__((packed)) htc_sta_msg_t;
|
---|
| 246 |
|
---|
[8a64320e] | 247 | /** HTC message to inform target about available capabilities.
|
---|
| 248 | *
|
---|
[59fa7ab] | 249 | */
|
---|
| 250 | typedef struct {
|
---|
[8a64320e] | 251 | uint32_t ampdu_limit; /**< Big Endian value! */
|
---|
[59fa7ab] | 252 | uint8_t ampdu_subframes;
|
---|
| 253 | uint8_t enable_coex;
|
---|
| 254 | uint8_t tx_chainmask;
|
---|
| 255 | uint8_t pad;
|
---|
| 256 | } __attribute__((packed)) htc_cap_msg_t;
|
---|
| 257 |
|
---|
[1dcc0b9] | 258 | typedef struct {
|
---|
| 259 | uint8_t sta_index;
|
---|
| 260 | uint8_t is_new;
|
---|
[8a64320e] | 261 | uint32_t cap_flags; /**< Big Endian value! */
|
---|
[1dcc0b9] | 262 | uint8_t legacy_rates_count;
|
---|
| 263 | uint8_t legacy_rates[HTC_RATES_MAX_LENGTH];
|
---|
| 264 | uint16_t pad;
|
---|
| 265 | } htc_rate_msg_t;
|
---|
| 266 |
|
---|
[8a64320e] | 267 | /** HTC RX status structure used in incoming HTC data messages.
|
---|
| 268 | *
|
---|
[1dcc0b9] | 269 | */
|
---|
| 270 | typedef struct {
|
---|
[8a64320e] | 271 | uint64_t timestamp; /**< Big Endian value! */
|
---|
| 272 | uint16_t data_length; /**< Big Endian value! */
|
---|
[1dcc0b9] | 273 | uint8_t status;
|
---|
| 274 | uint8_t phy_err;
|
---|
| 275 | int8_t rssi;
|
---|
| 276 | int8_t rssi_ctl[3];
|
---|
| 277 | int8_t rssi_ext[3];
|
---|
| 278 | uint8_t keyix;
|
---|
| 279 | uint8_t rate;
|
---|
| 280 | uint8_t antenna;
|
---|
| 281 | uint8_t more;
|
---|
| 282 | uint8_t is_aggr;
|
---|
| 283 | uint8_t more_aggr;
|
---|
| 284 | uint8_t num_delims;
|
---|
| 285 | uint8_t flags;
|
---|
| 286 | uint8_t dummy;
|
---|
[8a64320e] | 287 | uint32_t evm0; /**< Big Endian value! */
|
---|
| 288 | uint32_t evm1; /**< Big Endian value! */
|
---|
| 289 | uint32_t evm2; /**< Big Endian value! */
|
---|
[1dcc0b9] | 290 | } htc_rx_status_t;
|
---|
| 291 |
|
---|
[8a64320e] | 292 | /** HTC setup complete message structure
|
---|
| 293 | *
|
---|
[59fa7ab] | 294 | */
|
---|
| 295 | typedef struct {
|
---|
[8a64320e] | 296 | uint16_t message_id; /**< Big Endian value! */
|
---|
[59fa7ab] | 297 | } __attribute__((packed)) htc_setup_complete_msg_t;
|
---|
| 298 |
|
---|
[b7fd2a0] | 299 | extern errno_t htc_device_init(ath_t *, ieee80211_dev_t *, htc_device_t *);
|
---|
| 300 | extern errno_t htc_init(htc_device_t *);
|
---|
| 301 | extern errno_t htc_init_new_vif(htc_device_t *);
|
---|
| 302 | extern errno_t htc_read_control_message(htc_device_t *, void *, size_t, size_t *);
|
---|
| 303 | extern errno_t htc_read_data_message(htc_device_t *, void *, size_t, size_t *);
|
---|
| 304 | extern errno_t htc_send_control_message(htc_device_t *, void *, size_t, uint8_t);
|
---|
| 305 | extern errno_t htc_send_data_message(htc_device_t *, void *, size_t, uint8_t);
|
---|
[59fa7ab] | 306 |
|
---|
[8a64320e] | 307 | #endif /* ATHEROS_HTC_H */
|
---|