- Add support of ORF P4 Irdeto mode
[oscam.git] / utils / list_smargo.c
blob8e2f8ad2ef3c641ef0d663399901354399d2d174
1 /*
2 * libusb example program to list devices on the bus
3 * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <sys/types.h>
23 #include <string.h>
24 #include <strings.h>
25 #include "../globals.h"
26 #include "../csctapi/ifd_smartreader_types.h"
28 #if defined(__FreeBSD__)
29 #include <libusb.h>
30 #else
31 #include <libusb-1.0/libusb.h>
32 #endif
34 static void smartreader_check_endpoint(libusb_device *usb_dev, libusb_device_handle *handle)
36 struct libusb_device_descriptor usbdesc;
37 struct libusb_config_descriptor *configDesc;
38 int32_t ret;
39 int32_t j, k, l;
40 uint32_t m;
41 uint8_t tmpEndpointAddress;
42 int32_t nb_endpoint_ok;
43 int32_t busid, devid;
44 unsigned char iserialbuffer[128], iproductbuffer[128];
45 char *productptr = (char *)iproductbuffer;
46 static const char *const typename_str[6] = {"SR", "Infinity", "SRv2", "TripleP1", "TripleP2", "TripleP3"};
48 nb_endpoint_ok = 0;
50 ret = libusb_get_device_descriptor(usb_dev, &usbdesc);
51 if(ret < 0)
53 printf("Smartreader : couldn't read device descriptor, assuming this is not a smartreader");
54 return;
56 if(usbdesc.bNumConfigurations)
58 ret = libusb_get_active_config_descriptor(usb_dev, &configDesc);
59 if(ret)
61 printf("Smartreader : couldn't read config descriptor , assuming this is not a smartreader");
62 return;
64 for(m = 0; m < sizeof(reader_types) / sizeof(struct s_reader_types); ++m)
66 nb_endpoint_ok = 0;
67 for(j = 0; j < (configDesc->bNumInterfaces); j++)
69 for(k = 0; k < configDesc->interface[j].num_altsetting; k++)
71 for(l = 0; l < configDesc->interface[j].altsetting[k].bNumEndpoints; l++)
73 tmpEndpointAddress = configDesc->interface[j].altsetting[k].endpoint[l].bEndpointAddress;
74 if((tmpEndpointAddress == reader_types[m].in_ep || tmpEndpointAddress == reader_types[m].out_ep))
76 nb_endpoint_ok++;
82 if(nb_endpoint_ok == 2)
84 busid = libusb_get_bus_number(usb_dev);
85 devid = libusb_get_device_address(usb_dev);
86 memset(iserialbuffer, 0, sizeof(iserialbuffer));
87 memset(iproductbuffer, 0, sizeof(iproductbuffer));
88 libusb_get_string_descriptor_ascii(handle, usbdesc.iSerialNumber, iserialbuffer, sizeof(iserialbuffer));
89 libusb_get_string_descriptor_ascii(handle, usbdesc.iProduct, iproductbuffer, sizeof(iproductbuffer));
90 if ((!((!strcasecmp(productptr, "Triple Reader+")) && (m == 2))) && (!((!strcasecmp(productptr, "Smartreader2 plus")) && (m == 3)))) {
91 printf("bus %03d, device %03d : %04x:%04x %s (type=%s, in_ep=%02x, out_ep=%02x; insert in oscam.server 'device = %s%sSerial:%s')\n",
92 busid, devid,
93 usbdesc.idVendor, usbdesc.idProduct, strlen(productptr) > 0 ? productptr : "Smartreader",
94 typename_str[reader_types[m].rdrtypename], reader_types[m].in_ep, reader_types[m].out_ep,
95 reader_types[m].rdrtypename == 0 ? "" : typename_str[reader_types[m].rdrtypename] , reader_types[m].rdrtypename == 0 ? "" : ";", iserialbuffer
96 );}
102 static void print_devs(libusb_device **devs)
104 libusb_device *dev;
105 libusb_device_handle *handle;
106 int32_t i = 0;
107 int32_t ret;
109 while((dev = devs[i++]) != NULL)
111 struct libusb_device_descriptor usbdesc;
112 int32_t r = libusb_get_device_descriptor(dev, &usbdesc);
113 if(r < 0)
115 fprintf(stderr, "failed to get device descriptor");
116 return;
118 if(usbdesc.idVendor == 0x0403 && (usbdesc.idProduct == 0x6001 || usbdesc.idProduct == 0x6011))
120 ret = libusb_open(dev, &handle);
121 if(ret)
123 printf("couldn't open device %03d:%03d\n", libusb_get_bus_number(dev), libusb_get_device_address(dev));
124 continue;
126 // check for smargo endpoints.
127 smartreader_check_endpoint(dev, handle);
129 libusb_close(handle);
134 int32_t main(void)
136 libusb_device **devs;
137 int32_t r;
138 ssize_t cnt;
140 r = libusb_init(NULL);
141 if(r < 0)
142 { return r; }
144 printf("Looking for smartreader compatible devices...\n");
146 cnt = libusb_get_device_list(NULL, &devs);
147 if(cnt < 0)
148 { return (int32_t) cnt; }
150 print_devs(devs);
151 libusb_free_device_list(devs, 1);
153 libusb_exit(NULL);
155 return 0;