Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef _DEFINITIONS_H_ |
| 31 | #define _DEFINITIONS_H_ |
| 32 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 33 | #include <map> |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 34 | #include <string> |
| 35 | #include <cstdint> |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 36 | #include <tuple> |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 37 | #include "Utils.h" |
| 38 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 39 | // FW Defines |
| 40 | #define MAX_RF_NUMBER 8 |
| 41 | |
| 42 | |
| 43 | #define FW_ASSERT_REG 0x91F020 |
| 44 | #define UCODE_ASSERT_REG 0x91F028 |
| 45 | #define FW_ASSOCIATION_REG 0x880A44 |
| 46 | #define FW_ASSOCIATED_VALUE 0x6 |
| 47 | #define MCS_REG 0x880A60 |
| 48 | #define DEVICE_TYPE_REG 0x880A8C |
| 49 | #define FW_MODE_REG 0x880A34 |
| 50 | #define BOOT_LOADER_VERSION_REG 0x880A0C |
| 51 | #define CHANNEL_REG 0x883020 |
| 52 | #define BOARDFILE_REG 0x880014 |
| 53 | |
| 54 | #define UCODE_RX_ON_REG 0x9405BE |
| 55 | #define BF_SEQ_REG 0x941374 |
| 56 | #define BF_TRIG_REG 0x941380 |
| 57 | #define NAV_REG 0x940490 |
| 58 | #define TX_GP_REG 0x880A58 |
| 59 | #define RX_GP_REG 0x880A5C |
| 60 | |
| 61 | #define RF_CONNECTED_REG 0x889488 |
| 62 | #define RF_ENABLED_REG 0x889488 |
| 63 | |
| 64 | #define BASEBAND_TEMPERATURE_REG 0x91c808 |
| 65 | #define RF_TEMPERATURE_REG 0x91c80c |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 66 | |
| 67 | // ************************************************************************************************* |
| 68 | /* |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 69 | * The reply data may be generated in several ways, the data is expected to be obtained according to this type |
| 70 | */ |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 71 | enum REPLY_TYPE |
| 72 | { |
| 73 | REPLY_TYPE_NONE, |
| 74 | REPLY_TYPE_BUFFER, |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 75 | REPLY_TYPE_FILE, |
| 76 | REPLY_TYPE_WAIT_BINARY, |
| 77 | REPLY_TYPE_BINARY |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | // ************************************************************************************************* |
| 81 | /* |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 82 | * A response to the client, through the servers |
| 83 | */ |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 84 | struct ResponseMessage |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 85 | { |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 86 | ResponseMessage() : |
| 87 | type(REPLY_TYPE_NONE), |
| 88 | length(0U), |
| 89 | binaryMessage(nullptr), |
| 90 | inputBufSize(0U) |
| 91 | {} |
| 92 | |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 93 | std::string message; |
| 94 | REPLY_TYPE type; |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 95 | size_t length; |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 96 | uint8_t* binaryMessage; |
| 97 | vector<string> internalParsedMessage; |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 98 | unsigned inputBufSize; |
| 99 | }; |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 100 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 101 | // ************************************************************************************************* |
| 102 | /* A response to the user in CLI mode |
| 103 | */ |
| 104 | struct Status |
| 105 | { |
| 106 | Status() : |
| 107 | m_success(true), |
| 108 | m_message("") {} |
| 109 | |
| 110 | Status(bool success, std::string message) : |
| 111 | m_success(success), |
| 112 | m_message(message) {} |
| 113 | |
| 114 | bool m_success; |
| 115 | std::string m_message; |
| 116 | }; |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 117 | |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 118 | // ************************************************************************************************* |
| 119 | /* |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 120 | * ConnectionStatus indicates whether to close a connection with a client or not. |
| 121 | */ |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 122 | enum ConnectionStatus |
| 123 | { |
| 124 | CLOSE_CONNECTION, |
| 125 | KEEP_CONNECTION_ALIVE |
| 126 | }; |
| 127 | |
| 128 | // **************************** Events Structures and Enum Types ************************************** |
| 129 | /* |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 130 | * Define an event struct which would be sent as Json string. |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 131 | * NOTE that the __exactly__ same struct is defined in the side that gets this struct. |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 132 | */ |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 133 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 134 | struct FwVersion |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 135 | { |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 136 | DWORD m_major; |
| 137 | DWORD m_minor; |
| 138 | DWORD m_subMinor; |
| 139 | DWORD m_build; |
| 140 | |
| 141 | FwVersion() : |
| 142 | m_major(0), m_minor(0), m_subMinor(0), m_build(0) |
| 143 | {} |
| 144 | |
| 145 | bool operator==(const FwVersion& rhs) const |
| 146 | { |
| 147 | return std::tie(m_major, m_minor, m_subMinor, m_build) == std::tie(rhs.m_major, rhs.m_minor, rhs.m_subMinor, rhs.m_build); |
| 148 | } |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 149 | }; |
| 150 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 151 | struct FwTimestamp |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 152 | { |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 153 | FwTimestamp() : |
| 154 | m_hour(0), m_min(0), m_sec(0), m_day(0), m_month(0), m_year(0) |
| 155 | {} |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 156 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 157 | DWORD m_hour; |
| 158 | DWORD m_min; |
| 159 | DWORD m_sec; |
| 160 | DWORD m_day; |
| 161 | DWORD m_month; |
| 162 | DWORD m_year; |
| 163 | |
| 164 | bool operator==(const FwTimestamp& rhs) const |
| 165 | { |
| 166 | return std::tie(m_hour, m_min, m_sec, m_day, m_month, m_year) == std::tie(rhs.m_hour, rhs.m_min, rhs.m_sec, rhs.m_day, rhs.m_month, rhs.m_year); |
| 167 | } |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 168 | }; |
| 169 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 170 | //enum DRIVER_MODE |
| 171 | //{ |
| 172 | // IOCTL_WBE_MODE, |
| 173 | // IOCTL_WIFI_STA_MODE, |
| 174 | // IOCTL_WIFI_SOFTAP_MODE, |
| 175 | // IOCTL_CONCURRENT_MODE, // This mode is for a full concurrent implementation (not required mode switch between WBE/WIFI/SOFTAP) |
| 176 | // IOCTL_SAFE_MODE, // A safe mode required for driver for protected flows like upgrade and crash dump... |
| 177 | //}; |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 178 | |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 179 | // ************************************************************************************************* |
| 180 | |
| 181 | #define MAX_REGS_LEN (256* 1024) // Max registers to read/write at once //TODO - is it needed? maybe read until line terminator? |
| 182 | |
| 183 | // Max buffer size for a command and a reply. We should consider the longest command/data sequence to fit in a buffer. |
| 184 | // rb reading 1024 (MAX_REGS_LEN) registers: rb HHHHHHHH HHHH 1024*(0xHHHHHHHH) = 17 + 1024*10 = 10257 bytes |
| 185 | // wb writing 1024 (MAX_REGS_LEN) hex values: wb HHHHHHHH "1024*HH" = 14+1024*2 = 2062 bytes |
| 186 | #define MAX_INPUT_BUF (11*MAX_REGS_LEN) //TODO - is it needed? maybe read until line terminator? |
| 187 | |
| 188 | // ************************************************************************************************* |
| 189 | |
| 190 | struct HostIps |
| 191 | { |
| 192 | HostIps() : |
| 193 | m_ip(""), |
| 194 | m_broadcastIp("") |
| 195 | {} |
| 196 | |
| 197 | std::string m_ip; // host's IP address |
| 198 | std::string m_broadcastIp; // host's broadcast IP address (derivated by subnet mask) |
| 199 | }; |
| 200 | |
| 201 | // ************************************************************************************************* |
| 202 | |
| 203 | enum ServerType |
| 204 | { |
| 205 | stTcp, |
| 206 | stUdp |
| 207 | }; |
| 208 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 209 | const int SECOND_IN_MILLISECONDS = 1000; |
| 210 | |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 211 | #endif // !_DEFINITIONS_H_ |