Oct 24, 2010
Schedule
Oct 14, 2010
Oct 7, 2010
Today Schedule + some input report things
- Create 3 new classes for readWrite form. They are HID(), win32Keyboard() and handler()
- Integrate the classes into one.
- Spot out the correct process name of the foreground process, then send some hard-coded byte values to the device
- Can read report from device and split it into two modes. The first is modifier and another is non-modifier. Modifier consists of 8Bits defined in HID1_11.pdf. Non-modifier somehow can be found by simple maths.
- Create an ArrayList to store all key pressed first and released all of them at once.
- Make our process running in background. Reference:
- Optimize the program, maybe by minimizing the code size and introducing some algorithms.
- Start debugging. Finding any possible bugs.
- Get URL from Hwnd, have to try.
- Find a way to register hot-key in windows
Oct 4, 2010
- Study the pattern of the values returned. If I press a, b and c at the same time, the pattern becomes 00 00 04 05 06 00... If only a is pressed, it is 00 00 04 00 00 ... If only b is pressed, it is 00 00 05 00 00... We should write a "clever" function to analyze it.
- Integrate the getForegroundProcess program with this library.
- Figure out what should be sent to the widget to identify current running process.
- I forgot to change the flags and control type respectively.
- To write something, nAccess = GENERIC_WRITE; nsharemode= nShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; controlType= 0x02... It is similar if we want to read something.
- The overlapped structure is vital for ReadFile to call. It is originally a blocking call. However, we can change its behavior by feeding an overlapped structure to it. Refers to MSDN, the passage about Readfile.
- createFile is called with many arguments. These arguments should also be called from other winAPIs. We have to provide GUID at some points... (refer to the openDev src code in the class HID and also documentation from MSDN)
- Make reference to genericHID.cs and its author. It gives definition of each winAPI function useful for our HID class.
- Also acknowledge to author of the UseHIDSample.cs
Oct 2, 2010
using winAPI writeFile
- Have to check the flags, what do they mean...
- Have to ensure everything is sent successfully
- Try to lock the device, avoid other windows application sending things to it.
Sep 27, 2010
Can now communicate between gadgets and Windows
- Windows keeps polling the HID keyboard device. This is why we cannot use the generic Winodws API to help us writing report to the gadget device. Indeed, we can try creating a composite device, that is to combine both keyboard and an USB pipe (can be any HID device that not recognized as a system device). This way, windows handles all our key sent and we do have to make a customized program ourselves. To do this, we may have to modify linux device driver code located at: /linux-2.6.35/drivers/usb/gadget/ There are some codes stating the device descriptors. We found a file called autoepdescriptor. However, exploiting it will be not easy.
- Then we stick to a "joystick" approach. The joystick can also be recognized automatically by windows. Unfortunately, at first we enumerate the board as a joystick, the test program failed to send report to our device. We doubt that if this may be due to the absence of the OUT endpoint.
- On the day before mid-autumn festival, I take the board from MF and start investigating the possibility of opening the pipe. I crashed the file system and recovered it following some steps.
- Studying the possibility of adding some output report to the keyboard descriptor, but it fails as usual. One of the M$ document states that a way to make a "multi-functional" keyboard can be done by adding one more collection to the hid descriptor, but it is also not working. I doubt if the HID gadget device sticks to only 1 interrupt endpoint, which is by default 0x81 and that is why we cannot write report to the endpoint. Jan, the writer of the book, suggested that we can send report to the keyboard only by the way of writing feature report. I start trying to figure out why.
- Reading from the book as well as the pdf file from usb.org, I found that there can be only one way to send report to the interrupt IN endpoint. That is through having a control request. I also discovered that indeed the feature report is sent in the way of control transfer (p.328; p.321) when the OUT endpoint is absent. Then I start to enumerate the keyboard with the feature report descriptor. Certainly, it did not work.
- Googling from the web, I saw someone suggests that we can indeed make our customized, or called vendor defined HID. I saw some code from the net. One of them can successfully be implemented on our board. In the past when the HID report descriptor were written wrongly, windows would say "Cannot recognize the device". This time the device manager showed me that one INPUT DEVICE and HID COMPLIANT was installed. Since that device is enumerated with a feature report descriptor, I cannot find the way to send things to the board. Then I changed the report descriptor 0xB1 to 0x91 and start the test_hid program. Things can be sent from Windows to the board by calling winAPI (WriteFile) and the generic (Read on linux). However, it is hard to send things from the device to Windows since I mess up the format inside the report. I tried refer to the book to see what each field means and make my own vendor defined HID.
- I found important information from the book, ch12, starting from p.370.
[Usage Page] The upper 16 bits is shared as a global item and the lower 16 bits is used to identify local item. (p.370)...
That is why the keyboard is recognized as a keyboard through its report descriptor. I modified the Usage page and each Usage Item to see if the device is still working. It can be recognized by Windows, without any changes of other descriptor. Then I started the test program on hyper terminal (Though, we have to study further the format of the report). The typed code can be sent to windows and displayed on the C# program. Similarly, the report can be written to the board from Windows.
- Understand how to write an appropriate report so that it can be written from linux to windows successfully.
- Create the Virtual Keyboard Application with C#. Ask MF if the programs should be installed as an apps on Windows or not.
- Start GUI side on friendlyarm.
Sep 23, 2010
setup
- dnw.exe connect USB to PC, driver is downloaded from friendlyArm.net
- hyperterminal and COMport
- build kernel, type make zImage
- open hyperterm, press k
- send file using dnw
- on hyperterm, press b
- attach again the USB
Why do I receive "Access denied" when attempting to access my HID?
Windows 2000 and later have exclusive read/write access to HIDs that are configured as a system keyboards or mice. An application can obtain a handle to a system keyboard or mouse by not requesting READ or WRITE access with CreateFile. Applications can then use HidD_SetFeature and HidD_GetFeature (if the device supports Feature reports).
Things to do after installing ubuntu
- Install nautilus-open-terminal "sudo apt-get install nautilus-open-terminal" ; Do have to restart terminal, do it by "nautilus -q". It does the trick.
- Install scite; A GUI notepad++ like editor in ubuntu
- Add workspace switcher to panel; Click on panel and select add to panel; Choose workspace switcher
- mount -t vboxsf FYP wintmp
1. 安装标准的C开发环境,由于Ubuntu安装默认是不安装的,所以需要先安装一下:
sudo apt-get install gcc g++ libgcc1 libg++ make gdb 2.安装交叉编译器下载交叉编译器cross的包,然后解压
sudo tar jxvf cross-2.95.3.tar.bz2 (根据版本不同解压文件不同),然后将解压后的文件都转移到/usr/local/arm下(若/usr/local/下没有arm文件夹,可先建一个):
sudo mv 2.95.3/ /usr/local/arm 3.把交叉编译器的路径加入到PATH
sudo vim /etc/bash.bashrc 在后面加入如下代码:
QUOTE: if [ -d /usr/local/arm/2.95.3 ] ; thenPATH=/usr/local/arm/2.95.3/bin:"${PATH}"fi 4.使新的环境变量生效
# source /etc/profile 5.检查是否将路径加入PATH的方法:
echo $PATH 如果显示的内容中有/usr/local/arm/2.95.3/bin,说明已经将交叉编译器的路径加入PATH自此,交叉编译环境安装完成。下面我们就来测试一个简单的例子。/*Hello.c*/#include
main(){printf("hello ubuntu!\n");}程序输好以后确认无误,保存。进入程序文件所在目录执行:
arm-linux-gcc hello.c –o hello arm -linux-gcc是第一次出现,有人可能会问这个哪里来的,不妨打开刚才安装的交叉编译工具目录 /usr/local/arm/2.95.3/bin/可以发现里面有一个arm-linux-gcc文件,这个就是针对arm的CPU 的gcc编译器了。以后用其它编译工具链式也可以通过这种方法看看其编译器是什么了。编译好了以后就可以下载到目标机进行测试了。当然也可以先在PC机上测试正误。用gcc hello.c –o hello就可以生成PC机上程序了,在运行./hello 就可以发现终端显示hello!字样。用arm-linux-gcc编译的程序在PC机上是不能运行的,运行后给出错误报告:无法执行二进制文件。说明经过交叉编译环境编译出的文件是硬件可执行的二进制代码文件。
Sep 20, 2010
Going to do
To do list
- Develop the HID descriptor as a force feedback device; Or to ensure there at least one endpoint.
- Try sending force feedback report to the real joystick, making it vibrate.
1. What is composite device
Composite device is defined in the USB spec as follows (usb_20.pdf 5.2.3),
"A device that has multiple interfaces controlled independently of each other is referred to as a composite device."
Using composite device, multiple functions are combined into a single device.
Ex.
- Keyboard + Mouse
- Video + USB Hard disk
- I/O device (HID + USB_bulk)
Another advantage of composite device is that it eases the device driver development.
OS assigns a separate device driver to each Interface of the composite device as follows. Therefore, a dedicated monolithic driver is not required for newly designed device; you can realize it using existing drivers.
+----------------------------+ +----------------------
| Composite Device | | Host PC
| | |
| Function 0 -- Interface 0 --------- Device driver A <--->
| | |
| Function 1 -- Interface 1 --------- Device driver B <--->
+----------------------------+ +-----------------------
When OS has some required drivers as built-in, they are available for the composite device. These OS built-in device drivers are called as USB class driver.
"Approved Class Specification Documents" from USB.org
http://www.usb.org/developers/devclass_docs#approved
Windows have these built-in class drivers.
"USB FAQ: Introductory Level - USB Class Drivers" from MS WHDC
http://www.microsoft.com/whdc/system/bus/usb/USBFAQ_intro.mspx
Please note, available drivers for a composite device are not limited only to class drivers. Any driver can be applied, as long as it doesn't require a device class (class defined in device descriptor). For example, SiLabs USB_INT and USB_bulk drivers are also applicable for composite devices.
Sep 19, 2010
Mid September
- ReadFile(...), WriteFile(...)
- HID_setXXX(...), HID_getXXX(...)
At this writing there are several public "gadget drivers", each implementing a single common USB function so it will work with virtually any USB peripheral controller. (Drivers for composite gadgets, or for audio/video drivers requiring isochronous transfers, would not be able to work on at least some controller hardware. The gadget API does support such drivers.) You should plan on testing these in conjunction with the controller driver and system board you'll be using.
- Gadget Zero ... is essential for controller driver testing. It provides two configurations: one for bulk traffic source/sink, and another for bulk traffic loopback. On the device side it helps verify that the driver stack pass USB-IF and other tests (needed for at least USB branding). On the host side it helps test the USB stack, such as the Linux-USB HCDs and usbcore. If built as a module, start it by modprobe g_zero; no other initialization is needed. (Use the autoresume=N module parameter to make it try triggering remote wakeup N seconds after it's suspended.)
- ………………………………………..
- GadgetFS ... since not every developer wants to program in the kernel, or rely specifically on the Linux kernel APIs, a user mode API is available. An example user mode driver is usb.c. (It also needs usbstring.c and usbstring.h.) Notice how the device is initialized by writing its configuration and device descriptors to a file (such as /dev/gadget/$CHIP), and how the endpoints are initialized in similar ways (writing descriptors to /dev/gadget/$ENDPOINT). After initializing them, just read or write to the files to transfer data; or to handle events including control requests to retrieve string descriptors, configure alternate settings, and implement class or vendor requests. On Linux 2.6 AIO (Async I/O) support is available, helping user mode drivers avoid i/o latencies and letting them stream data as quickly as in-kernel drivers can stream it. Note that user mode gadget drivers do not necesarily need to be licensed according to the GPL.
- http://msdn.microsoft.com/en-us/library/ff539939(VS.85).aspx The HID report
- http://www.linux-usb.org/gadget/ Linux Gadget HID driver
- http://www.helmpcb.com/Electronics/USBJoystick/HIDDescriptor.aspx Generic joystick descriptor
- http://www.microsoft.com/mspress/books/sampchap/6262.aspx Intro to keyboard descriptor
- http://www.usblyzer.com/usb-human-interface-device-hid-class-decoder.htm HID and endpoint
Sep 9, 2010
- Flash in the latest kernal version, 2.6.3X (This was done by Ka Chun); Reason: To use usbgadget. The old kernal does not support feature of pretending the usb slave device. We cannot use the port provided by mini2440.
- Play tricks on the kernal code. This is beacause not all ports can be used from the new kernal code. We have to edit it, enable features so that the correct hardware can be activated.
- The touch screen was once not working. Ka Chun fixed this
- Successfully hook the event to the application. Once the correct event is captured, we can perform winAPI to find out the handle of the window that throw us the event. HWND is useful as it acts as an unique identifier to provide rich information such as process ID, text on the window for us to analysis.
- Indeed, the old method we have used is Polling but it wasted CPU resourses so much. To get rid of it, we once considered making use of just a typical single thread. I have written a simple program using hook with Cplusplus. However, the program terminated soon. That is why we have to turn in to GUI program. The GUI thread is supposed to run infinitely until it is killed by user.
- Since the C sharp is used for GUI program. (The reason for not using C++ is that GUI C# provide more fancy interface for designing. C# provides more objects for GUI design.) The other issue will be the driver program, which supposed to be written in C language (To help communicating with low level device). Originally, Libusb-win32 was introduced as an API to send and read data from the USB device. After some searching from the NET, we found that a further improved version of Libusb is provided called LibUSBDotNet. .Net stands for C# GUI class.
- Make sure bytes can be sent to the mini2440 and read from mini2440 correctly.
- Study the QT extended on mini2440 (Time consuming)
- Study the source code of the test program of the HID device.
Aug 23, 2010
Meeting on 20 August
- using libusb-win32 API to find the suitable USB device, and send the "bulk" characters to the bus driver.
- Borrow board mini arm 2440 from Simon. Windows fails to detect the existence of the board, which may due to no driver written on the board. Ka chun suggests we have to write the driver and insert it into the kernel to let the board pretend it as a HID device.
- Investigate usage of "linux usb gadget" which appeared as an API for linux
- MF made another task for me, which is being able to find out current running process by capturing the event.
- On August 22, sunday, google "switch foreground window event", found something useful and post below. The available source code is written in C#. I may change it into C++.
Switch Foreground window event capture [success in C#]
Aug 15, 2010
How to Install Winusb.sys as the Device's Function Driver
- Install the Windows Driver Kit.
- Create a driver package folder on the machine to which the USB device is connected. For example c:\UsbDevice.
- Copy the WinUSB co-installer (WinusbcoinstallerX.dll) from the WinDDK\BuildNumber\redist\winusb to the driver package folder.
The WinUSB co-installer (Winusbcoinstaller.dll) installs WinUSB on the target system, if necessary. The WDK includes three versions of the co-installer depending on the system architecture: x86-based, x64-based, and Itanium-based systems. They are all named WinusbcoinstallerX.dll and are located in the appropriate subdirectory in the WinDDK\BuildNumber\redist\winusb folder.
- Copy the KMDF co-installer (WdfcoinstallerXXX.dll) from the WinDDK\BuildNumber\redist\wdf to the driver package folder.
The KMDF co-installer (WdfcoinstallerXXX.dll) installs the correct version of KMDF on the target system, if necessary. The version of WinUSB co-installer must match the KMDF co-installer because KMDF-based client drivers, such as Winusb.sys, require the corresponding version of the KMDF framework to be installed properly on the system. For example, Winusbcoinstaller2.dll requires KMDF version 1.9, which is installed by Wdfcoinstaller01009.dll. The x86 and x64 versions of WdfcoinstallerXXX.dll are included with the WDK under the WinDDK\BuildNumber\redist\wdf folder. The following table shows the WinUSB co-installer and the associated KMDF co-installer to use on the target system.
Use the following table to determine the WinUSB co-installer and the associated KMDF co-installer.
WinUSB co-installer KMDF library version KMDF co-installer Winusbcoinstaller.dll Requires KMDF version 1.5 or later. Wdfcoinstaller01005.dll
Wdfcoinstaller01007.dll
Wdfcoinstaller01009.dll
Winusbcoinstaller2.dll Requires KMDF version 1.9 or later. Wdfcoinstaller01009.dll - Write an INF that installs Winusb.sys as the function driver for the USB device.
- Create a signed catalog file for the package. This file is required to install WinUSB on x64 versions of Windows Vista.
- Attach the USB device to your computer.
- Run devcon.exe as follows:
devcon.exe install inf_file.inf "hardware_id"
- devcon.exe can be found in the
\WinDDK\build_number\tools\devcon\ \devcon.exe folder. - inf_file indicates the name of your INF.
- hardware_id indicates the hardware identifier for the device provided by the device vendor. This can be found in the INF. For example, for the OSR USB-FX2 Learning Kit device from OSR, the identifier is USB\Vid_0547&Pid_1002.
Note Because the hardware id contains '&', make sure that you specify the hardware id within quotes.
- devcon.exe can be found in the
- Alternatively, you can use the Device Manager to install the driver. Follow the instructions on the Update Driver Software wizard and choose manual installation. You will need to provide the location of the driver package folder to complete the installation.
Aug 6, 2010
winUSB
Today Meeting
- The generic HID keyboard driver. But the difficulty is we do not know if PC can send any data to the keyboard thru the generic driver. That may be a potential problem we have to solve.
- The winUSB API. Indeed, I don't pose so much knowledge on this but I am now preferring using this API function. Mainly because it is handy and M$ has already written different API with the winUSB.sys file for us.
Aug 2, 2010
Build without VC++ directly in CMD
Solution found
Source http://www.cnblogs.com/wubiyu/archive/2010/05/17/1737420.html
Vs2010 配置驱动开发环境
1、安装VS2010,安装WDK 7.0(DDK);
2、新建VC++->Empty Project
3、打开Configuration Manager 并新建一个名称为“ dirver ”的Solution Configuration 并将“dirver” 设为Active Solution Configuration .
4、打开View-> property Manager。
5、在"dirver" solution configuration 上点击右键,选择Add new property Sheet。取名为“dirverProperty”. 并对他进下以下设置。
5.1. C\C++ - General - Debug Information Format = Program Database (/Zi)
5.2. C\C++ - Preprocessor - Preprocessor Definitions = _X86_ [add also DBG for Debug config]
【WIN32;_DEBUG;_X86_;i386;STD_CALL;CONDITION_HANDLING;WIN32_LEAN_AND_MEAN;NT_UP;SRVDBG;DBG;_IDWBUILD;_WIN32_WINNT=0x0400;% (PreprocessorDefinitions)】
5.3. C\C++ - Code Generation - Enable C++ Exceptions = No
5.4. C\C++ - Code Generation - Basic Runtime Checks = Default
5.5. C\C++ - Code Generation - Buffer Security Check = No (/GS-)
5.6. C\C++ - Advanced - Calling Convention = __stdcall (/Gz)
5.7. C\C++ - Advanced - Compile As = Compile as C Code (/TC) [if you are going to use plain C]
5.8. Linker - General - Output File = $(OutDir)\$(ProjectName).sys
5.9. Linker - General - Enable Incremental Linking = Default
5.10. Linker - Input - Additional Dependencies = ntoskrnl.lib hal.lib $(NOINHERIT) [add here needed libs here e.g. ntoskrnl.lib hal.lib]
【不知道上面是不是笔误,应该为:ntoskrnl.lib;hal.lib;%(AdditionalDependencies)】
5.11. Linker - Input - Ignore All Default Libraries = Yes (/NODEFAULTLIB)
5.12. Linker - Manifest File - Generate Manifest = No
5.13. Linker - System - SubSystem = Native (/SUBSYSTEM:NATIVE)
5.14. Linker - System - Driver = Driver (/DRIVER)
5.15. Linker - Advanced - Entry Point = DriverEntry
5.16. Linker - Advanced - Base Address = 0x10000
5.17. Linker - Advanced - Randomized Base Address = Disable (/DYNAMICBASE:NO)
【这个也是错误的:应该置空】
5.18. Linker - Advanced - Data Execution Prevention (DEP) = Disable (/NXCOMPAT:NO)
【这个也是错误的:应该置空】
6. Config VC++ Directories
6.1 Open Open up property manager by clicking on Menu View->Property Manager.
6.2 Expand the project node and then the Configuration|Platform nodes, you will see "Microsoft.cpp.
for the global settings, similar to the old tools/Options/VC++ Directories.
6.3 Multi-Select "Microsoft.cpp.
6.4 In the property page window, click on "VC++ Directories" (for example) in the left pane, add new paths for the directories such as "Include Directories". separated by
semicolons
(eg:Include Directories config As:
$(ddkroot)\INC
$(ddkroot)\INC\WNET
$(ddkroot)\INC\DDK\WNET
Library Directories config As:
$(ddkroot)\LIB\WNET\I386
)
6.5 Make sure to save the settings before shutting down Visual Studio.
6.6 Re-launch Visual Studio and the new settings will be in effect.
6.7 Note: If you would like to only change the settings for one project, you can right click on the project and bring up the property page. Change the settings for “VC++
Directories”, these settings will be persisted to the project file.
七. OK. Have done. Now you can test it with simple code, e.g.:
#include "ntddk.h"
NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)
{
return STATUS_UNSUCCESSFUL;
}
特别说明:
1.
Visual Studio 2010 在智能设备开发方面只支持Windows Phone OS 7.0。如果你要为Windows CE 5.0和Windows Mobile 6.5开发应用程序,请安装Visual Studio 2008。
2.
做驱动开发时,SDK的版本要和WDK的版本一致,即Win7 WDK要配Win7 SDK,否则会出现编译错误。VS2010里集成了Windows SDK 7.0A。
3.
如果出现类似如下编译错误,解决方法是:拷贝C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sal.h,然后覆盖掉C:\WinDDK\7600.16385.1\inc\api\sal.h。
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2143: syntax error : missing ')' before 'const'
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2143: syntax error : missing '{' before 'const'
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2059: syntax error : ','
.............
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(107): fatal error C1003: error count exceeds 100; stopping compilation
Start writing simple WDM driver
- Cannot directly compile the solution, have to compile each cpp file step by step, C1083 Error
- Cannot link to the symbol from kernal, system32. Have to set Debug->Option and Setting->Symbols->Checked the option.
- Device not found, still figuring out.
- VC2010 cannot find the path of DDK header files
- 1. Run VS2005
2. Select Tools->Options->Project and Solutions->VC++ Directories For;VC2010 it is in Project->Properties
3. On the right side choose Include file (from show directories from)
4. Add WDKInstallationPath\BuildNumber\ inc to the list; For win7, we have to specifically identify the DDK path: C:\WinDDK\7600.16385.1\inc\ddk
5. On the right side choose Library file (from show directories from)
6. Add WDKInstallationPath\BuildNumber\ lib to the list
7. Press OK
1> stdafx.cpp
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2065: '_In_opt_z_' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): warning C4229: anachronism used : modifiers on data are ignored
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2182: '_invalid_parameter' : illegal use of type 'void'
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2491: '_invalid_parameter' : definition of dllimport data not allowed
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2059: syntax error : ')'
Solution from http://stackoverflow.com/questions/1356653/multiple-compiling-errors-with-basic-c-application-on-vs2010-beta-1
The problem is here: C:\WinDDK\6001.18001\inc\api\sal.h
sal.h defines annotations, which are being used in the CRT headers... The DDK includes its own sal.h, which is obsolete and dones not contain all the annotations.
There are 2 possible solutions: - change the include paths so that the "C:\Program Files\Microsoft Visual Studio 10.0\VC\include" comes before "C:\WinDDK\6001.18001\inc\api"
- just delete "C:\WinDDK\6001.18001\inc\api\sal.h" :)