Home | History | Annotate | Download | only in rmidevice
      1 /*
      2  * Copyright (C) 2014 Andrew Duggan
      3  * Copyright (C) 2014 Synaptics Inc
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 #ifndef _HIDDEVICE_H_
     19 #define _HIDDEVICE_H_
     20 
     21 #include <linux/hidraw.h>
     22 #include <string>
     23 #include "rmidevice.h"
     24 
     25 class HIDDevice : public RMIDevice
     26 {
     27 public:
     28 	HIDDevice() : RMIDevice(), m_inputReport(NULL), m_outputReport(NULL), m_attnData(NULL),
     29 		      m_readData(NULL),
     30 		      m_inputReportSize(0),
     31 		      m_outputReportSize(0),
     32 		      m_featureReportSize(0),
     33 		      m_deviceOpen(false)
     34 	{}
     35 	virtual int Open(const char * filename);
     36 	virtual int Read(unsigned short addr, unsigned char *buf,
     37 				unsigned short len);
     38 	virtual int Write(unsigned short addr, const unsigned char *buf,
     39 				 unsigned short len);
     40 	virtual int SetMode(int mode);
     41 	virtual int WaitForAttention(struct timeval * timeout = NULL,
     42 					unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK);
     43 	virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask,
     44 					unsigned char *buf, unsigned int *len);
     45 	virtual void Close();
     46 	virtual void RebindDriver();
     47 	~HIDDevice() { Close(); }
     48 
     49 	virtual void PrintDeviceInfo();
     50 
     51 private:
     52 	int m_fd;
     53 
     54 	struct hidraw_report_descriptor m_rptDesc;
     55 	struct hidraw_devinfo m_info;
     56 
     57 	unsigned char *m_inputReport;
     58 	unsigned char *m_outputReport;
     59 
     60 	unsigned char *m_attnData;
     61 	unsigned char *m_readData;
     62 	int m_dataBytesRead;
     63 
     64 	size_t m_inputReportSize;
     65 	size_t m_outputReportSize;
     66 	size_t m_featureReportSize;
     67 
     68 	bool m_deviceOpen;
     69 
     70 	enum mode_type {
     71 		HID_RMI4_MODE_MOUSE			= 0,
     72 		HID_RMI4_MODE_ATTN_REPORTS		= 1,
     73 		HID_RMI4_MODE_NO_PACKED_ATTN_REPORTS	= 2,
     74 	};
     75 
     76 	int GetReport(int *reportId, struct timeval * timeout = NULL);
     77 	void PrintReport(const unsigned char *report);
     78 	void ParseReportSizes();
     79 
     80 	// static HID utility functions
     81 	static bool LookupHidDeviceName(int bus, int vendorId, int productId, std::string &deviceName);
     82 	static bool FindTransportDevice(int bus, std::string & hidDeviceName,
     83 					std::string & transportDeviceName, std::string & driverPath);
     84 	static bool FindHidRawFile(std::string & hidDeviceName, std::string & hidrawFile);
     85  };
     86 
     87 #endif /* _HIDDEVICE_H_ */
     88