~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to debian/patches/89_braille.patch

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno, Aurelien Jarno
  • Date: 2009-03-07 06:20:34 UTC
  • mfrom: (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20090307062034-i3pead4mw653v2el
Tags: 0.10.0-1
[ Aurelien Jarno ]
* New upstream release:
  - Fix fr-be keyboard mapping (closes: bug#514462).
  - Fix stat64 structure on ppc-linux-user (closes: bug#470231).
  - Add a chroot option (closes: bug#415996).
  - Add evdev support (closes: bug#513210).
  - Fix loop on symlinks in user mode (closes: bug#297572).
  - Bump depends on openbios-sparc.
  - Depends on openbios-ppc.
  - Update 12_signal_powerpc_support.patch.
  - Update 21_net_soopts.patch.
  - Drop 44_socklen_t_check.patch (merged upstream).
  - Drop 49_null_check.patch (merged upstream).
  - Update 64_ppc_asm_constraints.patch.
  - Drop security/CVE-2008-0928-fedora.patch (merged upstream).
  - Drop security/CVE-2007-5730.patch (merged upstream).
* patches/80_stable-branch.patch: add patches from stable branch:
  - Fix race condition between signal handler/execution loop (closes:
    bug#474386, bug#501731).
* debian/copyright: update.
* Compile and install .dtb files:
  - debian/control: build-depends on device-tree-compiler.
  - debian/patches/81_compile_dtb.patch: new patch from upstream.
  - debian/rules: compile and install bamboo.dtb and mpc8544.dtb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
commit 4a0163c1e18b1c752bfaf086bf806f0fc7be5c41
2
 
Author: aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162>
3
 
Date:   Tue Apr 8 06:01:02 2008 +0000
4
 
 
5
 
    Braille device support
6
 
    
7
 
    (Samuel Thibault)
8
 
    
9
 
    
10
 
    git-svn-id: svn+ssh://svn.savannah.nongnu.org/qemu/trunk@4173 c046a42c-6fe2-441c-8c8c-71466251a162
11
 
 
12
 
Index: qemu-0.9.1/Makefile
13
 
===================================================================
14
 
--- qemu-0.9.1.orig/Makefile    2008-04-14 11:26:14.000000000 +0200
15
 
+++ qemu-0.9.1/Makefile 2008-04-14 11:26:14.000000000 +0200
16
 
@@ -60,6 +60,11 @@
17
 
 OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o usb-serial.o
18
 
 OBJS+=sd.o ssi-sd.o
19
 
 
20
 
+ifdef CONFIG_BRLAPI
21
 
+OBJS+= baum.o
22
 
+LIBS+=-lbrlapi
23
 
+endif
24
 
+
25
 
 ifdef CONFIG_WIN32
26
 
 OBJS+=tap-win32.o
27
 
 endif
28
 
Index: qemu-0.9.1/Makefile.target
29
 
===================================================================
30
 
--- qemu-0.9.1.orig/Makefile.target     2008-04-14 11:26:14.000000000 +0200
31
 
+++ qemu-0.9.1/Makefile.target  2008-04-14 11:26:14.000000000 +0200
32
 
@@ -565,7 +565,7 @@
33
 
 endif
34
 
 
35
 
 $(QEMU_SYSTEM): $(VL_OBJS) ../libqemu_common.a libqemu.a
36
 
-       $(CC) $(VL_LDFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(CURSES_LIBS) $(COCOA_LIBS) $(VL_LIBS)
37
 
+       $(CC) $(VL_LDFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(CURSES_LIBS) $(COCOA_LIBS) $(VL_LIBS) $(BRLAPI_LIBS)
38
 
 
39
 
 depend: $(SRCS)
40
 
        $(CC) -MM $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $^ 1>.depend
41
 
Index: qemu-0.9.1/configure
42
 
===================================================================
43
 
--- qemu-0.9.1.orig/configure   2008-04-14 11:26:14.000000000 +0200
44
 
+++ qemu-0.9.1/configure        2008-04-14 11:26:14.000000000 +0200
45
 
@@ -281,6 +281,8 @@
46
 
   ;;
47
 
   --disable-kqemu) kqemu="no"
48
 
   ;;
49
 
+  --disable-brlapi) brlapi="no"
50
 
+  ;;
51
 
   --enable-profiler) profiler="yes"
52
 
   ;;
53
 
   --enable-cocoa) cocoa="yes" ; coreaudio="yes" ; sdl="no"
54
 
@@ -413,6 +415,7 @@
55
 
 echo "  --enable-alsa            enable ALSA audio driver"
56
 
 echo "  --enable-fmod            enable FMOD audio driver"
57
 
 echo "  --enable-dsound          enable DirectSound audio driver"
58
 
+echo "  --disable-brlapi         disable BrlAPI"
59
 
 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
60
 
 echo "  --enable-system          enable all system emulation targets"
61
 
 echo "  --disable-system         disable all system emulation targets"
62
 
@@ -688,6 +691,20 @@
63
 
 fi
64
 
 
65
 
 ##########################################
66
 
+# BrlAPI probe
67
 
+
68
 
+if test -z "$brlapi" ; then
69
 
+    brlapi=no
70
 
+cat > $TMPC << EOF
71
 
+#include <brlapi.h>
72
 
+int main( void ) { return brlapi__openConnection (NULL, NULL, NULL); }
73
 
+EOF
74
 
+    if $cc -o $TMPE ${OS_CFLAGS} $TMPC -lbrlapi 2> /tmp/qemu-$$-brlapi.log ; then
75
 
+           brlapi=yes
76
 
+    fi # brlapi compile test
77
 
+fi # -z $brlapi
78
 
+
79
 
+##########################################
80
 
 # curses probe
81
 
 
82
 
 if test "$curses" = "yes" ; then
83
 
@@ -780,6 +797,7 @@
84
 
     echo "Target Sparc Arch $sparc_cpu"
85
 
 fi
86
 
 echo "kqemu support     $kqemu"
87
 
+echo "brlapi support    $brlapi"
88
 
 echo "Documentation     $build_docs"
89
 
 [ ! -z "$uname_release" ] && \
90
 
 echo "uname -r          $uname_release"
91
 
@@ -1006,6 +1024,11 @@
92
 
   echo "CONFIG_CURSES=yes" >> $config_mak
93
 
   echo "CURSES_LIBS=-lcurses" >> $config_mak
94
 
 fi
95
 
+if test "$brlapi" = "yes" ; then
96
 
+  echo "CONFIG_BRLAPI=yes" >> $config_mak
97
 
+  echo "#define CONFIG_BRLAPI 1" >> $config_h
98
 
+  echo "BRLAPI_LIBS=-lbrlapi" >> $config_mak
99
 
+fi
100
 
 
101
 
 # XXX: suppress that
102
 
 if [ "$bsd" = "yes" ] ; then
103
 
Index: qemu-0.9.1/hw/baum.c
104
 
===================================================================
105
 
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
106
 
+++ qemu-0.9.1/hw/baum.c        2008-04-14 11:26:14.000000000 +0200
107
 
@@ -0,0 +1,643 @@
108
 
+/*
109
 
+ * QEMU Baum Braille Device
110
 
+ *
111
 
+ * Copyright (c) 2008 Samuel Thibault
112
 
+ *
113
 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
114
 
+ * of this software and associated documentation files (the "Software"), to deal
115
 
+ * in the Software without restriction, including without limitation the rights
116
 
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
117
 
+ * copies of the Software, and to permit persons to whom the Software is
118
 
+ * furnished to do so, subject to the following conditions:
119
 
+ *
120
 
+ * The above copyright notice and this permission notice shall be included in
121
 
+ * all copies or substantial portions of the Software.
122
 
+ *
123
 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
124
 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
125
 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
126
 
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
127
 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
128
 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
129
 
+ * THE SOFTWARE.
130
 
+ */
131
 
+#include "qemu-common.h"
132
 
+#include "qemu-char.h"
133
 
+#include "qemu-timer.h"
134
 
+#include "usb.h"
135
 
+#include <assert.h>
136
 
+#include <brlapi.h>
137
 
+#include <brlapi_constants.h>
138
 
+#include <brlapi_keycodes.h>
139
 
+#ifdef CONFIG_SDL
140
 
+#include <SDL/SDL_syswm.h>
141
 
+#endif
142
 
+
143
 
+#if 0
144
 
+#define DPRINTF(fmt, ...) \
145
 
+        printf(fmt, ## __VA_ARGS__)
146
 
+#else
147
 
+#define DPRINTF(fmt, ...)
148
 
+#endif
149
 
+
150
 
+#define ESC 0x1B
151
 
+
152
 
+#define BAUM_REQ_DisplayData           0x01
153
 
+#define BAUM_REQ_GetVersionNumber      0x05
154
 
+#define BAUM_REQ_GetKeys               0x08
155
 
+#define BAUM_REQ_SetMode               0x12
156
 
+#define BAUM_REQ_SetProtocol           0x15
157
 
+#define BAUM_REQ_GetDeviceIdentity     0x84
158
 
+#define BAUM_REQ_GetSerialNumber       0x8A
159
 
+
160
 
+#define BAUM_RSP_CellCount             0x01
161
 
+#define BAUM_RSP_VersionNumber         0x05
162
 
+#define BAUM_RSP_ModeSetting           0x11
163
 
+#define BAUM_RSP_CommunicationChannel  0x16
164
 
+#define BAUM_RSP_PowerdownSignal       0x17
165
 
+#define BAUM_RSP_HorizontalSensors     0x20
166
 
+#define BAUM_RSP_VerticalSensors       0x21
167
 
+#define BAUM_RSP_RoutingKeys           0x22
168
 
+#define BAUM_RSP_Switches              0x23
169
 
+#define BAUM_RSP_TopKeys               0x24
170
 
+#define BAUM_RSP_HorizontalSensor      0x25
171
 
+#define BAUM_RSP_VerticalSensor                0x26
172
 
+#define BAUM_RSP_RoutingKey            0x27
173
 
+#define BAUM_RSP_FrontKeys6            0x28
174
 
+#define BAUM_RSP_BackKeys6             0x29
175
 
+#define BAUM_RSP_CommandKeys           0x2B
176
 
+#define BAUM_RSP_FrontKeys10           0x2C
177
 
+#define BAUM_RSP_BackKeys10            0x2D
178
 
+#define BAUM_RSP_EntryKeys             0x33
179
 
+#define BAUM_RSP_JoyStick              0x34
180
 
+#define BAUM_RSP_ErrorCode             0x40
181
 
+#define BAUM_RSP_InfoBlock             0x42
182
 
+#define BAUM_RSP_DeviceIdentity                0x84
183
 
+#define BAUM_RSP_SerialNumber          0x8A
184
 
+#define BAUM_RSP_BluetoothName         0x8C
185
 
+
186
 
+#define BAUM_TL1 0x01
187
 
+#define BAUM_TL2 0x02
188
 
+#define BAUM_TL3 0x04
189
 
+#define BAUM_TR1 0x08
190
 
+#define BAUM_TR2 0x10
191
 
+#define BAUM_TR3 0x20
192
 
+
193
 
+#define BUF_SIZE 256
194
 
+
195
 
+typedef struct {
196
 
+    CharDriverState *chr;
197
 
+
198
 
+    brlapi_handle_t *brlapi;
199
 
+    int brlapi_fd;
200
 
+    int x, y;
201
 
+
202
 
+    uint8_t in_buf[BUF_SIZE];
203
 
+    uint8_t in_buf_used;
204
 
+    uint8_t out_buf[BUF_SIZE];
205
 
+    uint8_t out_buf_used, out_buf_ptr;
206
 
+
207
 
+    QEMUTimer *cellCount_timer;
208
 
+} BaumDriverState;
209
 
+
210
 
+/* Let's assume NABCC by default */
211
 
+static const uint8_t nabcc_translation[256] = {
212
 
+    [0] = ' ',
213
 
+#ifndef BRLAPI_DOTS
214
 
+#define BRLAPI_DOTS(d1,d2,d3,d4,d5,d6,d7,d8) \
215
 
+    ((d1?BRLAPI_DOT1:0)|\
216
 
+     (d2?BRLAPI_DOT2:0)|\
217
 
+     (d3?BRLAPI_DOT3:0)|\
218
 
+     (d4?BRLAPI_DOT4:0)|\
219
 
+     (d5?BRLAPI_DOT5:0)|\
220
 
+     (d6?BRLAPI_DOT6:0)|\
221
 
+     (d7?BRLAPI_DOT7:0)|\
222
 
+     (d8?BRLAPI_DOT8:0))
223
 
+#endif
224
 
+    [BRLAPI_DOTS(1,0,0,0,0,0,0,0)] = 'a',
225
 
+    [BRLAPI_DOTS(1,1,0,0,0,0,0,0)] = 'b',
226
 
+    [BRLAPI_DOTS(1,0,0,1,0,0,0,0)] = 'c',
227
 
+    [BRLAPI_DOTS(1,0,0,1,1,0,0,0)] = 'd',
228
 
+    [BRLAPI_DOTS(1,0,0,0,1,0,0,0)] = 'e',
229
 
+    [BRLAPI_DOTS(1,1,0,1,0,0,0,0)] = 'f',
230
 
+    [BRLAPI_DOTS(1,1,0,1,1,0,0,0)] = 'g',
231
 
+    [BRLAPI_DOTS(1,1,0,0,1,0,0,0)] = 'h',
232
 
+    [BRLAPI_DOTS(0,1,0,1,0,0,0,0)] = 'i',
233
 
+    [BRLAPI_DOTS(0,1,0,1,1,0,0,0)] = 'j',
234
 
+    [BRLAPI_DOTS(1,0,1,0,0,0,0,0)] = 'k',
235
 
+    [BRLAPI_DOTS(1,1,1,0,0,0,0,0)] = 'l',
236
 
+    [BRLAPI_DOTS(1,0,1,1,0,0,0,0)] = 'm',
237
 
+    [BRLAPI_DOTS(1,0,1,1,1,0,0,0)] = 'n',
238
 
+    [BRLAPI_DOTS(1,0,1,0,1,0,0,0)] = 'o',
239
 
+    [BRLAPI_DOTS(1,1,1,1,0,0,0,0)] = 'p',
240
 
+    [BRLAPI_DOTS(1,1,1,1,1,0,0,0)] = 'q',
241
 
+    [BRLAPI_DOTS(1,1,1,0,1,0,0,0)] = 'r',
242
 
+    [BRLAPI_DOTS(0,1,1,1,0,0,0,0)] = 's',
243
 
+    [BRLAPI_DOTS(0,1,1,1,1,0,0,0)] = 't',
244
 
+    [BRLAPI_DOTS(1,0,1,0,0,1,0,0)] = 'u',
245
 
+    [BRLAPI_DOTS(1,1,1,0,0,1,0,0)] = 'v',
246
 
+    [BRLAPI_DOTS(0,1,0,1,1,1,0,0)] = 'w',
247
 
+    [BRLAPI_DOTS(1,0,1,1,0,1,0,0)] = 'x',
248
 
+    [BRLAPI_DOTS(1,0,1,1,1,1,0,0)] = 'y',
249
 
+    [BRLAPI_DOTS(1,0,1,0,1,1,0,0)] = 'z',
250
 
+
251
 
+    [BRLAPI_DOTS(1,0,0,0,0,0,1,0)] = 'A',
252
 
+    [BRLAPI_DOTS(1,1,0,0,0,0,1,0)] = 'B',
253
 
+    [BRLAPI_DOTS(1,0,0,1,0,0,1,0)] = 'C',
254
 
+    [BRLAPI_DOTS(1,0,0,1,1,0,1,0)] = 'D',
255
 
+    [BRLAPI_DOTS(1,0,0,0,1,0,1,0)] = 'E',
256
 
+    [BRLAPI_DOTS(1,1,0,1,0,0,1,0)] = 'F',
257
 
+    [BRLAPI_DOTS(1,1,0,1,1,0,1,0)] = 'G',
258
 
+    [BRLAPI_DOTS(1,1,0,0,1,0,1,0)] = 'H',
259
 
+    [BRLAPI_DOTS(0,1,0,1,0,0,1,0)] = 'I',
260
 
+    [BRLAPI_DOTS(0,1,0,1,1,0,1,0)] = 'J',
261
 
+    [BRLAPI_DOTS(1,0,1,0,0,0,1,0)] = 'K',
262
 
+    [BRLAPI_DOTS(1,1,1,0,0,0,1,0)] = 'L',
263
 
+    [BRLAPI_DOTS(1,0,1,1,0,0,1,0)] = 'M',
264
 
+    [BRLAPI_DOTS(1,0,1,1,1,0,1,0)] = 'N',
265
 
+    [BRLAPI_DOTS(1,0,1,0,1,0,1,0)] = 'O',
266
 
+    [BRLAPI_DOTS(1,1,1,1,0,0,1,0)] = 'P',
267
 
+    [BRLAPI_DOTS(1,1,1,1,1,0,1,0)] = 'Q',
268
 
+    [BRLAPI_DOTS(1,1,1,0,1,0,1,0)] = 'R',
269
 
+    [BRLAPI_DOTS(0,1,1,1,0,0,1,0)] = 'S',
270
 
+    [BRLAPI_DOTS(0,1,1,1,1,0,1,0)] = 'T',
271
 
+    [BRLAPI_DOTS(1,0,1,0,0,1,1,0)] = 'U',
272
 
+    [BRLAPI_DOTS(1,1,1,0,0,1,1,0)] = 'V',
273
 
+    [BRLAPI_DOTS(0,1,0,1,1,1,1,0)] = 'W',
274
 
+    [BRLAPI_DOTS(1,0,1,1,0,1,1,0)] = 'X',
275
 
+    [BRLAPI_DOTS(1,0,1,1,1,1,1,0)] = 'Y',
276
 
+    [BRLAPI_DOTS(1,0,1,0,1,1,1,0)] = 'Z',
277
 
+
278
 
+    [BRLAPI_DOTS(0,0,1,0,1,1,0,0)] = '0',
279
 
+    [BRLAPI_DOTS(0,1,0,0,0,0,0,0)] = '1',
280
 
+    [BRLAPI_DOTS(0,1,1,0,0,0,0,0)] = '2',
281
 
+    [BRLAPI_DOTS(0,1,0,0,1,0,0,0)] = '3',
282
 
+    [BRLAPI_DOTS(0,1,0,0,1,1,0,0)] = '4',
283
 
+    [BRLAPI_DOTS(0,1,0,0,0,1,0,0)] = '5',
284
 
+    [BRLAPI_DOTS(0,1,1,0,1,0,0,0)] = '6',
285
 
+    [BRLAPI_DOTS(0,1,1,0,1,1,0,0)] = '7',
286
 
+    [BRLAPI_DOTS(0,1,1,0,0,1,0,0)] = '8',
287
 
+    [BRLAPI_DOTS(0,0,1,0,1,0,0,0)] = '9',
288
 
+
289
 
+    [BRLAPI_DOTS(0,0,0,1,0,1,0,0)] = '.',
290
 
+    [BRLAPI_DOTS(0,0,1,1,0,1,0,0)] = '+',
291
 
+    [BRLAPI_DOTS(0,0,1,0,0,1,0,0)] = '-',
292
 
+    [BRLAPI_DOTS(1,0,0,0,0,1,0,0)] = '*',
293
 
+    [BRLAPI_DOTS(0,0,1,1,0,0,0,0)] = '/',
294
 
+    [BRLAPI_DOTS(1,1,1,0,1,1,0,0)] = '(',
295
 
+    [BRLAPI_DOTS(0,1,1,1,1,1,0,0)] = ')',
296
 
+
297
 
+    [BRLAPI_DOTS(1,1,1,1,0,1,0,0)] = '&',
298
 
+    [BRLAPI_DOTS(0,0,1,1,1,1,0,0)] = '#',
299
 
+
300
 
+    [BRLAPI_DOTS(0,0,0,0,0,1,0,0)] = ',',
301
 
+    [BRLAPI_DOTS(0,0,0,0,1,1,0,0)] = ';',
302
 
+    [BRLAPI_DOTS(1,0,0,0,1,1,0,0)] = ':',
303
 
+    [BRLAPI_DOTS(0,1,1,1,0,1,0,0)] = '!',
304
 
+    [BRLAPI_DOTS(1,0,0,1,1,1,0,0)] = '?',
305
 
+    [BRLAPI_DOTS(0,0,0,0,1,0,0,0)] = '"',
306
 
+    [BRLAPI_DOTS(0,0,1,0,0,0,0,0)] ='\'',
307
 
+    [BRLAPI_DOTS(0,0,0,1,0,0,0,0)] = '`',
308
 
+    [BRLAPI_DOTS(0,0,0,1,1,0,1,0)] = '^',
309
 
+    [BRLAPI_DOTS(0,0,0,1,1,0,0,0)] = '~',
310
 
+    [BRLAPI_DOTS(0,1,0,1,0,1,1,0)] = '[',
311
 
+    [BRLAPI_DOTS(1,1,0,1,1,1,1,0)] = ']',
312
 
+    [BRLAPI_DOTS(0,1,0,1,0,1,0,0)] = '{',
313
 
+    [BRLAPI_DOTS(1,1,0,1,1,1,0,0)] = '}',
314
 
+    [BRLAPI_DOTS(1,1,1,1,1,1,0,0)] = '=',
315
 
+    [BRLAPI_DOTS(1,1,0,0,0,1,0,0)] = '<',
316
 
+    [BRLAPI_DOTS(0,0,1,1,1,0,0,0)] = '>',
317
 
+    [BRLAPI_DOTS(1,1,0,1,0,1,0,0)] = '$',
318
 
+    [BRLAPI_DOTS(1,0,0,1,0,1,0,0)] = '%',
319
 
+    [BRLAPI_DOTS(0,0,0,1,0,0,1,0)] = '@',
320
 
+    [BRLAPI_DOTS(1,1,0,0,1,1,0,0)] = '|',
321
 
+    [BRLAPI_DOTS(1,1,0,0,1,1,1,0)] ='\\',
322
 
+    [BRLAPI_DOTS(0,0,0,1,1,1,0,0)] = '_',
323
 
+};
324
 
+
325
 
+/* The serial port can receive more of our data */
326
 
+static void baum_accept_input(struct CharDriverState *chr)
327
 
+{
328
 
+    BaumDriverState *baum = chr->opaque;
329
 
+    int room, first;
330
 
+
331
 
+    if (!baum->out_buf_used)
332
 
+        return;
333
 
+    room = qemu_chr_can_read(chr);
334
 
+    if (!room)
335
 
+        return;
336
 
+    if (room > baum->out_buf_used)
337
 
+        room = baum->out_buf_used;
338
 
+
339
 
+    first = BUF_SIZE - baum->out_buf_ptr;
340
 
+    if (room > first) {
341
 
+        qemu_chr_read(chr, baum->out_buf + baum->out_buf_ptr, first);
342
 
+        baum->out_buf_ptr = 0;
343
 
+        baum->out_buf_used -= first;
344
 
+        room -= first;
345
 
+    }
346
 
+    qemu_chr_read(chr, baum->out_buf + baum->out_buf_ptr, room);
347
 
+    baum->out_buf_ptr += room;
348
 
+    baum->out_buf_used -= room;
349
 
+}
350
 
+
351
 
+/* We want to send a packet */
352
 
+static void baum_write_packet(BaumDriverState *baum, const uint8_t *buf, int len)
353
 
+{
354
 
+    uint8_t io_buf[1 + 2 * len], *cur = io_buf;
355
 
+    int room;
356
 
+    *cur++ = ESC;
357
 
+    while (len--)
358
 
+        if ((*cur++ = *buf++) == ESC)
359
 
+            *cur++ = ESC;
360
 
+    room = qemu_chr_can_read(baum->chr);
361
 
+    len = cur - io_buf;
362
 
+    if (len <= room) {
363
 
+        /* Fits */
364
 
+        qemu_chr_read(baum->chr, io_buf, len);
365
 
+    } else {
366
 
+        int first;
367
 
+        uint8_t out;
368
 
+        /* Can't fit all, send what can be, and store the rest. */
369
 
+        qemu_chr_read(baum->chr, io_buf, room);
370
 
+        len -= room;
371
 
+        cur = io_buf + room;
372
 
+        if (len > BUF_SIZE - baum->out_buf_used) {
373
 
+            /* Can't even store it, drop the previous data... */
374
 
+            assert(len <= BUF_SIZE);
375
 
+            baum->out_buf_used = 0;
376
 
+            baum->out_buf_ptr = 0;
377
 
+        }
378
 
+        out = baum->out_buf_ptr;
379
 
+        baum->out_buf_used += len;
380
 
+        first = BUF_SIZE - baum->out_buf_ptr;
381
 
+        if (len > first) {
382
 
+            memcpy(baum->out_buf + out, cur, first);
383
 
+            out = 0;
384
 
+            len -= first;
385
 
+            cur += first;
386
 
+        }
387
 
+        memcpy(baum->out_buf + out, cur, len);
388
 
+    }
389
 
+}
390
 
+
391
 
+/* Called when the other end seems to have a wrong idea of our display size */
392
 
+static void baum_cellCount_timer_cb(void *opaque)
393
 
+{
394
 
+    BaumDriverState *baum = opaque;
395
 
+    uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y };
396
 
+    DPRINTF("Timeout waiting for DisplayData, sending cell count\n");
397
 
+    baum_write_packet(baum, cell_count, sizeof(cell_count));
398
 
+}
399
 
+
400
 
+/* Try to interpret a whole incoming packet */
401
 
+static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
402
 
+{
403
 
+    const uint8_t *cur = buf;
404
 
+    uint8_t req = 0;
405
 
+
406
 
+    if (!len--)
407
 
+        return 0;
408
 
+    if (*cur++ != ESC) {
409
 
+        while (*cur != ESC) {
410
 
+            if (!len--)
411
 
+                return 0;
412
 
+            cur++;
413
 
+        }
414
 
+        DPRINTF("Dropped %d bytes!\n", cur - buf);
415
 
+    }
416
 
+
417
 
+#define EAT(c) do {\
418
 
+    if (!len--) \
419
 
+        return 0; \
420
 
+    if ((c = *cur++) == ESC) { \
421
 
+        if (!len--) \
422
 
+            return 0; \
423
 
+        if (*cur++ != ESC) { \
424
 
+            DPRINTF("Broken packet %#2x, tossing\n", req); \
425
 
+               if (qemu_timer_pending(baum->cellCount_timer)) { \
426
 
+                qemu_del_timer(baum->cellCount_timer); \
427
 
+                baum_cellCount_timer_cb(baum); \
428
 
+            } \
429
 
+            return (cur - 2 - buf); \
430
 
+        } \
431
 
+    } \
432
 
+} while (0)
433
 
+
434
 
+    EAT(req);
435
 
+    switch (req) {
436
 
+    case BAUM_REQ_DisplayData:
437
 
+    {
438
 
+        uint8_t cells[baum->x * baum->y], c;
439
 
+        uint8_t text[baum->x * baum->y];
440
 
+        uint8_t zero[baum->x * baum->y];
441
 
+        int cursor = BRLAPI_CURSOR_OFF;
442
 
+        int i;
443
 
+
444
 
+        /* Allow 100ms to complete the DisplayData packet */
445
 
+        qemu_mod_timer(baum->cellCount_timer, qemu_get_clock(vm_clock) + ticks_per_sec / 10);
446
 
+        for (i = 0; i < baum->x * baum->y ; i++) {
447
 
+            EAT(c);
448
 
+            cells[i] = c;
449
 
+            if ((c & (BRLAPI_DOT7|BRLAPI_DOT8))
450
 
+                    == (BRLAPI_DOT7|BRLAPI_DOT8)) {
451
 
+                cursor = i + 1;
452
 
+                c &= ~(BRLAPI_DOT7|BRLAPI_DOT8);
453
 
+            }
454
 
+            if (!(c = nabcc_translation[c]))
455
 
+                c = '?';
456
 
+            text[i] = c;
457
 
+        }
458
 
+        qemu_del_timer(baum->cellCount_timer);
459
 
+
460
 
+        memset(zero, 0, sizeof(zero));
461
 
+
462
 
+        brlapi_writeArguments_t wa = {
463
 
+            .displayNumber = BRLAPI_DISPLAY_DEFAULT,
464
 
+            .regionBegin = 1,
465
 
+            .regionSize = baum->x * baum->y,
466
 
+            .text = text,
467
 
+            .textSize = baum->x * baum->y,
468
 
+            .andMask = zero,
469
 
+            .orMask = cells,
470
 
+            .cursor = cursor,
471
 
+            .charset = "ISO-8859-1",
472
 
+        };
473
 
+
474
 
+        if (brlapi__write(baum->brlapi, &wa) == -1)
475
 
+            brlapi_perror("baum brlapi_write");
476
 
+        break;
477
 
+    }
478
 
+    case BAUM_REQ_SetMode:
479
 
+    {
480
 
+        uint8_t mode, setting;
481
 
+        DPRINTF("SetMode\n");
482
 
+        EAT(mode);
483
 
+        EAT(setting);
484
 
+        /* ignore */
485
 
+        break;
486
 
+    }
487
 
+    case BAUM_REQ_SetProtocol:
488
 
+    {
489
 
+        uint8_t protocol;
490
 
+        DPRINTF("SetProtocol\n");
491
 
+        EAT(protocol);
492
 
+        /* ignore */
493
 
+        break;
494
 
+    }
495
 
+    case BAUM_REQ_GetDeviceIdentity:
496
 
+    {
497
 
+        uint8_t identity[17] = { BAUM_RSP_DeviceIdentity,
498
 
+            'B','a','u','m',' ','V','a','r','i','o' };
499
 
+        DPRINTF("GetDeviceIdentity\n");
500
 
+        identity[11] = '0' + baum->x / 10;
501
 
+        identity[12] = '0' + baum->x % 10;
502
 
+        baum_write_packet(baum, identity, sizeof(identity));
503
 
+        break;
504
 
+    }
505
 
+    case BAUM_REQ_GetVersionNumber:
506
 
+    {
507
 
+        uint8_t version[] = { BAUM_RSP_VersionNumber, 1 }; /* ? */
508
 
+        DPRINTF("GetVersionNumber\n");
509
 
+        baum_write_packet(baum, version, sizeof(version));
510
 
+        break;
511
 
+    }
512
 
+    case BAUM_REQ_GetSerialNumber:
513
 
+    {
514
 
+        uint8_t serial[] = { BAUM_RSP_SerialNumber,
515
 
+            '0','0','0','0','0','0','0','0' };
516
 
+        DPRINTF("GetSerialNumber\n");
517
 
+        baum_write_packet(baum, serial, sizeof(serial));
518
 
+        break;
519
 
+    }
520
 
+    case BAUM_REQ_GetKeys:
521
 
+    {
522
 
+        DPRINTF("Get%0#2x\n", req);
523
 
+        /* ignore */
524
 
+        break;
525
 
+    }
526
 
+    default:
527
 
+        DPRINTF("unrecognized request %0#2x\n", req);
528
 
+        do
529
 
+            if (!len--)
530
 
+                return 0;
531
 
+        while (*cur++ != ESC);
532
 
+        cur--;
533
 
+        break;
534
 
+    }
535
 
+    return cur - buf;
536
 
+}
537
 
+
538
 
+/* The other end is writing some data.  Store it and try to interpret */
539
 
+static int baum_write(CharDriverState *chr, const uint8_t *buf, int len)
540
 
+{
541
 
+    BaumDriverState *baum = chr->opaque;
542
 
+    int tocopy, cur, eaten, orig_len = len;
543
 
+
544
 
+    if (!len)
545
 
+        return 0;
546
 
+    if (!baum->brlapi)
547
 
+        return len;
548
 
+
549
 
+    while (len) {
550
 
+        /* Complete our buffer as much as possible */
551
 
+        tocopy = len;
552
 
+        if (tocopy > BUF_SIZE - baum->in_buf_used)
553
 
+            tocopy = BUF_SIZE - baum->in_buf_used;
554
 
+
555
 
+        memcpy(baum->in_buf + baum->in_buf_used, buf, tocopy);
556
 
+        baum->in_buf_used += tocopy;
557
 
+        buf += tocopy;
558
 
+        len -= tocopy;
559
 
+
560
 
+        /* Interpret it as much as possible */
561
 
+        cur = 0;
562
 
+        while (cur < baum->in_buf_used &&
563
 
+                (eaten = baum_eat_packet(baum, baum->in_buf + cur, baum->in_buf_used - cur)))
564
 
+            cur += eaten;
565
 
+
566
 
+        /* Shift the remainder */
567
 
+        if (cur) {
568
 
+            memmove(baum->in_buf, baum->in_buf + cur, baum->in_buf_used - cur);
569
 
+            baum->in_buf_used -= cur;
570
 
+        }
571
 
+
572
 
+        /* And continue if any data left */
573
 
+    }
574
 
+    return orig_len;
575
 
+}
576
 
+
577
 
+/* The other end sent us some event */
578
 
+static void baum_send_event(CharDriverState *chr, int event)
579
 
+{
580
 
+    BaumDriverState *baum = chr->opaque;
581
 
+    switch (event) {
582
 
+    case CHR_EVENT_BREAK:
583
 
+        break;
584
 
+    case CHR_EVENT_RESET:
585
 
+        /* Reset state */
586
 
+        baum->in_buf_used = 0;
587
 
+        break;
588
 
+    }
589
 
+}
590
 
+
591
 
+/* Send the key code to the other end */
592
 
+static void baum_send_key(BaumDriverState *baum, uint8_t type, uint8_t value) {
593
 
+    uint8_t packet[] = { type, value };
594
 
+    DPRINTF("writing key %x %x\n", type, value);
595
 
+    baum_write_packet(baum, packet, sizeof(packet));
596
 
+}
597
 
+
598
 
+/* We got some data on the BrlAPI socket */
599
 
+static void baum_chr_read(void *opaque)
600
 
+{
601
 
+    BaumDriverState *baum = opaque;
602
 
+    brlapi_keyCode_t code;
603
 
+    int ret;
604
 
+    if (!baum->brlapi)
605
 
+        return;
606
 
+    while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) {
607
 
+        DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code);
608
 
+        /* Emulate */
609
 
+        switch (code & BRLAPI_KEY_TYPE_MASK) {
610
 
+        case BRLAPI_KEY_TYPE_CMD:
611
 
+            switch (code & BRLAPI_KEY_CMD_BLK_MASK) {
612
 
+            case BRLAPI_KEY_CMD_ROUTE:
613
 
+                baum_send_key(baum, BAUM_RSP_RoutingKey, (code & BRLAPI_KEY_CMD_ARG_MASK)+1);
614
 
+                baum_send_key(baum, BAUM_RSP_RoutingKey, 0);
615
 
+                break;
616
 
+            case 0:
617
 
+                switch (code & BRLAPI_KEY_CMD_ARG_MASK) {
618
 
+                case BRLAPI_KEY_CMD_FWINLT:
619
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2);
620
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
621
 
+                    break;
622
 
+                case BRLAPI_KEY_CMD_FWINRT:
623
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR2);
624
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
625
 
+                    break;
626
 
+                case BRLAPI_KEY_CMD_LNUP:
627
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR1);
628
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
629
 
+                    break;
630
 
+                case BRLAPI_KEY_CMD_LNDN:
631
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR3);
632
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
633
 
+                    break;
634
 
+                case BRLAPI_KEY_CMD_TOP:
635
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TR1);
636
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
637
 
+                    break;
638
 
+                case BRLAPI_KEY_CMD_BOT:
639
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL3|BAUM_TR3);
640
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
641
 
+                    break;
642
 
+                case BRLAPI_KEY_CMD_TOP_LEFT:
643
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1);
644
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
645
 
+                    break;
646
 
+                case BRLAPI_KEY_CMD_BOT_LEFT:
647
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR3);
648
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
649
 
+                    break;
650
 
+                case BRLAPI_KEY_CMD_HOME:
651
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1|BAUM_TR3);
652
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
653
 
+                    break;
654
 
+                case BRLAPI_KEY_CMD_PREFMENU:
655
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TL3|BAUM_TR1);
656
 
+                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
657
 
+                    break;
658
 
+                }
659
 
+            }
660
 
+            break;
661
 
+        case BRLAPI_KEY_TYPE_SYM:
662
 
+            break;
663
 
+        }
664
 
+    }
665
 
+    if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) {
666
 
+        brlapi_perror("baum: brlapi_readKey");
667
 
+        brlapi__closeConnection(baum->brlapi);
668
 
+        free(baum->brlapi);
669
 
+        baum->brlapi = NULL;
670
 
+    }
671
 
+}
672
 
+
673
 
+CharDriverState *chr_baum_init(void)
674
 
+{
675
 
+    BaumDriverState *baum;
676
 
+    CharDriverState *chr;
677
 
+    brlapi_handle_t *handle;
678
 
+#ifdef CONFIG_SDL
679
 
+    SDL_SysWMinfo info;
680
 
+#endif
681
 
+    int tty;
682
 
+
683
 
+    baum = qemu_mallocz(sizeof(BaumDriverState));
684
 
+    if (!baum)
685
 
+        return NULL;
686
 
+
687
 
+    baum->chr = chr = qemu_mallocz(sizeof(CharDriverState));
688
 
+    if (!chr)
689
 
+        goto fail_baum;
690
 
+
691
 
+    chr->opaque = baum;
692
 
+    chr->chr_write = baum_write;
693
 
+    chr->chr_send_event = baum_send_event;
694
 
+    chr->chr_accept_input = baum_accept_input;
695
 
+
696
 
+    handle = qemu_mallocz(brlapi_getHandleSize());
697
 
+    if (!handle)
698
 
+        goto fail_chr;
699
 
+    baum->brlapi = handle;
700
 
+
701
 
+    baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL);
702
 
+    if (baum->brlapi_fd == -1) {
703
 
+        brlapi_perror("baum_init: brlapi_openConnection");
704
 
+        goto fail_handle;
705
 
+    }
706
 
+
707
 
+    baum->cellCount_timer = qemu_new_timer(vm_clock, baum_cellCount_timer_cb, baum);
708
 
+
709
 
+    if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) {
710
 
+        brlapi_perror("baum_init: brlapi_getDisplaySize");
711
 
+        goto fail;
712
 
+    }
713
 
+
714
 
+#ifdef CONFIG_SDL
715
 
+    memset(&info, 0, sizeof(info));
716
 
+    SDL_VERSION(&info.version);
717
 
+    if (SDL_GetWMInfo(&info))
718
 
+        tty = info.info.x11.wmwindow;
719
 
+    else
720
 
+#endif
721
 
+        tty = BRLAPI_TTY_DEFAULT;
722
 
+
723
 
+    if (brlapi__enterTtyMode(handle, tty, NULL) == -1) {
724
 
+        brlapi_perror("baum_init: brlapi_enterTtyMode");
725
 
+        goto fail;
726
 
+    }
727
 
+
728
 
+    qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
729
 
+
730
 
+    qemu_chr_reset(chr);
731
 
+
732
 
+    return chr;
733
 
+
734
 
+fail:
735
 
+    qemu_free_timer(baum->cellCount_timer);
736
 
+    brlapi__closeConnection(handle);
737
 
+fail_handle:
738
 
+    free(handle);
739
 
+fail_chr:
740
 
+    free(chr);
741
 
+fail_baum:
742
 
+    free(baum);
743
 
+    return NULL;
744
 
+}
745
 
+
746
 
+USBDevice *usb_baum_init(void)
747
 
+{
748
 
+    /* USB Product ID of Super Vario 40 */
749
 
+    return usb_serial_init("productid=FE72:braille");
750
 
+}
751
 
Index: qemu-0.9.1/hw/baum.h
752
 
===================================================================
753
 
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
754
 
+++ qemu-0.9.1/hw/baum.h        2008-04-14 11:26:14.000000000 +0200
755
 
@@ -0,0 +1,29 @@
756
 
+/*
757
 
+ * QEMU Baum
758
 
+ *
759
 
+ * Copyright (c) 2008 Samuel Thibault
760
 
+ *
761
 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
762
 
+ * of this software and associated documentation files (the "Software"), to deal
763
 
+ * in the Software without restriction, including without limitation the rights
764
 
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
765
 
+ * copies of the Software, and to permit persons to whom the Software is
766
 
+ * furnished to do so, subject to the following conditions:
767
 
+ *
768
 
+ * The above copyright notice and this permission notice shall be included in
769
 
+ * all copies or substantial portions of the Software.
770
 
+ *
771
 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
772
 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
773
 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
774
 
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
775
 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
776
 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
777
 
+ * THE SOFTWARE.
778
 
+ */
779
 
+
780
 
+/* usb device */
781
 
+USBDevice *usb_baum_init(void);
782
 
+
783
 
+/* char device */
784
 
+CharDriverState *chr_baum_init(void);
785
 
Index: qemu-0.9.1/qemu-doc.texi
786
 
===================================================================
787
 
--- qemu-0.9.1.orig/qemu-doc.texi       2008-04-14 11:26:14.000000000 +0200
788
 
+++ qemu-0.9.1/qemu-doc.texi    2008-04-14 11:26:14.000000000 +0200
789
 
@@ -528,6 +528,10 @@
790
 
 Serial converter to host character device @var{dev}, see @code{-serial} for the
791
 
 available devices.
792
 
 
793
 
+@item braille
794
 
+Braille device.  This will use BrlAPI to display the braille output on a real
795
 
+or fake device.
796
 
+
797
 
 @end table
798
 
 
799
 
 @end table
800
 
@@ -841,6 +845,10 @@
801
 
 @item -serial mon:telnet::4444,server,nowait
802
 
 @end table
803
 
 
804
 
+@item braille
805
 
+Braille device.  This will use BrlAPI to display the braille output on a real
806
 
+or fake device.
807
 
+
808
 
 @end table
809
 
 
810
 
 @item -parallel @var{dev}
811
 
@@ -1596,6 +1604,9 @@
812
 
 @end example
813
 
 will connect to tcp port 4444 of ip 192.168.0.2, and plug that to the virtual
814
 
 serial converter, faking a Matrix Orbital LCD Display (USB ID 0403:FA00).
815
 
+@item braille
816
 
+Braille device.  This will use BrlAPI to display the braille output on a real
817
 
+or fake device.
818
 
 @end table
819
 
 
820
 
 @node host_usb_devices
821
 
Index: qemu-0.9.1/vl.c
822
 
===================================================================
823
 
--- qemu-0.9.1.orig/vl.c        2008-04-14 11:26:14.000000000 +0200
824
 
+++ qemu-0.9.1/vl.c     2008-04-14 11:27:17.000000000 +0200
825
 
@@ -29,6 +29,7 @@
826
 
 #include "hw/fdc.h"
827
 
 #include "hw/audiodev.h"
828
 
 #include "hw/isa.h"
829
 
+#include "hw/baum.h"
830
 
 #include "net.h"
831
 
 #include "console.h"
832
 
 #include "sysemu.h"
833
 
@@ -3434,7 +3435,12 @@
834
 
     } else
835
 
     if (strstart(filename, "file:", &p)) {
836
 
         return qemu_chr_open_win_file_out(p);
837
 
-    }
838
 
+    } else
839
 
+#endif
840
 
+#ifdef CONFIG_BRLAPI
841
 
+    if (!strcmp(filename, "braille")) {
842
 
+        return chr_baum_init();
843
 
+    } else
844
 
 #endif
845
 
     {
846
 
         return NULL;
847
 
@@ -5217,6 +5223,10 @@
848
 
         dev = usb_wacom_init();
849
 
     } else if (strstart(devname, "serial:", &p)) {
850
 
         dev = usb_serial_init(p);
851
 
+#ifdef CONFIG_BRLAPI
852
 
+    } else if (!strcmp(devname, "braille")) {
853
 
+        dev = usb_baum_init();
854
 
+#endif
855
 
     } else {
856
 
         return -1;
857
 
     }