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