Oct 24, 2010

Schedule

Using QT to develop the GUI interface these days

Made several versions. Now want to make it iphone like, may have to hard code the position of every icons.

GIMP is recommended for icon editing.

Oct 7, 2010

Today Schedule + some input report things

Today Finished:
  1. Create 3 new classes for readWrite form. They are HID(), win32Keyboard() and handler()
  2. Integrate the classes into one.
  3. Spot out the correct process name of the foreground process, then send some hard-coded byte values to the device
  4. 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.
  5. Create an ArrayList to store all key pressed first and released all of them at once.
Going to implement:
  1. Make our process running in background. Reference:
  2. Optimize the program, maybe by minimizing the code size and introducing some algorithms.
  3. Start debugging. Finding any possible bugs.
  4. Get URL from Hwnd, have to try.
  5. Find a way to register hot-key in windows

The format of the HID report is vital for decoding the meaning inside the report.
Page 70 of the HID1_11.pdf which can be downloaded from the USB official website is useful.

Oct 4, 2010

Finished wrapping the HID API library with C# codes. A reading thread is responsible for reading something from the widget.

Following to do are:
  1. 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.
  2. Integrate the getForegroundProcess program with this library.
  3. Figure out what should be sent to the widget to identify current running process.
The bugs that make the program unable to read and write data:
  1. I forgot to change the flags and control type respectively.
  2. 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.
  3. 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.
Acknowledgement (HID class only) and some follow-up explanation:
  1. 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)
  2. Make reference to genericHID.cs and its author. It gives definition of each winAPI function useful for our HID class.
  3. Also acknowledge to author of the UseHIDSample.cs

Oct 2, 2010

using winAPI writeFile

  1. Have to check the flags, what do they mean...
  2. Have to ensure everything is sent successfully
  3. Try to lock the device, avoid other windows application sending things to it.

Sep 27, 2010

Can now communicate between gadgets and Windows

Three days for the investigation. I have googled a lot and most of the results are not reasonable. I have borrowed a book from the University Library, called

USB COMPLETE

Surprisingly, it is written by Jan Axelson which I have found his website useful before... (See the entry before, I have added his webpage for reference) Chapter 11, 12, 13 were all about the HID device.

Notes jot on these days (the weekends)
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
To do list -
  1. Understand how to write an appropriate report so that it can be written from linux to windows successfully.
  2. Create the Virtual Keyboard Application with C#. Ask MF if the programs should be installed as an apps on Windows or not.
  3. Start GUI side on friendlyarm.

Sep 23, 2010

setup

  1. dnw.exe connect USB to PC, driver is downloaded from friendlyArm.net
  2. hyperterminal and COMport
  3. build kernel, type make zImage
  4. open hyperterm, press k
  5. send file using dnw
  6. on hyperterm, press b
  7. attach again the USB
Create shareFolder in vBox sudo mount -t ubuntuTmp windowsTmp
http://www.cygnal.org/ubb/Forum9/HTML/001381.html Explanation on keyboard descriptor

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

  1. 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.
  2. Install scite; A GUI notepad++ like editor in ubuntu
  3. Add workspace switcher to panel; Click on panel and select add to panel; Choose workspace switcher
  4. mount -t vboxsf FYP wintmp
ARM-Linux-gcc

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

  1. Develop the HID descriptor as a force feedback device; Or to ensure there at least one endpoint.
  2. 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.


src: http://www.cygnal.org/ubb/Forum9/HTML/001050.html

Sep 19, 2010

Mid September

We have stuck in the process of how windows sends message to HID device. On this stage, we successfully enumerate the mini2440 as a HID keyboard to Windows. The thing left was sending the right HID report to the device.

It seems that windows does not allow us to send any HID report to the keyboard, any HID device other than keyboard or mouse, it will be fine. There are many sites talking about this. winAPI provides two basic function for developers to send the HID reports to the target USB HID device. They are called, (quoted from MSDN, http://msdn.microsoft.com/en-us/library/ff542417(v=VS.85).aspx)

  1. ReadFile(...), WriteFile(...)
  2. HID_setXXX(...), HID_getXXX(...)
They are quoted without test, hopefully tomorrow we will test it on mini2440. Several useful references were quoted. http://courses.cs.tau.ac.il/embedded/projects/fall2009/HID-Host/ This site shows how they use win32 API to make a customized device.

For generic USB HID concept, a PDF file is downloaded and stored in the vBox. From this point of view, we knew that the interface is a collection of endpoints. The endpoints work as accepting or sending control messages to or from the host. Tommorow we will try making one more interface or one endpoint as a port for win32 to send the command.

Quoted from offical Linux Gadget HID driver:

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.
Quoted from M$
It isn't possible to open a handle to a mouse or keyboard collection because the system input thread has opened these devices exclusively. Furthermore, these devices don't appear in the enumeration of the HID interface GUID. (HIDCLASS doesn't advertise the HID interface GUID for keyboard and mice so as to prevent some random user-mode program from opening those devices before the system's own raw input thread can do so.) It does you no good to register a private interface GUID for your device because HIDCLASS will fail an IRP_MJ_CREATE directed to the main device object. Consequently, there is no way to communicate with a custom mouse or keyboard driver using standard methods.


Useful website:

Sep 9, 2010

This is the first week of September.
Finished stuffs:
[Pretend to be the HID device on the ARM9 board] Part done by Ka Chun
  1. 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.
  2. 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.
  3. The touch screen was once not working. Ka Chun fixed this
[Windows platform]
  1. 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.
  2. 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.
  3. 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.
[Things to be Developed soon]
  1. Make sure bytes can be sent to the mini2440 and read from mini2440 correctly.
  2. Study the QT extended on mini2440 (Time consuming)
  3. Study the source code of the test program of the HID device.

Aug 23, 2010

Meeting on 20 August

Gist:
  1. using libusb-win32 API to find the suitable USB device, and send the "bulk" characters to the bus driver.
  2. 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.
  3. Investigate usage of "linux usb gadget" which appeared as an API for linux
  4. MF made another task for me, which is being able to find out current running process by capturing the event.
  5. 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#]

Here is the source code:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;

namespace ExampleApp
{
class ExampleForm : Form
{
delegate void WinEventDelegate(IntPtr hWinEventHook,
uint eventType, IntPtr hwnd, int idObject,
int idChild, uint dwEventThread, uint dwmsEventTime);

const uint WINEVENT_OUTOFCONTEXT = 0;
const uint EVENT_SYSTEM_FOREGROUND = 3;

[DllImport("user32.dll")]
static extern bool UnhookWinEvent(IntPtr hWinEventHook);
[DllImport("user32.dll")]
static extern IntPtr SetWinEventHook(uint eventMin,
uint eventMax, IntPtr hmodWinEventProc,
WinEventDelegate lpfnWinEventProc, uint idProcess,
uint idThread, uint dwFlags);
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd,
StringBuilder lpString, int nMaxCount);

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ExampleForm());
}

ListBox m_list;
IntPtr m_hhook;

public ExampleForm()
{
m_list = new ListBox();
m_list.IntegralHeight = false;
m_list.Dock = DockStyle.Fill;
Controls.Add(m_list);

Text = "SetWinEventHook Example";

Load += new EventHandler(Program_Load);
FormClosing +=
new FormClosingEventHandler(Program_FormClosing);
}

void Program_Load(object sender, EventArgs e)
{
m_hhook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND,
EVENT_SYSTEM_FOREGROUND, IntPtr.Zero,
WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
}

void WinEventProc(IntPtr hWinEventHook, uint eventType,
IntPtr hwnd, int idObject, int idChild,
uint dwEventThread, uint dwmsEventTime)
{
if (eventType == EVENT_SYSTEM_FOREGROUND)
{
StringBuilder sb = new StringBuilder(500);
GetWindowText(hwnd, sb, sb.Capacity);

m_list.Items.Insert(0,
"Switched to: " + sb.ToString());
}
}

void Program_FormClosing(
object sender, FormClosingEventArgs e)
{
UnhookWinEvent(m_hhook);
}
}
}

Aug 15, 2010

How to Install Winusb.sys as the Device's Function Driver

  1. Install the Windows Driver Kit.
  2. Create a driver package folder on the machine to which the USB device is connected. For example c:\UsbDevice.
  3. 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.

  4. 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-installerKMDF library versionKMDF co-installer
    Winusbcoinstaller.dllRequires KMDF version 1.5 or later.

    Wdfcoinstaller01005.dll

    Wdfcoinstaller01007.dll

    Wdfcoinstaller01009.dll

    Winusbcoinstaller2.dllRequires KMDF version 1.9 or later.Wdfcoinstaller01009.dll

  5. Write an INF that installs Winusb.sys as the function driver for the USB device.
  6. Create a signed catalog file for the package. This file is required to install WinUSB on x64 versions of Windows Vista.
  7. Attach the USB device to your computer.
  8. 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.

  9. 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.
INF file sample:

Addendum to Thread "Calling WinUSB from an application"

Hi. Just for completeness sake, see below for a revised version of the inf file located in the following thread: http://www.osronline.com/showThread.cfm?link=102204 It was pointed out to me by Zhao Yu from Motica that the inf file needed to be revised for copying files correctly in a cross-platform manner (by that I mean 32-bit vs. 64-bit). Zhao quotes from a WDK 6000 document: "The CopyFiles directive does not support decorating a file-list-section name with a system-defined platform extension (.nt, .ntx86, .ntia64, or .ntamd64). ". Thus, the coinstaller in the previous inf file couldn't copy the two dlls on some platforms. Plus, he requested to have a SourceDiskFiles section put in as well. The inf template below puts in place his changes. So, this should be a better inf file to use to get started... For those of you who haven't followed this thread topic, this inf file is a template that can be used to install WinUSB as the primary device driver for a device (just replace the strings, GUIDs, VID and PID). To install, place your tweaked version of this inf file in a directory, then make two subdirectories, "amd64" and "x86", and place the co-installer dlls (found in the WDK) for those particular platforms in their respective directory and off you go... Thanks Zhao! --Brian Hindman ; ================ Version section ================= [Version] Signature = "$Windows NT$" Class = MyDeviceClass ClassGuid = {11111111-2222-3333-4444-555555555555} Provider = %ProviderName% DriverVer = 05/22/2007, 6.0.1.0 ; ========== Manufacturer/Models sections =========== [Manufacturer] %ProviderName% = MyDevice_WinUSB,NTx86,NTia64,NTamd64 [MyDevice_WinUSB.NTx86] %USB\MyDevice.DeviceDesc% =USB_Install, USB\VID_xxxx&PID_xxxx [MyDevice_WinUSB.NTamd64] %USB\MyDevice.DeviceDesc% =USB_Install, USB\VID_xxxx&PID_xxxx ; ================== Installation ================== [USB_Install] Include = WinUSB.inf Needs = WinUSB.NT [USB_Install.Services] Include = WinUSB.inf AddService = WinUSB, 0x00000002, WinUSB_ServiceInstall [WinUSB_ServiceInstall] DisplayName = %WinUSB_SvcDesc% ServiceType = 1 StartType = 3 ErrorControl = 1 ServiceBinary = %12%\WinUSB.sys [USB_Install.Wdf] KmdfService = WinUSB, WinUSB_Install [WinUSB_Install] KmdfLibraryVersion = 1.5 [USB_Install.HW] AddReg = Dev_AddReg [Dev_AddReg] HKR,,DeviceInterfaceGUIDs,0x00010000,"{55555555-4444-3333-2222-111111111111}" [USB_Install.CoInstallers] AddReg = CoInstallers_AddReg CopyFiles = CoInstallers_CopyFiles [CoInstallers_AddReg] HKR, , CoInstallers32, 0x00010000, "WinUSBCoInstaller.dll", "WdfCoInstaller01005.dll, WdfCoInstaller" [CoInstallers_CopyFiles] WinUSBCoInstaller.dll WdfCoInstaller01005.dll [SourceDisksNames] 1 = %MediaDescription% [SourceDisksFiles] WinUSBCoInstaller.dll = 1, x86 WdfCoInstaller01005.dll = 1, x86 [SourceDisksFiles.amd64] WinUSBCoInstaller.dll = 1, amd64 WdfCoInstaller01005.dll = 1, amd64 [DestinationDirs] CoInstallers_CopyFiles = 11 ; ==================== Strings ===================== [Strings] ProviderName = "My Company" USB\MyDevice.DeviceDesc="My Device using WinUSB only" MediaDescription = "My Installation Media" WinUSB_SvcDesc = "WinUSB Driver Service"<br />from: <span class="Apple-style-span" style="font-family: Tahoma, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; white-space: normal; "><a href="http://www.osronline.com/showthread.cfm?link=109991">http://www.osronline.com/showthread.cfm?link=109991</a> and msdn</span>

Aug 6, 2010

winUSB

Following the whitepaper written by M$, I am now confussing with the steps that writing the INF file to load the .sys into device manager.

I searched from the Internet. It is not easy to find how I can enumerate the GUID which is a vital option in the INF file. Keep going now...

Today Meeting

Meet with MF at 122.
We have discussed issues about how the hardware were supposed to communicate.
Basically, it will be a Linux device, there will be PC to device connection.
Originally, I am going to write the device driver on windows using the WDM.
After serveral discussion with MF, we figured out that we had to finish the earliest version as soon as possible. That is, at least we can have something demonstrate to our marker before December 2010. And now I have to shift to other easier method.

There will be some suggestions from MF:
  1. 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.
  2. 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.
MF also said that what Windows has to do is simple. It only has to register the hardware (thru the driver) and send some encrypted simple message to our Linux device. The n the device will decrypt the message. Big project comes from the Linux part. That is all we included.

Aug 2, 2010

Build without VC++ directly in CMD

Source:http://hi.baidu.com/kktlxd/blog/item/291051340e6d724b251f1418.html

Also, we have to include the makefile as well as the Sources to the same directory.
Make sure that there won't be any spacing in the path of directory or the following error: http://stackoverflow.com/questions/1154660/fatal-error-u1087-cannot-have-and-dependents-for-same-target shows up...


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..users" file for each Configuration|Platform. These are the files

for the global settings, similar to the old tools/Options/VC++ Directories.
6.3 Multi-Select "Microsoft.cpp..users", right click and bring up the property page window
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

View the sample code downloaded from code project.
Starting the sample program with Visual C++ 2010 express.
Some problems encountered:

  1. Cannot directly compile the solution, have to compile each cpp file step by step, C1083 Error
  2. Cannot link to the symbol from kernal, system32. Have to set Debug->Option and Setting->Symbols->Checked the option.
  3. Device not found, still figuring out.
Problems encountered while editing HelloWDM: http://www.luocong.com/articles/show_article.asp?Article_ID=11

  1. VC2010 cannot find the path of DDK header files
  2. 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

However, error msg appeared:

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" :)