blob: 65f47ae70143762485b246a78292b1e031539eb5 [file] [log] [blame]
The Android Open Source Project52d4c302009-03-03 19:29:09 -08001/*
2 * Copyright 2007 The Android Open Source Project
3 *
4 * Fake device support.
5 */
6#ifndef _WRAPSIM_FAKEDEV_H
7#define _WRAPSIM_FAKEDEV_H
8
9#include <sys/types.h>
10#include <sys/uio.h>
11#include <errno.h>
12
13typedef struct FakeDev FakeDev;
14
Marco Nelissen542e4f12009-07-08 12:49:42 -070015typedef int (*Fake_close)(FakeDev* dev, int);
16typedef FakeDev* (*Fake_dup)(FakeDev* dev, int);
17typedef ssize_t (*Fake_read)(FakeDev* dev, int, void*, size_t);
18typedef ssize_t (*Fake_readv)(FakeDev* dev, int, const struct iovec*, int);
19typedef ssize_t (*Fake_write)(FakeDev* dev, int, const void*, size_t);
20typedef ssize_t (*Fake_writev)(FakeDev* dev, int, const struct iovec*, int);
21typedef void* (*Fake_mmap)(FakeDev* dev, void*, size_t, int, int, int, __off_t);
22typedef int (*Fake_ioctl)(FakeDev* dev, int, int, void*);
The Android Open Source Project52d4c302009-03-03 19:29:09 -080023
24/*
25 * An open fake device entry.
26 */
27struct FakeDev {
28 /* string, for debugging; usually orig. device name */
29 char* debugName;
30
31 /* state bucket */
32 void* state;
33
34 /* the file descriptor we're associated with */
35 int fd;
36
37 /* in some cases we use a pair; this is the other one */
38 int otherFd;
39
40 /*
41 * Device functions we provide.
42 *
43 * All other file descriptor operations should fail, usually with EBADF.
44 */
45 Fake_close close;
Marco Nelissen542e4f12009-07-08 12:49:42 -070046 Fake_dup dup;
The Android Open Source Project52d4c302009-03-03 19:29:09 -080047 Fake_read read;
48 Fake_readv readv;
49 Fake_write write;
50 Fake_writev writev;
51 Fake_mmap mmap; // handles both mmap() and mmap64()
52 Fake_ioctl ioctl;
53};
54
55/*
56 * If a handler isn't defined for a syscall, we return EMLINK so that it's
57 * obvious when the error is generated by us.
58 */
59#define kNoHandlerError EMLINK
60
61/*
62 * Fake file descriptors begin here. This should be chosen such that no
63 * real descriptor is ever at or above this value.
64 */
65#define kFakeFdBase 512
66#define kMaxFakeFdCount 256
67
68/*
69 * Create a new, completely fake device entry.
70 */
71FakeDev* wsCreateFakeDev(const char* debugName);
72
73/*
74 * Create a new, mostly fake device entry.
75 */
76FakeDev* wsCreateRealFakeDev(const char* debugName);
77
78/*
79 * Free a fake device entry.
80 */
81void wsFreeFakeDev(FakeDev* dev);
82
83/*
84 * Given a file descriptor, find the corresponding fake device. Returns
85 * NULL if the fd doesn't correspond to one of our entries.
86 */
87FakeDev* wsFakeDevFromFd(int fd);
88
89/*
90 * Check to see if this open() call is on a device we want to spoof.
91 *
92 * Returns a "fake" file descriptor on success, <0 on error.
93 */
94int wsInterceptDeviceOpen(const char* pathName, int flags);
95
96/*
97 * Check to see if this access() call is on a device we want to spoof.
98 *
99 * Returns 0 if the device can be fake-accessed, -1 if it can't, -2
100 * if it can't and we don't want to allow fallback to the host-device.
101 */
102int wsInterceptDeviceAccess(const char* pathName, int flags);
103
104/*
105 * Devices.
106 */
107FakeDev* wsOpenDevAudio(const char* pathName, int flags);
108FakeDev* wsOpenDevConsoleTty(const char* pathName, int flags);
109FakeDev* wsOpenDevEvent(const char* pathName, int flags);
110FakeDev* wsOpenDevFb(const char* pathName, int flags);
111FakeDev* wsOpenDevLog(const char* pathName, int flags);
112FakeDev* wsOpenDevPower(const char* pathName, int flags);
The Android Open Source Project700ccfc2009-03-18 22:20:25 -0700113FakeDev* wsOpenSysPower(const char* pathName, int flags);
The Android Open Source Project52d4c302009-03-03 19:29:09 -0800114FakeDev* wsOpenDevVibrator(const char* pathName, int flags);
115
116/*
117 * Performs key remapping and sends the event to the global input event device.
118 */
119void wsSendSimKeyEvent(int key, int isDown);
120
121/*
122 * Send a touch event to the global input event device.
123 */
124void wsSendSimTouchEvent(int action, int x, int y);
125
126#endif /*_WRAPSIM_FAKEDEV_H*/