blob: e0877c2c43269b554d88cc61619ee8ad8a19111e [file] [log] [blame]
Vadim Iosevich20d50d82017-09-19 11:38:15 +03001/*
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 Ioseviche76832c2017-11-05 09:09:14 +020047#include "LogCollector.h"
48#include <thread>
Vadim Iosevich20d50d82017-09-19 11:38:15 +030049
50using namespace std;
51
52class Device
53{
54public:
55 explicit Device(const string& deviceName);
56
57 virtual ~Device() {}
58
59 // Functionality common to all devices
60
Vadim Ioseviche76832c2017-11-05 09:09:14 +020061 bool Init();
62
63 bool Fini();
64
Vadim Iosevich20d50d82017-09-19 11:38:15 +030065 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 Ioseviche76832c2017-11-05 09:09:14 +020097 //TODO: make private after blocking simultaneous driver actions
Vadim Iosevich20d50d82017-09-19 11:38:15 +030098 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 Ioseviche76832c2017-11-05 09:09:14 +0200106 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 Iosevich20d50d82017-09-19 11:38:15 +0300125private:
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 Ioseviche76832c2017-11-05 09:09:14 +0200133 map<CpuType,unique_ptr<log_collector::LogCollector>> m_logCollectors;
Vadim Iosevich20d50d82017-09-19 11:38:15 +0300134
135 BasebandType ReadBasebandType() const;
136
Vadim Ioseviche76832c2017-11-05 09:09:14 +0200137 // Custom registers
138 std::map<std::string, int> m_customRegisters;
139
140 bool RegisterDriverControlEvents();
141
Vadim Iosevich20d50d82017-09-19 11:38:15 +0300142 // Internal service for fetching the FW version and compile time
143 bool ReadDeviceFwInfoInternal(FwVersion& fwVersion, FwTimestamp& fwTimestamp) const;
144
Vadim Ioseviche76832c2017-11-05 09:09:14 +0200145 void PollFwVersion(vector<unique_ptr<HostManagerEventBase>>& events);
146 void PollLogs(vector<unique_ptr<HostManagerEventBase>>& events);
147
Vadim Iosevich20d50d82017-09-19 11:38:15 +0300148 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 Ioseviche76832c2017-11-05 09:09:14 +0200161
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 Iosevich20d50d82017-09-19 11:38:15 +0300173};
174
175#endif // !_11AD_DEVICE_H_