Fusing Reality with the Virtual Reality of a Serious
Game
Mikael Svensson
November 4, 2010
Master’s Thesis in Computing Science, 30 credits Supervisor at BAE Systems H¨ agglunds: Johan Persson
Supervisor at CS-UmU: Jonny Pettersson Examiner: Fredrik Georgsson
Ume˚ a University
Department of Computing Science SE-901 87 UME˚ A
SWEDEN
Abstract
Real world military and civilian training causes hundreds of lethal accidents each year around the world. Until now the reality has been impossible to replace in civilian and military training. But with the emergence of serious games combined with the latest advances in 3d simulated environments Bohemia Interactive developed the COTS (Com- mercially Of The Shelf) game VBS2(Virtual BattleSpace 2). BAE Systems H¨ agglunds’
goal with this thesis is to investigate the potential of using VBS2 as the simulation platform in a new cost effective and realistic vehicle training systems.
The major focus of this thesis is to find a way to control vehicles in VBS2. After evaluating the tools available during this thesis project DSF (Device Simulation Frame- work) is chosen to control VBS2. DSF is used to solve the problem by simulating a USB HID Joystick which controls VBS2 through DirectInput. This thesis therefore contains an in-depth study of the USB2.0 protocol, the HID protocol, and the DSF framework.
The thesis shows in the end a prototype that can control VBS2 or any other game that
supports DirectInput. The thesis also reveals a general design of the core of the vehicle
trainer that connects the hardware simulator SimBas with VBS2.
ii
Contents
1 Introduction 1
1.1 BAE Systems H¨ agglunds . . . . 1
1.2 Background . . . . 1
1.3 Systems today . . . . 1
1.4 VBS2 . . . . 2
1.5 BAE Systems H¨ agglunds Goal . . . . 2
1.6 Outline . . . . 2
2 Problem Areas 3 2.1 The design . . . . 3
2.2 The interaction with VBS2 . . . . 4
2.3 The implementation of the most important part of the system . . . . 4
3 How To Control VBS2 5 3.1 Fusion . . . . 5
3.2 DirectInput . . . . 5
3.3 Comparison . . . . 6
4 DirectInput and the underlaying driver stack 7 4.1 DirectInput . . . . 7
4.2 Windows Driver stack . . . . 7
4.3 Driver layers . . . . 8
4.4 The driver stack below DirectInput . . . . 10
5 Simulation of a Joystick in Windows 13 5.1 Device Simulation Framework . . . . 14
5.1.1 The DSF COM object model . . . . 15
5.1.2 USB2.0 Descriptors . . . . 17
5.1.3 Descriptor objects in SoftUSBDevice . . . . 20
5.1.4 HID Descriptors . . . . 20
5.1.5 Report Descriptors . . . . 21
5.1.6 The Report and DSF . . . . 26
iii
iv CONTENTS
6 Design and Implementation 27
6.1 Design . . . . 27
6.1.1 The hardware . . . . 27
6.1.2 The software . . . . 28
6.2 Implementation of Simulated Joystick . . . . 29
6.2.1 Initiation & Configuration . . . . 31
6.2.2 Configuration . . . . 31
6.2.3 Plug in and Unplug the device . . . . 33
6.2.4 Sending reports . . . . 33
6.2.5 Termination . . . . 34
6.2.6 C#/.net - C++/com wrapper . . . . 34
7 Results and Conclusions 35 7.1 Discussion . . . . 35
7.2 Future work . . . . 37
8 Acknowledgements 39 References 41 A Requirements 45 A.1 User Requirements . . . . 45
A.2 System Requirements . . . . 46
List of Figures
4.1 Figure of the general driver stack composed with knowledge from Mi- crosoft MSDN. . . . 9 4.2 A conceptual image of the driverstack under DirectInput composed with
knowledge from Microsoft MSDN. . . . . 11 5.1 A combined image of the driverstack under DirectInput and the DSF
architecture composed with knowledge from Microsoft MSDN. . . . . . 15 5.2 An image of the DSF object hierarchy composed with knowledge from
Microsoft MSDN. . . . 16 5.3 An image of the USB2.0 descriptors composed with knowledge from Mi-
crosoft msdn and the USB2.0 specification. . . . . 17 5.4 An image of a report descriptor that describe a HID Joystick.The fig-
ure is composed with knowledge from HID class specification,the USB2.0 specification, and HID usage tables specification. . . . 22 6.1 A conceptual image of the system. . . . 28 6.2 The state chart for the simulated HID device. . . . 30 7.1 A screenshot in Windows showing the prototype just after it have moved
the simulated joystick. . . . 36
v
vi LIST OF FIGURES
List of Tables
5.1 Table over items in figure 5.4. . . . 23 5.2 Table over the attribute field of the input item. . . . 24 6.1 Table over the objects that is initiated. . . . 31
vii
viii LIST OF TABLES
Chapter 1
Introduction
This master thesis was done at BAE Systems H¨ agglunds head quarters in ¨ Ornsk¨ oldsvik as a thesis for the degree of Master in computing science and engineering at Ume˚ a University. The thesis work started of as an investigation in how to solve the problem of making cheaper and better training simulators for BAE Systems H¨ agglunds different Vehicles. This by using COTS(commercially off the shelf) games and more specific the military simulation game VBS2(Virtual Battle Space 2). As the work proceeded different problem areas were identified and the work ended in this Master thesis which proposes solutions in the different problem areas.
1.1 BAE Systems H¨ agglunds
BAE System H¨ agglunds is a division in the global company BAE that has about 107 000 employees all over the world. BAE Systems H¨ agglunds has about 950 employees in different areas from production to development. BAE Systems H¨ agglunds develops, manufactures and modifies military vehicles ranging from all-terrain vehicles to combat vehicles. BAE Systems H¨ agglunds has developed and manufactured many well known vehicles like CV90, BV206, Bv206s, BVS10, and SEP. BAE Systems H¨ agglunds has also an impressive industry history in making wooden furniture, buses, electric engines, trams, airplanes, and several other products.[1]
1.2 Background
The customers of BAE Systems H¨ agglunds often ask for a more cost-effective alternative for training in a virtual environment. VBS2(see section 1.4) could be a solution to that request. VBS2 is the market leading serious game in the category of military simulation today and is a further development from Operation flashpoint game idea by Bohemia Interactive Australia [6]. VBS2 might be interesting as a virtual environment and as a platform for future training systems from BAE System H¨ agglunds.
1.3 Systems today
The current training systems are made ”in house” with expensive third party 3d engines.
These systems are very expensive to develop and maintain. They can not compete with
1
2 Chapter 1. Introduction
the COTS games that does develop more and better functions faster.
1.4 VBS2
VBS2 is a serious game and an battlefield simulator. Serious games is a category of games that focuses on education for a real world subject like military tactics, health care, and firefighting [35]. Serious games have a pedagogical part that is incorporated into the game. One of the pedagogical parts in VBS2 is AAR(after action review). AAR records the training session in VBS2 and can replay the recording after the training session. The instructor can show exactly what happened and give advice on improvements. Another difference between normal games and Serious games like VBS2 is that normal games tries to enhance the game to be more entertaining and discard human drawbacks that is called the super soldier syndrome [29]. VBS2 on the other hand tries to mimic human capability and drawbacks. One of the futures of VBS2 is that it simulates the human eyes light sensitivity. When you remove the night vision goggles the eyes have to acclimatize to the dark which gives a more realistic night combat situations. VBS2 also has ballistic simulation that they claim is 99% realistic [2]. Their ballistic simulation uses correct parameters down to the rotation of earth which enables realistic weapons training. VBS2 is highly customizable to be able to simulate different real world areas and real world objects. VBS2 has been a real success story for Bohemia Interactive Australia and is now market leading. They have attracted several important users, for example NATO, USA, Australia and the Netherlands. Over all, this makes VBS2 a good candidate as simulation platform for new vehicle training systems.
1.5 BAE Systems H¨ agglunds Goal
The goal of BAE Systems H¨ agglunds with this thesis work is to investigate if it is possible to build a vehicle training system with VBS2 as the simulation platform. The different parts of the goal are to find a way to interact with VBS2, to design a prototype system, and to implement the most important parts of the system.
1.6 Outline
This thesis is divided into eight chapters which are followed by one appendix. This
chapter gives an introduction and background to the thesis. The chapter also states the
goal for the thesis. Chapter two describes the problems that are identified in the pilot
study. Chapter three investigate and discuss the two ways to control VBS2 which lead to
the decision to use DirectInput. Chapter four investigates the underlying architecture of
DirektInput which includes windows driver stack, USB, and HID. Chapter five discusses
how to use DSF to simulate a Joystick. Chapter five goes on and describes USB and HID
deeper and how DSF simulates the joystick. Chapter six describe first the general design
of the vehicle training system and after that the chapter describes how the simulated
Joystick prototype is implemented. Chapter seven discusses the result and present what
should be done in the future. Chapter eight is acknowledgments and after chapter eight
follows the references. Appendix A contains the requirement document.
Chapter 2
Problem Areas
Chapter one describes the goals of this thesis and this chapter will explain the problems that needs to be solved to best satisfy the goals. This chapter is also largely the result of the pilot study done in the beginning of the thesis work.
The assignment is to investigate if it is possible to build a vehicle training system with VBS2 as the simulation environment. The parts of the assignment are to find a way to control VBS2 from another application, make a design on a general vehicle trainer, and implement the most important parts of the system.
2.1 The design
A general vehicle training system must be designed to handle multiple roles. A combat vehicle has for example; a driver, a gunner, and a commander. The task of the com- mander is to find targets, to navigate, and to give orders. The task of the gunner is to eliminate targets, to steer the turret, and to choose weapons. The task of the driver is to drive the vehicle and to control all the functions of the chassis. The system has to be designed to be easy to change and to create new roles, because various vehicles may have different roles. The design has to involve a connection to the hardware through SimBas. SimBas is a modular simulation of hardware and software of all the different electronic components in a vehicle from BAE Systems H¨ agglunds. Real hardware can also be connected to SimBas to replace the simulated counterparts. The interaction with VBS2 shall be tested with a prototype. The full list of requirements can be found in appendix A.
3
4 Chapter 2. Problem Areas
2.2 The interaction with VBS2
The most important part of the system is the connection to VBS2. Other parts of the system will be useless without the ability to control VBS2. The goal is to be able to steer the vehicles in VBS2 as it would be in real life. There are two standard ways to control VBS2. The first one is through DirectInput, that is an API (Application Programming Interface) for developers to collect user inputs from keyboards, mouses, joysticks, and other game controllers [11]. The other one is VBS2’s API FUSION that enables other programs to interact with VBS2. A literature study has to be done in order to decide which way that would be the best to chose for different problems. The way that is selected will then have to be studied closer in a deeper literature study. The knowledge gained in the literature studies will also be used when implementing the prototype.
2.3 The implementation of the most important part of the system
As described in the section above the interaction with VBS2 is the most important part of
the system. The interaction with VBS2 is also the part where BAE System H¨ agglunds
will gain the most knowledge if implemented. The other parts of the system will be
implemented if time allows. To ease the maintenance the system has to be implemented
in C# mostly. The language used with the interaction with VBS2 is depending of the
result of the literature study.
Chapter 3
How To Control VBS2
Chapter 2 states that there are two ways to control VBS2, with Fusion and/or Direct- Input. This chapter will discuss these two ways and show which one of them is the best to use in this system.
3.1 Fusion
Fusion is an API built by SimCentric which is an add-on module to VBS2 [30]. The purpose of Fusion is to enable developers to control VBS2 from outside of the simulation.
The Fusion API is a collection of C++ classes that enables developers to create, modify, and get information from objects in VBS2. Fusion is released in stages, v1.0 released in May 2009 and v2.0 in April 2010 [7].
In v1.0 Fusion is abstracting the ASI (Application Script Interface) to the C++ API which is object oriented and easier to use. The purpose of the ASI’s is to create and modify entire scenarios or parts of scenarios in VBS2. The ASI has no direct control of the models in VBS2. In v2.0 SimCentric enables the developers to use the simula- tion core, which means that developers will have complete control over the models and environment in VBS2.[30]
3.2 DirectInput
DirectInput is an Microsoft API which enables developers to gather inputs from different input devices without knowing the properties of the device beforehand. DirectInput also handles output for force feedback and haptic devices. When a developer needs input from a joystick they uses DirectInput to enumerate all attached devices to the computer.
The Developer can then choose which joystick to use and fetch the capabilities of that joystick. The joystick describes itself in a standardized way which enables a developer to develop applications that are compatible with a wide range of input devices.[12]
VBS2, as almost all other windows games supports DirectInput which are a widely used industry standard for input devices. DirectInput is incorporated in the original user interface of VBS2 which is an FPS (First Person Shooter) where you play a soldier in first person. The soldier in a vehicle in the game can have different roles. DirectInput
5
6 Chapter 3. How To Control VBS2
is limited by that role and can only do the actions that the role handles. For example a person in the game that plays the role of a driver can steer, accelerate, brake, and control lights. A combat vehicle has at least three roles; driver, commander, and gunner which have to be controlled in three separate instances of the game to have full control of the vehicle.
3.3 Comparison
Fusion and DirectInput are both clearly a way to control VBS2 but they have different approaches. DirectInput has a couple of advantages and disadvantages. DirectInput is an industry standard which means that a solution based on DirectInput will work with other games seamlessly. DirectInput will have good support in many years in the future and if that changes Microsoft will have a long transition period. One of DirectInput disadvantages is that it needs to have one VBS2 client per role in a vehicle, three to control a combat vehicle. The Game’s DirectInput interface can only use the predefined actions in the game. The predefined action covers almost all the needed actions except for example fire smokescreen which have to be chosen in a graphical list in the game.
When looking at Fusion’s disadvantages and advantages we have to take in to account the different versions. This because the differences between v1.0 and v2.0 are too big.
Version 1.0 of Fusion is a powerful tool to modify scenarios in runtime. It has some functions to change a vehicles course but it either commands the AI in the game to turn or rotate the vehicle immediately without simulation. There is no good way to realisti- cally steer a vehicle in v1.0 [25]. Version 2.0 will include better functions to steer the vehicle according to information released at this point. Version 2.0 will make it possible to simulate the dynamics of the vehicle outside VBS2. This will make vehicles in VBS2 to behave more realistically. It’s a pity that v2.0 will be released in the end or after this project is finished which makes v2.0 not a feasible way to control VBS2 in this thesis.
The conclusion is that Fusion will not be a viable way to control VBS2 until v2.0 is
released. DirectInput is therefore the best way to control VBS2 in this project.
Chapter 4
DirectInput and the
underlaying driver stack
The previous chapter showed that DirectInput is the currently best way to control VBS2 in the time frame of this thesis. The purpose for this chapter is to study the possibilities to use DirectInput to control VBS2 without a physical joystick. This will be done by a deeper study in the design of the Windows driver stack and the specific drive stack that DirectInput uses. This to give a better understanding where and how to insert the simulated joystick in a way that it can fool the system in perceiving it as a physical joystick. Last in this chapter the chosen solution will be studied in closer detail.
4.1 DirectInput
As the previous chapter explained DirectInput is an API that developers use to abstract the underlying complexity of which and how the attached input devices are connected and used. The developer do not need to know which type of joystick it is or which port it is connected to beforehand. There is no purpose to study the DirectInput API any closer, because developers of applications that use DirectInput will take care of the connection between the API and the application. The interesting part is what will happen under DirectInput where it may be possible to connect a simulated joystick.
Under DirectInput is the driver stack which is different depending on which version of Windows is used. After Windows XP the driver stack has nearly stayed the same. The scope of this thesis is therefore Windows XP and later. DirectInput is part of DirectX which in this thesis is version 5 or later.
4.2 Windows Driver stack
The basics of Windows driver stack is the first step to understand the DirectInput driver stack. The driver stack describes how applications access and use hardware in a stan- dardized way. In this way you could change hardware and the applications will still work. This is done in the driver stack HAL (Hardware Abstraction Layer) which hides specific hardware from the above layer. The driver stack is divided into two parts, the kernel-mode and the user-mode.
7
8 Chapter 4. DirectInput and the underlaying driver stack
Kernel-mode contains the HAL and routines for memory management, I/O and so on.
Kernel-mode code has access to memory and hardware directly. It is running in so called privileged processor mode. Privileged processor mode does not have any restriction to the hardware and can access all memory. The kernel-mode does have some drawbacks.
It has not unlimited memory like user-mode which has virtual memory that is also stored on disk. The kernel-mode has also almost no safeguards to protect the memory from corruption. Debugging is also more difficult than in user-mode.[24]
User-mode contains applications and user-mode drivers. User-mode applications and drivers have to go through the Win32 API to access any hardware. Win32 API works like a gate to the kernel. The user mode application calls the Win32 API and Win32 API calls the right kernel-mode function [27].
4.3 Driver layers
The driver stack can be described as a layered structure with each layer adding value to that device. See the conceptual figure 4.1 that describe the driver stack layers. The lowest layer is a hardware bus driver that handles a specific bus like USB or Firewire.
The bus driver is usually written by Microsoft and is part of the operating system. The Bus driver enumerates devices that are attached on the bus. Under the enumeration it identifies the devices and creates a device object for each device. [25, 8]
A device object is a representation of that device and contains pointers to the next driver object. In this way is the driver stack chained together. Each driver (not mini drivers attached to a class driver) has to create a device object. More information on de- vice objects and driver stacks can be found in the documentation of the WDK(Windows driver kit).[9]
The layer above the bus driver is a pair of drivers, the port driver and a miniport driver. The miniport driver is often developed by the manufacturer of the hardware.
The miniport driver handles all the protocol specific requests between the bus driver and the port driver. For example the USB stack has three miniport drivers that each supports different version of the USB standard [28]. The port driver or in some cases like USB is called a host controller handles more generic request about the bus and is not aware of the version specific details of the bus. In this way newer and better versions of the protocol and hardware can be added without rewriting the whole stack. The only thing that needs to be rewritten is the miniport driver. The port driver is almost always supplied by the operation system.[25]
The class and miniclass driver pair is built up in a similar way. The class driver han-
dles a specific class of devices that is attached on the underlying bus or port. The class
driver is hardware independent which means that the class driver can be reused on other
buses or ports that have devices of the same class. The class driver is almost always
supplied with the operation system. The miniclass driver is the only thing that has to
be rewritten when the underlying bus or port is changed. The miniclass driver is often
supplied by the manufacturer. Every layer above the class driver in the stack does not
know whats is under the class driver layer and do not need to know. The layers above
only wants to know what type of class the device is to be able to use it.[25]
4.3. Driver layers 9
The kernel-mode client drivers handles request from the Win32 API or from a class driver below. The kernel-mode client driver handles tasks that can’t be done in user mode. The user-mode client driver works similar to the kernel-mode client driver but it is in user-mode. It handles requests from the Win32 API or from applications. User- mode client drivers are preferred because they are easier to develop and do not affect stability of the system as sever as kernel-mode client drivers. This conceptual model of the driver stack is the basic way to represent a general driver stack in Windows in a simpler way. In most cases not all layers are needed depending on what the purpose of the stack is. Some driver stacks may break the stack concept and have component outside the main stack that it calls. One other component not represented in the figure is the filter driver. The filter driver can be placed between every layer to filter out information or adding information.[25]
Hardware Bus Driver Miniport Driver
Port Driver Miniclass Driver
Kernel-Mode Client Driver User-mode
Kernel-mode
Win32 API User-Mode
Client Driver Application
Class Driver
Figure 4.1: Figure of the general driver stack composed with knowledge from Microsoft
MSDN.
10 Chapter 4. DirectInput and the underlaying driver stack
4.4 The driver stack below DirectInput
DirectInput driver stack follows the general conceptual design that is described in the section 4.3. The figure 4.2 is a conceptual image of the driver stack below DirectInput with a joystick connected.
In the bottom is the USB bus hardware which follows specified versions of a USB stan- dard. There are two versions of the USB standard used today 2.0 and 1.1.
Version 2.0 is used in situations when higher bandwidth is a priority. Version 1.1 is used in simpler devices like mouses and keyboards. There is also a 3.0 version but it has just been released and have not yet become a major standard yet. 3.0 has an even higher bandwidth than 2.0.[28, 34]
There are three standard protocols for hardware host controller chips that is widely used today Openhci (Open host controller interface), Uhci (Universal host controller interface), and Ehci (Enhanced Host controller interface). Openhci and Uhci are two different host controller interfaces for USB 1.1, both are developed for each their hard- ware specification. There are two groups of hardware and software companies behind the two standards. Intel created Uhci and all Intel’s USB 1.1 controller chips uses Uhci.
Openhci started as an collaboration between Microsoft, Compaq , and National semicon- ductors. Openhci and Uhci both support low-speed and full-speed bandwidth standards stated in the USB 1.1 specification. This means that when there is an USB 1.1 host controller that Intel have constructed attached to the computer, the computer needs an Uhci driver and vice versa. When USB implementers forum started to develop USB2.0 they insisted to have only one Host controller interface standard. The name of USB2.0 Host controller is Ehci. Ehci takes care of all devices that is USB2.0 compatible and uses high-speed bandwidth standard. Backwards compatibility is ensured by using Uhci and Openhci as companion driver which handles the low-speed and full-speed devices.
This means that it is possible to have up to three different host controller drivers at the same time running in the same computer.[28, 3, 4, 34, 5]
These three drivers can also be called miniport drivers and are paired to the USB host controller driver also called port driver. USB host controller driver takes care of all hardware independent tasks. USB host controller driver is developed by Microsoft.
Every USB host controller has one USB root hub that contains all the ports that USB devices can be attached to. The USB devices that are attached to the hub belongs to one of the predefined USB classes. The supported classes are Hub device, HID (Human Input Devices), mass storage, audio, communication device, printer, content security, and image device -class. In this case the device is a Joystick which conforms to the HID device class. HID is a protocol for input devices of different configurations. Later in this thesis HID protocol will be discussed further.[28, 13]
Above the USB root hub driver is the HID USB miniclass driver. It handles all the
USB specific tasks for the HID class driver that is on top of the HID USB miniclass
driver. HID protocol can be used on other buses and ports if there is a miniclass driver
that takes care of that bus or ports specific protocol. The HID Class driver and HID
USB miniclass driver is Developed by Microsoft.[28, 26]
4.4. The driver stack below DirectInput 11
After the HID class driver is the transition to user-mode. In user-mode is DirectIn- put that is dynamically linked to HID.dll. HID.dll is a user-mode client driver that helps DirectInput to parse the information from the device.[20]
USB Minidriver USB Minidriver USB Minidriver
Openhci Uhci Ehci
USB bus Hardware USB Host controller driver
USB 2.0 USB 1.1
USB 1.1
USB root hub HID USB Miniclass driver
HID Class driver User-mode
Kernel-mode
DirectInput HID.dll
Application using DirectInput
Figure 4.2: A conceptual image of the driverstack under DirectInput composed with
knowledge from Microsoft MSDN.
12 Chapter 4. DirectInput and the underlaying driver stack
Chapter 5
Simulation of a Joystick in Windows
The knowledge presented in the chapter about DirectInput’s underlying driver stack enables some conclusions to arise about how the solution will look like. One conclusion is that the driver stack under DirectInput, especially the kernel-mode part has to be part of the solution.
If a solution is made in only user-mode by replacing HID.dll or put a filter between Win32 and DirectInput it will generate more problems than it is worth. This is mostly because it is not well documented and may affect the stability of other parts of the system. If it is possible to find the unofficial interface that is used between DirectInput and HID.dll it may not be safe to use it. Microsoft will for example not inform publicly if they change an unofficial interface and the change may have unknown consequences.
Therefore it is dangerous to use unofficial interfaces.
Microsoft has an official API to emulate mouse and keyboard messages in user mode but not for Joysticks and other HID devices. This is why the driver stack has to be in the solution. As described in chapter four, some parts of the stack can be changed with- out the layers above recognizing any difference. It is possible to remove the HID USB miniclass driver and replace it with another that receives events from an application in user-mode. This is a valid solution but is very hard to implement because it involves kernel-mode.
In this thesis time frame it is not possible to learn how to implement a driver that follows both the USB specification and the HID specification. The same goes if a filter driver is used. Another argument is that such a driver will affect the stability of the system if it is not built correctly. Microsoft has developed a framework that solves this problem in the same way as described above by just removing everything under the USB Hub driver and replace it with a simulated counterpart [14]. This framework is called DSF (Device Simulation Framework). DSF is the technique which is chosen in this thesis to solve the problem with controlling VBS2, this by implementing a simulated joystick.
13
14 Chapter 5. Simulation of a Joystick in Windows
5.1 Device Simulation Framework
DSF is developed to ease the testing of USB devices software before the hardware is built. This helps USB device developers to develop hardware and software in parallel.
It enables developers to create a simulation of a USB device and then to control it in user-mode via an application or a script. DSF is part of WDK and is divided in two parts, DSF runtime and DSF Interfaces. DSF Runtime installs all the drivers and the resources to run a simulated USB device. It also installs a Software enumerator and a utility program which enables adding or removing simulated Ehci controllers from the system. DSF interfaces installs the Managed DSF framework. The manged framework enables users to develop test applications in .net. But the framework can not create or modify simulated USB devices it can only use them.[10, 23]
Figure 5.1 shows the conceptual model of a system with simulated HID device using the DSF framework. On the right side in figure 5.1 is the driver stack under DirectIn- put that has been described in figure 4.2. The big difference compare to figure 4.2 is that DSF has replaced the Ehci controller with its own simulated Ehci controller. The simulated Ehci controller act as an real Ehci Controller but instead of being connected to the hardware it is connected to the DSF runtime and the simulated USB device.
The simulated Ehci controller has its own mini driver and port driver which has their hardware access calls re-routed to DSF own libraries in order to simulate for exam- ple interrupts. The DSF mini driver communicates with the simulated Ehci controller as if it would be a real hardware controller. No layer from and above the mini driver can see any difference between a hardware controller and the simulated controller.[14, 16]
On the left side of figure 5.1 is the DSF stack. On the top of the stack is the sim-
ulated USB device DLL (Dynamic link library) which is implemented by the user of
the framework. The simulated USB device is developed in User-mode and has to be
implemented in a programming language which supports describing in COM (Microsoft
Component Object Model) client code. This is because the DSF framework is devel-
oped by using that standard. The simulated USB device initiates a SoftUSBDevice
COM object which is a representation of a USB device. The SoftUSBDevice COM
object is built up very similar to the USB2.0 specification and are the basis for all sim-
ulated USB devices. The SoftUSBDevice COM object will later be examine closer. The
SoftUSBDevice COM object is connected to it’s counterpart SoftUSBDevice object in
Kernel-mode. The SoftUSBDevice object in kernel-mode is plugged in to the simulated
Ehci controller with the help of DSF Runtime. More on that later. The COM object
is then used to handle all USB transactions which transmits configurations and reports
to the simulated Ehci controller which passes on the information up in the DirectInput
driver stack. In the bottom of the DSF stack is the DSF runtime. The runtime is built
to handle a variety of simulated devices and buses. But with existing release it can only
handle simulated USB buses.[14, 15]
5.1. Device Simulation Framework 15
DSF USB Minidriver Ehci DSF USB Host
controller driver
USB 2.0 USB root hub
HID USB Miniclass driver
HID Class driver User-mode
Kernel-mode
DirectInput HID.dll
Application using DirectInput Application
that uses the simulated USB Device
Simulated USB Device DLL
SoftUSBDevice Object
DSF Runtime
Simulated USB Ehci Controller SoftHIDProtocolXlator
Object
DSF Framework
HID USB Driver Stack
DSF Stack
Figure 5.1: A combined image of the driverstack under DirectInput and the DSF archi- tecture composed with knowledge from Microsoft MSDN.
5.1.1 The DSF COM object model
The core of the DSF COM object model is based on three COM objects DSF, DSFDe- vice, and DSFBus with respective interfaces IDSF, IDSFDevice, and IDSFBus. The DSF runtime is represented in the framework with the DSF COM object. DSF COM object is the root object in the hierarchy and may contain children devices of the object type DSFDevices. DSFDevices may also have children devices if it satisfies IDSFBus interface. Every device in the DSF framework has to satisfy the IDSFDevice interface in order to be added to the hierarchy. The hierarchy is built up in this way which is shown in figure 5.2. The DSF root object has several methods and properties. One of the properties is the children devices which is a collection of DSFDevices. The collection has its own object type DSFDevices which have only methods to read the collection.
It has unfortunately a name that can be mixed up with DSFDevice in plural. From
here on DSFDevices means DSFDevice in plural. DSF have several methods but the
most important method is HotPlug. HotPlug is used to attach an IDSFDevice to the
hierarchy. HotPlug can only attach a DSFDevice to an DSFDevice that also satisfies
16 Chapter 5. Simulation of a Joystick in Windows
IDSFBus interface. This is why DSFDevices may only have children if it also satisfies IDSFBus interface. When HotPlug is called to attach a IDSFDevice to a IDSFBus, for example to the simulated Ehci controller, it will notify the simulated Ehci controller through the DSF runtime that a new device has been attached. The simulated Ehci controller simulates a hardware interrupt to the DSF USB Ehci mini driver which acts like it is a real hardware device that has been attached. The IDSFBus have only two methods HotPlug and Unplug. HotPlug works in the same way as IDSF HotPlug with the difference that IDSF HotPlug returns the IDSFBus which the simulated device is plugged in to. This because IDSF do not have an Unplug method. The DSF COM object model contains several more types of objects which can be read about in the WDK documentation. [15, 14, 22]
IDSF
IDSFDevice
IDSFDevice
IDSFDevice IDSFBus
IDSFDevice
Figure 5.2: An image of the DSF object hierarchy composed with knowledge from Microsoft MSDN.
SoftUSBDevice is an USB device simulator and follows the DSF object model de-
scribed earlier. SoftUSBDevice has a property which returns the SoftUSBDevice own
DSFDevice object which then is used to HotPlug to ether the simulated Ehci controller
or a SoftUSBHub. SoftUSBDevice is designed to follow the USB2.0 specification to
enable it to be perceive as an real USB device. The USB2.0 specification specifies that
descriptors shall describe the device to the host computer. These descriptors contains
all the properties of that device from its power needs to how the data pipeline shall be
set up. SoftUSBDevice is one of those descriptor representations. SoftUSBDevice and
the other descriptor representations have two sides here, they are both a representation
of the descriptor and part of the logic behind the simulated USB device.
5.1. Device Simulation Framework 17
SoftUSBDevice
SoftUSBConfiguration SoftUSBConfiguration
SoftUSBInterface SoftUSBInterface SoftUSBInterface SoftUSBEndpoint SoftUSBEndpoint
SoftUSBEndpoint SoftUSBEndpoint