Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +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 _11AD_DEVICE_H_ |
| 31 | #define _11AD_DEVICE_H_ |
| 32 | |
| 33 | #include <string> |
| 34 | #include <vector> |
| 35 | #include <set> |
| 36 | #include <iostream> |
| 37 | #include <memory> |
| 38 | #include <mutex> |
| 39 | |
| 40 | #include "OperatingSystemConstants.h" |
| 41 | #include "access_layer_11ad/Definitions.h" |
| 42 | #include "../DebugLogger.h" |
| 43 | #include "../DriverAPI.h" |
| 44 | #include "AccessLayerAPI.h" |
| 45 | #include "EventsDefinitions.h" |
| 46 | #include "HostDefinitions.h" |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 47 | #include "LogCollector.h" |
| 48 | #include <thread> |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 49 | |
| 50 | using namespace std; |
| 51 | |
| 52 | class Device |
| 53 | { |
| 54 | public: |
| 55 | explicit Device(const string& deviceName); |
| 56 | |
| 57 | virtual ~Device() {} |
| 58 | |
| 59 | // Functionality common to all devices |
| 60 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 61 | bool Init(); |
| 62 | |
| 63 | bool Fini(); |
| 64 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 65 | bool IsValid() const { return m_driver != nullptr; } |
| 66 | |
| 67 | const string& GetDeviceName(void) const { return m_deviceName; } |
| 68 | |
| 69 | bool SendWmi(DWORD command, vector<DWORD> payload) |
| 70 | { |
| 71 | //do something with params |
| 72 | (void)command; |
| 73 | (void)payload; |
| 74 | return false; |
| 75 | |
| 76 | } |
| 77 | |
| 78 | vector<DWORD> GetWmiEvent() |
| 79 | { |
| 80 | |
| 81 | vector<DWORD> ret; |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | std::vector<unique_ptr<HostManagerEventBase>> Poll(void); |
| 86 | |
| 87 | // ************************** [END] Device API **********************// |
| 88 | |
| 89 | BasebandType GetBasebandType(); |
| 90 | |
| 91 | bool GetSilenceMode() const { return m_isSilent; } |
| 92 | |
| 93 | void SetSilenceMode(bool silentMode) { m_isSilent = silentMode; } |
| 94 | |
| 95 | DriverAPI* GetDriver() const { return m_driver.get(); } |
| 96 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 97 | //TODO: make private after blocking simultaneous driver actions |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 98 | mutable mutex m_mutex; // threads synchronization |
| 99 | |
| 100 | bool GetIsAlive(void) const { return m_isAlive; } |
| 101 | |
| 102 | const FwVersion& GetFwVersion(void) const { return m_fwVersion; } |
| 103 | |
| 104 | const FwTimestamp& GetFwTimestamp(void) const { return m_fwTimestamp; } |
| 105 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 106 | DWORD GetCapabilities(void) const { return m_capabilitiesMask; } |
| 107 | |
| 108 | // ************************ Log Collector *************************// |
| 109 | bool StartLogCollector(); // TODO - use GetLogCollector functions instead of this one and remove this function |
| 110 | |
| 111 | bool StopLogCollector(); // TODO - use GetLogCollector functions instead of this one and remove this function |
| 112 | |
| 113 | log_collector::LogCollector* GetLogCollector(CpuType type); |
| 114 | |
| 115 | // *********************** [END] Log Collector *******************// |
| 116 | |
| 117 | // ************************ Custom Regs *************************// |
| 118 | bool AddCustomRegister(const string& name, int address); |
| 119 | |
| 120 | bool RemoveCustomRegister(const string& name); |
| 121 | |
| 122 | std::map<string, int>& GetCustomRegisters(); |
| 123 | // *********************** [END] Custom Regs *******************// |
| 124 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 125 | private: |
| 126 | BasebandType m_basebandType; |
| 127 | unique_ptr<DriverAPI> m_driver; |
| 128 | bool m_isSilent; |
| 129 | bool m_isAlive; |
| 130 | string m_deviceName; |
| 131 | FwVersion m_fwVersion; |
| 132 | FwTimestamp m_fwTimestamp; |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 133 | map<CpuType,unique_ptr<log_collector::LogCollector>> m_logCollectors; |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 134 | |
| 135 | BasebandType ReadBasebandType() const; |
| 136 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 137 | // Custom registers |
| 138 | std::map<std::string, int> m_customRegisters; |
| 139 | |
| 140 | bool RegisterDriverControlEvents(); |
| 141 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 142 | // Internal service for fetching the FW version and compile time |
| 143 | bool ReadDeviceFwInfoInternal(FwVersion& fwVersion, FwTimestamp& fwTimestamp) const; |
| 144 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 145 | void PollFwVersion(vector<unique_ptr<HostManagerEventBase>>& events); |
| 146 | void PollLogs(vector<unique_ptr<HostManagerEventBase>>& events); |
| 147 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 148 | enum FwInfoRegisters : DWORD |
| 149 | { |
| 150 | FW_VERSION_MAJOR_REGISTER = 0x880a2c, |
| 151 | FW_VERSION_MINOR_REGISTER = 0x880a30, |
| 152 | FW_VERSION_SUB_MINOR_REGISTER = 0x880a34, |
| 153 | FW_VERSION_BUILD_REGISTER = 0x880a38, |
| 154 | FW_TIMESTAMP_HOUR_REGISTER = 0x880a14, |
| 155 | FW_TIMESTAMP_MINUTE_REGISTER = 0x880a18, |
| 156 | FW_TIMESTAMP_SECOND_REGISTER = 0x880a1c, |
| 157 | FW_TIMESTAMP_DAY_REGISTER = 0x880a20, |
| 158 | FW_TIMESTAMP_MONTH_REGISTER = 0x880a24, |
| 159 | FW_TIMESTAMP_YEAR_REGISTER = 0x880a28 |
| 160 | }; |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 161 | |
| 162 | // Capabilities region: |
| 163 | DWORD m_capabilitiesMask; |
| 164 | |
| 165 | // each value in the enum represents a bit in the DWORD (the values would be 1,2,3,4...) |
| 166 | enum CAPABILITIES : DWORD |
| 167 | { |
| 168 | DRIVER_CONTROL_EVENTS // capability of the driver to send and receive driver control commands and events |
| 169 | }; |
| 170 | |
| 171 | void SetCapability(CAPABILITIES capability, bool isTrue); |
| 172 | bool IsCapabilitySet(CAPABILITIES capability) const; |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | #endif // !_11AD_DEVICE_H_ |