annotate controlmsg.c @ 10:078dc69945ad

working: libjpeg-turbo support, handle fb and monitor with different size
author Peter Meerwald <pmeerw@pmeerw.net>
date Sun, 15 May 2011 17:48:57 +0200
parents 71b9540bdd23
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
1 /* $Id: usbreplay.c,v 1.7 2004/02/07 17:02:32 bd Exp $ */
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
2 /* Use only with the Hauppauge WinTV PVR usb2, VID/PID 2040/2900. */
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
3 /* No commercial affiliation, warranty, copyright, party invitation, */
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
4 /* fitness or non-fitness, implied or otherwise, is claimed by this comment. */
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
5 /* Compile with -lusb, then put it where capture.pl will find it. */
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
6
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
7 #include <usb.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
8 #include <stdlib.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
9 #include <stdio.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
10 #include <string.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
11 #include <fcntl.h>
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
12
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
13 struct usb_device *find_first_pvr() {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
14 struct usb_bus *bus;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
15 struct usb_device *dev;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
16
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
17 usb_init();
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
18 usb_find_busses();
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
19 usb_find_devices();
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
20
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
21 for (bus = usb_busses; bus; bus = bus->next) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
22 for (dev = bus->devices; dev; dev = dev->next) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
23 if (dev->descriptor.idVendor == 0x04e8 &&
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
24 dev->descriptor.idProduct == 0x2027) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
25 fprintf(stderr, "Samsung photoframe in Mass Storage mode found ...\n");
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
26 return dev;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
27 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
28 else if (dev->descriptor.idVendor == 0x04e8 &&
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
29 dev->descriptor.idProduct == 0x2028){
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
30 fprintf(stderr, "Samsung photoframe in Custom Product mode found ...\n");
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
31 return NULL;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
32 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
33 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
34 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
35 fprintf(stderr, "No Samsung device found ...\n");
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
36 return NULL;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
37 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
38
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
39
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
40 int replay() {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
41 int res = -1;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
42 char buf[256];
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
43 usb_dev_handle *udev;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
44 struct usb_device *dev = NULL;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
45 int numeps = 0;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
46
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
47 dev = find_first_pvr();
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
48 if (dev == NULL) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
49 fprintf(stderr, "Since no Samsung device in Mass Storage mode found, not going to do anything\n");
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
50 return 0;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
51 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
52 udev = usb_open(dev);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
53
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
54 setuid(getuid());
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
55
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
56 strcpy(buf, "** no string **");
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
57 res = usb_get_string_simple(udev, dev->descriptor.iManufacturer, buf, sizeof(buf));
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
58 fprintf(stderr, "usb_get_string_simple => %d, %s\n", res, buf);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
59
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
60 char blah[254];
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
61 memset(blah,0,254);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
62
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
63 res = usb_control_msg(udev, USB_TYPE_STANDARD | USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, 0xfe, 0xfe, blah, 0xfe, 1000);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
64 printf("usb_control_msg() = %d\n",res);
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
65
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
66 fprintf(stderr, "Just switched to 0x2028 Custom Product mode\n");
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
67 return 0;
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
68 }
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
69
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
70
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
71 int main(int argc, char *argv[]) {
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
72 return replay();
71b9540bdd23 starting, importing Woo's code and adding minimon
Peter Meerwald <pmeerw@pmeerw.net>
parents:
diff changeset
73 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.