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