chiark / gitweb /
Merge libudev, udev, and the unconditional extras in a single Makefile.am.
[elogind.git] / extras / modem-modeswitch / ma8280p_us.c
1 /* http://www.natox.be/ma8280p/
2  * http://www.leopold.dk/~martin/ma-8230p.html
3  * http://figvam.blogspot.com/2007/01/mobile-action-8730p-usb-cable-and-linux.html
4  */
5
6 /*
7  *
8  * Code by davy hollevoet. This is simply an adaptation of code
9  * generated by usbsnoop2libusb. (http://iki.fi/lindi/usb/usbsnoop2libusb.pl)
10  *
11  * This code is released under both the GPL version 2 and BSD licenses.
12  * Either license may be used.
13  *
14  * GPLv2
15  * ********
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * In addition:
27  *
28  * Redistribution and use in source and binary forms, with or without
29  * modification, are permitted provided that the following conditions
30  * are met:
31  *
32  * 1. Redistributions of source code must retain the above copyright
33  * notice, this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright
35  * notice, this list of conditions and the following disclaimer in the
36  * documentation and/or other materials provided with the distribution.
37  * 3. The name of the author may not be used to endorse or promote
38  * products derived from this software without specific prior written
39  * permission.
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
42  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
45  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
46  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
47  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
50  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51  * POSSIBILITY OF SUCH DAMAGE.
52  *
53  * BSD
54  * ******
55  * Copyright (c) 1998, Regents of the University of California
56  * All rights reserved.
57  * Redistribution and use in source and binary forms, with or without
58  * modification, are permitted provided that the following conditions are met:
59  *
60  *     * Redistributions of source code must retain the above copyright
61  *       notice, this list of conditions and the following disclaimer.
62  *     * Redistributions in binary form must reproduce the above copyright
63  *       notice, this list of conditions and the following disclaimer in the
64  *       documentation and/or other materials provided with the distribution.
65  *     * Neither the name of the University of California, Berkeley nor the
66  *       names of its contributors may be used to endorse or promote products
67  *       derived from this software without specific prior written permission.
68  *
69  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
70  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
71  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
72  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
73  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
74  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
75  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
76  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
77  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
78  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79  *
80  */
81
82 /* This file is (mostly) generated with usbsnoop2libusb.pl from a usbsnoop log file. */
83 /* Latest version of the script should be in http://iki.fi/lindi/usb/usbsnoop2libusb.pl */
84 #include <stdio.h>
85 #include <stdlib.h>
86 #include <string.h>
87 #include <assert.h>
88 #include <signal.h>
89 #include <ctype.h>
90 #include <usb.h>
91
92 #include "utils.h"
93 #include "ma8280p_us.h"
94
95 int ma8280p_switch (struct usb_dev_handle *devh, struct usb_device *dev)
96 {
97         int ret = 1;
98         char *buf = NULL;
99
100         buf = malloc (65535);
101         if (!buf) {
102                 error ("%s: not enough memory", dev->filename, ret);
103                 return -1;
104         }
105
106         ret = usb_get_descriptor(devh, 0x0000001, 0x0000000, buf, 0x0000012);
107         usleep(6*1000);
108         ret = usb_get_descriptor(devh, 0x0000001, 0x0000000, buf, 0x0000012);
109         usleep(6*1000);
110         ret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000400);
111         usleep(10*1000);
112         ret = usb_release_interface(devh, 0);
113         if (ret != 0) 
114                 debug ("%s: failed to release interface before set_configuration: %d", dev->filename, ret);
115         ret = usb_set_configuration(devh, 0x0000001);
116         ret = usb_claim_interface(devh, 0);
117         if (ret != 0) 
118                 debug ("%s: claim after set_configuration failed with error %d", dev->filename, ret);
119         //ret = usb_set_altinterface(devh, 0);
120         //usleep(33*1000);
121         ret = usb_control_msg(devh, USB_TYPE_CLASS + USB_RECIP_INTERFACE + USB_ENDPOINT_IN, 0x0000001, 0x0000300, 0x0000000, buf, 0x0000008, 1000);
122         usleep(5*1000);
123         memcpy(buf, "\xb0\x04\x00\x00\x02\x90\x26\x86", 0x0000008);
124         ret = usb_control_msg(devh, USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x0000009, 0x0000300, 0x0000000, buf, 0x0000008, 1000);
125         usleep(4*1000);
126         memcpy(buf, "\xb0\x04\x00\x00\x02\x90\x26\x86", 0x0000008);
127         ret = usb_control_msg(devh, USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x0000009, 0x0000300, 0x0000000, buf, 0x0000008, 1000);
128         usleep(4*1000);
129
130         usleep(4*1000);
131         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
132         usleep(6*1000);
133         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
134         usleep(1*1000);
135         //URB_FUNCTION_GET_STATUS_FROM_ENDPOINT skipped
136         usleep(4*1000);
137         memcpy(buf, "\x37\x01\xfe\xdb\xc1\x33\x1f\x83", 0x0000008);
138         ret = usb_interrupt_write(devh, 0x00000002, buf, 0x0000008, 1000);
139         usleep(3*1000);
140         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
141         usleep(1*1000);
142         memcpy(buf, "\x37\x0e\xb5\x9d\x3b\x8a\x91\x51", 0x0000008);
143         ret = usb_interrupt_write(devh, 0x00000002, buf, 0x0000008, 1000);
144         usleep(7*1000);
145         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
146         usleep(1*1000);
147         memcpy(buf, "\x34\x87\xba\x0d\xfc\x8a\x91\x51", 0x0000008);
148         ret = usb_interrupt_write(devh, 0x00000002, buf, 0x0000008, 1000);
149         usleep(7*1000);
150         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
151         usleep(8*1000);
152         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
153         usleep(8*1000);
154         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
155         usleep(8*1000);
156         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
157         usleep(8*1000);
158         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
159         usleep(8*1000);
160         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
161         usleep(8*1000);
162         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
163         usleep(8*1000);
164         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
165         usleep(8*1000);
166         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
167         usleep(8*1000);
168         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
169         usleep(8*1000);
170         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
171         usleep(8*1000);
172         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
173         usleep(8*1000);
174         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
175         usleep(8*1000);
176         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
177         usleep(8*1000);
178         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
179         usleep(8*1000);
180         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
181         usleep(8*1000);
182         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
183         usleep(8*1000);
184         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
185         usleep(8*1000);
186         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
187         usleep(8*1000);
188         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
189         usleep(8*1000);
190         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
191         usleep(8*1000);
192         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
193         usleep(8*1000);
194         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
195         usleep(8*1000);
196         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
197         usleep(8*1000);
198         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
199         usleep(8*1000);
200         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
201         usleep(8*1000);
202         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
203         usleep(8*1000);
204         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
205         usleep(8*1000);
206         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
207         usleep(8*1000);
208         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
209         usleep(8*1000);
210         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
211         usleep(8*1000);
212         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
213         usleep(8*1000);
214         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
215         usleep(8*1000);
216         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
217         usleep(8*1000);
218         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
219         usleep(8*1000);
220         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
221         usleep(8*1000);
222         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
223         usleep(8*1000);
224         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
225         usleep(8*1000);
226         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
227         usleep(8*1000);
228         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
229         usleep(8*1000);
230         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
231         usleep(8*1000);
232         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
233         usleep(8*1000);
234         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
235         usleep(8*1000);
236         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
237         usleep(8*1000);
238         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
239         usleep(8*1000);
240         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
241         usleep(8*1000);
242         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
243         usleep(8*1000);
244         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
245         usleep(8*1000);
246         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
247         usleep(8*1000);
248         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
249         usleep(8*1000);
250         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
251         usleep(8*1000);
252         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
253         usleep(8*1000);
254         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
255         usleep(8*1000);
256         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
257         usleep(8*1000);
258         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
259         usleep(8*1000);
260         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
261         usleep(8*1000);
262         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
263         usleep(8*1000);
264         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
265         usleep(8*1000);
266         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
267         usleep(8*1000);
268         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
269         usleep(8*1000);
270         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
271         usleep(8*1000);
272         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
273         usleep(8*1000);
274         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
275         usleep(2*1000);
276         //URB_FUNCTION_GET_STATUS_FROM_ENDPOINT skipped
277         usleep(4*1000);
278         memcpy(buf, "\x37\x01\xfe\xdb\xc1\x33\x1f\x83", 0x0000008);
279         ret = usb_interrupt_write(devh, 0x00000002, buf, 0x0000008, 1000);
280         usleep(2*1000);
281         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
282         usleep(1*1000);
283         memcpy(buf, "\x37\x0e\xb5\x9d\x3b\x8a\x91\x51", 0x0000008);
284         ret = usb_interrupt_write(devh, 0x00000002, buf, 0x0000008, 1000);
285         usleep(7*1000);
286         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
287         usleep(1*1000);
288         memcpy(buf, "\x34\x87\xba\x0d\xfc\x8a\x91\x51", 0x0000008);
289         ret = usb_interrupt_write(devh, 0x00000002, buf, 0x0000008, 1000);
290         usleep(7*1000);
291         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
292         usleep(8*1000);
293         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
294         usleep(8*1000);
295         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
296         usleep(8*1000);
297         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
298         usleep(8*1000);
299         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
300         usleep(8*1000);
301         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
302         usleep(8*1000);
303         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
304         usleep(8*1000);
305         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
306         usleep(8*1000);
307         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
308         usleep(8*1000);
309         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
310         usleep(8*1000);
311         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
312         usleep(8*1000);
313         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
314         usleep(8*1000);
315         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
316         usleep(8*1000);
317         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
318         usleep(8*1000);
319         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
320         usleep(8*1000);
321         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
322         usleep(8*1000);
323         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
324         usleep(8*1000);
325         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
326         usleep(8*1000);
327         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
328         usleep(8*1000);
329         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
330         usleep(8*1000);
331         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
332         usleep(8*1000);
333         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
334         usleep(8*1000);
335         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
336         usleep(8*1000);
337         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
338         usleep(8*1000);
339         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
340         usleep(8*1000);
341         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
342         usleep(8*1000);
343         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
344         usleep(8*1000);
345         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
346         usleep(8*1000);
347         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
348         usleep(8*1000);
349         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
350         usleep(8*1000);
351         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
352         usleep(8*1000);
353         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
354         usleep(8*1000);
355         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
356         usleep(8*1000);
357         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
358         usleep(8*1000);
359         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
360         usleep(8*1000);
361         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
362         usleep(8*1000);
363         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
364         usleep(8*1000);
365         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
366         usleep(8*1000);
367         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
368         usleep(8*1000);
369         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
370         usleep(8*1000);
371         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
372         usleep(8*1000);
373         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
374         usleep(8*1000);
375         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
376         usleep(8*1000);
377         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
378         usleep(8*1000);
379         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
380         usleep(8*1000);
381         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
382         usleep(8*1000);
383         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
384         usleep(8*1000);
385         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
386         usleep(8*1000);
387         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
388         usleep(8*1000);
389         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
390         usleep(8*1000);
391         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
392         usleep(8*1000);
393         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
394         usleep(8*1000);
395         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
396         usleep(8*1000);
397         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
398         usleep(8*1000);
399         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
400         usleep(8*1000);
401         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
402         usleep(8*1000);
403         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
404         usleep(8*1000);
405         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
406         usleep(8*1000);
407         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
408         usleep(8*1000);
409         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
410         usleep(8*1000);
411         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
412         usleep(8*1000);
413         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
414         usleep(8*1000);
415         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
416         usleep(8*1000);
417         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
418         usleep(8*1000);
419         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
420         usleep(8*1000);
421         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
422         usleep(8*1000);
423         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
424         usleep(8*1000);
425         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
426         usleep(8*1000);
427         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
428         usleep(8*1000);
429         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
430         usleep(8*1000);
431         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
432         usleep(8*1000);
433         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
434         usleep(8*1000);
435         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
436         usleep(1*1000);
437         //URB_FUNCTION_GET_STATUS_FROM_ENDPOINT skipped
438         usleep(4*1000);
439         memcpy(buf, "\x33\x04\xfe\x00\xf4\x6c\x1f\xf0", 0x0000008);
440         ret = usb_interrupt_write(devh, 0x00000002, buf, 0x0000008, 1000);
441         usleep(3*1000);
442         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
443         usleep(1*1000);
444         //URB_FUNCTION_GET_STATUS_FROM_ENDPOINT skipped
445         usleep(4*1000);
446         memcpy(buf, "\x32\x07\xfe\xf0\x29\xb9\x3a\xf0", 0x0000008);
447         ret = usb_interrupt_write(devh, 0x00000002, buf, 0x0000008, 1000);
448         usleep(3*1000);
449         ret = usb_interrupt_read(devh, 0x00000081, buf, 0x0000008, 1000);
450
451         if (buf)
452                 free (buf);
453         return 0;
454 }