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 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 30 | #ifndef _11AD_DRIVER_API_H_ |
| 31 | #define _11AD_DRIVER_API_H_ |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 32 | |
| 33 | #include <string> |
| 34 | #include <set> |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 35 | #include <vector> |
| 36 | #include <sstream> |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 37 | #include <unordered_map> |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 38 | |
| 39 | #include "OperatingSystemConstants.h" |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 40 | #include "Definitions.h" |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 41 | #include "DebugLogger.h" |
| 42 | #include "Utils.h" |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 43 | |
| 44 | using namespace std; |
| 45 | |
| 46 | class DriverAPI |
| 47 | { |
| 48 | public: |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 49 | DriverAPI(string interfaceName): m_interfaceName(interfaceName) |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 50 | { |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 51 | } |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 52 | |
| 53 | virtual ~DriverAPI() {} |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 54 | |
| 55 | // Base access functions (to be implemented by specific device) |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 56 | virtual bool Read(DWORD address, DWORD& value) { return false; } |
| 57 | virtual bool ReadBlock(DWORD addr, DWORD blockSize, vector<DWORD>& values) { return false; } |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 58 | virtual bool ReadBlock(DWORD addr, DWORD blockSize, char *arrBlock) { return false; } // blockSize in bytes |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 59 | virtual bool Write(DWORD address, DWORD value) { return false; } |
| 60 | virtual bool WriteBlock(DWORD addr, vector<DWORD> values) { return false; }; |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 61 | virtual bool WriteBlock(DWORD address, DWORD blockSize, const char *valuesToWrite) { return false; } |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 62 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 63 | // PMC functions |
| 64 | virtual bool AllocPmc(unsigned descSize, unsigned descNum, std::string& outMessage) { return false; } |
| 65 | virtual bool DeallocPmc(std::string& outMessage) { return false; } |
| 66 | virtual bool CreatePmcFile(unsigned refNumber, std::string& outMessage) { return false; } |
| 67 | virtual bool FindPmcFile(unsigned refNumber, std::string& outMessage) { return false; } |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 68 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 69 | virtual bool IsOpen(void) { return false; } |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 70 | virtual bool Open() { return false; } |
| 71 | virtual bool ReOpen() { return false; }; |
Vadim Iosevich | 40679a1 | 2017-06-06 14:24:07 +0300 | [diff] [blame] | 72 | virtual bool DriverControl(uint32_t Id, |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 73 | const void *inBuf, uint32_t inBufSize, |
| 74 | void *outBuf, uint32_t outBufSize, DWORD* pLastError = nullptr) { return false; } |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 75 | virtual void Close() {} |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 76 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 77 | virtual int GetDriverMode(int ¤tState) { return false; } |
| 78 | virtual bool SetDriverMode(int newState, int &oldState) { return false; } |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 79 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 80 | virtual bool RegisterDriverControlEvents() { return false; } |
| 81 | |
Vadim Iosevich | 20d50d8 | 2017-09-19 11:38:15 +0300 | [diff] [blame] | 82 | virtual void Reset() {}; // interface reset |
| 83 | |
| 84 | const string& GetInterfaceName() const |
| 85 | { |
| 86 | return m_interfaceName; |
| 87 | } |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 88 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 89 | bool IsValid() |
| 90 | { |
| 91 | DWORD value; |
| 92 | if (!Read(BAUD_RATE_REGISTER, value)) return false; |
| 93 | return IsValidInternal(); |
| 94 | } |
| 95 | |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 96 | protected: |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 97 | |
| 98 | const string m_interfaceName; |
| 99 | |
| 100 | // Enumeration for commands sent through DriverControl (translating from it to the appropriate command per OS) |
| 101 | // Note: It is a contract with DmTools and the Driver, order is important! |
| 102 | enum DRIVER_COMMAND |
| 103 | { |
| 104 | DRIVER_CMD_FW_WMI, |
| 105 | DRIVER_CMD_GENERIC_COMMAND, |
| 106 | DRIVER_GET_DRIVER_STATISTICS |
| 107 | }; |
| 108 | |
| 109 | std::unordered_map<DRIVER_COMMAND, uint32_t, hash<int>> m_driverCommandToIoctlMap; |
| 110 | |
| 111 | virtual void InsertDriverCommandsToMap() {} |
| 112 | |
| 113 | private: |
| 114 | |
| 115 | virtual bool IsValidInternal() { return true; } |
Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | |
Vadim Iosevich | e76832c | 2017-11-05 09:09:14 +0200 | [diff] [blame] | 119 | #endif //_11AD_DRIVER_API_H_ |