28538c77098921f5a93d911ccb95852cb76159b8
[rfid/librfid.git] / gemtag / gemtag.c
1 /*
2  * (C) 2006 by Frank Zirkelbach <hackbard@hackdaworld.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License version 2 
6  *  as published by the Free Software Foundation
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <errno.h>
23
24 #include <usb.h>
25 #include "gemtag.h"
26
27 /* variables */
28
29 struct gemtag_handle {
30         struct usb_dev_handle *handle;
31 };
32
33 /* functions */
34
35 struct usb_device *find_device(unsigned short vendor, unsigned short device) {
36         
37         struct usb_bus *bus;
38         struct usb_device *dev;
39
40         bus=usb_get_busses();
41         while(bus) {
42                 dev=bus->devices;
43                 while(dev) {
44                         if(dev->descriptor.idVendor==vendor &&
45                            dev->descriptor.idProduct==device)
46                                 return dev;
47                         dev=dev->next;
48                 }
49                 bus=bus->next;
50         }
51         return NULL;
52 }
53
54 struct gemtag_handle *gemtag_open(void) {
55         struct usb_device *gemtag;
56         unsigned char rbuf[16];
57         unsigned int rlen;
58         unsigned int i,numconf;
59         unsigned int j,numint;
60         struct gemtag_handle *gh;
61
62         rlen=sizeof(rbuf);
63
64         usb_init();
65         usb_find_busses();
66         usb_find_devices();
67
68         gemtag=find_device(USB_VENDOR_GEMTAG, USB_DEVICE_X501);
69         if(!gemtag) return NULL;
70
71         gh=malloc(sizeof(struct gemtag_handle));
72         if(!gh) return NULL;
73
74         memset(gh,0,sizeof(struct gemtag_handle));
75
76         numconf=gemtag->descriptor.bNumConfigurations;
77         printf("found gemtag, %u configurations\n",numconf);
78         for(i=0;i<numconf;i++) {
79                 numint=gemtag->config[i].bNumInterfaces;
80                 printf("config %u [nr %u] has %u interfaces\n",
81                        i,gemtag->config[i].bConfigurationValue,
82                        numint);
83                 for(j=0;j<numint;j++) {
84                         printf("config %u interface %u has %u altsettings\n",
85                                i,j,gemtag->config[i].interface[j].num_altsetting);
86                 }
87         }
88
89         gh->handle=usb_open(gemtag);
90         if(!gh->handle)
91                 goto out_free;
92
93 out_free:
94         free(gh);
95         return NULL;
96 }
97         
98 int main(int argc, char **argv) {
99
100         struct gemtag_handle *gh;
101
102         gh=gemtag_open();
103
104         return 1;
105 }
106