Changeset 4998 for trunk/csctapi/ifd_smartreader.c
- Timestamp:
- 04/14/11 02:41:42 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/csctapi/ifd_smartreader.c
r4724 r4998 26 26 27 27 struct s_sr_config { 28 int F;28 int32_t F; 29 29 float D; 30 int fs;31 int N;32 int T;33 int inv;34 int parity;35 int irdeto;36 int running;30 int32_t fs; 31 int32_t N; 32 int32_t T; 33 int32_t inv; 34 int32_t parity; 35 int32_t irdeto; 36 int32_t running; 37 37 libusb_device *usb_dev; 38 38 libusb_device_handle *usb_dev_handle; … … 40 40 uint8_t in_ep; // 0x01 41 41 uint8_t out_ep; // 0x82 42 int index;42 int32_t index; 43 43 /** usb read timeout */ 44 int usb_read_timeout;44 int32_t usb_read_timeout; 45 45 /** usb write timeout */ 46 int usb_write_timeout;47 u nsigned intwritebuffer_chunksize;46 int32_t usb_write_timeout; 47 uint32_t writebuffer_chunksize; 48 48 unsigned char bitbang_enabled; 49 int baudrate;50 int interface; // 0 or 149 int32_t baudrate; 50 int32_t interface; // 0 or 1 51 51 /** maximum packet size. Needed for filtering modem status bytes every n packets. */ 52 u nsigned intmax_packet_size;52 uint32_t max_packet_size; 53 53 unsigned char g_read_buffer[4096]; 54 u nsigned intg_read_buffer_size;54 uint32_t g_read_buffer_size; 55 55 pthread_mutex_t g_read_mutex; 56 56 pthread_cond_t g_read_cond; 57 57 pthread_mutex_t g_usb_mutex; 58 58 pthread_cond_t g_usb_cond; 59 int poll;59 int32_t poll; 60 60 pthread_t rt; 61 61 unsigned char modem_status; … … 67 67 static struct libusb_device *find_smartreader(const char*busname,const char *devname, uint8_t out_endpoint); 68 68 static void smartreader_init(S_READER *reader, uint8_t out_endpoint); 69 static u nsigned intsmartreader_determine_max_packet_size(S_READER *reader);70 static int smartreader_usb_close_internal (S_READER *reader);71 static int smartreader_usb_reset(S_READER *reader);72 static int smartreader_usb_open_dev(S_READER *reader);73 static int smartreader_usb_purge_rx_buffer(S_READER *reader);74 static int smartreader_usb_purge_tx_buffer(S_READER *reader);75 static int smartreader_usb_purge_buffers(S_READER *reader);76 static int smartreader_convert_baudrate(int baudrate, S_READER *reader, unsigned short *value, unsigned short*index);77 static int smartreader_set_baudrate(S_READER *reader, int baudrate);78 static int smartreader_setdtr_rts(S_READER *reader, int dtr, int rts);79 static int smartreader_setflowctrl(S_READER *reader, int flowctrl);80 static int smartreader_set_line_property2(S_READER *reader, enum smartreader_bits_type bits,69 static uint32_t smartreader_determine_max_packet_size(S_READER *reader); 70 static int32_t smartreader_usb_close_internal (S_READER *reader); 71 static int32_t smartreader_usb_reset(S_READER *reader); 72 static int32_t smartreader_usb_open_dev(S_READER *reader); 73 static int32_t smartreader_usb_purge_rx_buffer(S_READER *reader); 74 static int32_t smartreader_usb_purge_tx_buffer(S_READER *reader); 75 static int32_t smartreader_usb_purge_buffers(S_READER *reader); 76 static int32_t smartreader_convert_baudrate(int32_t baudrate, S_READER *reader, uint16_t *value, uint16_t *index); 77 static int32_t smartreader_set_baudrate(S_READER *reader, int32_t baudrate); 78 static int32_t smartreader_setdtr_rts(S_READER *reader, int32_t dtr, int32_t rts); 79 static int32_t smartreader_setflowctrl(S_READER *reader, int32_t flowctrl); 80 static int32_t smartreader_set_line_property2(S_READER *reader, enum smartreader_bits_type bits, 81 81 enum smartreader_stopbits_type sbit, enum smartreader_parity_type parity, 82 82 enum smartreader_break_type break_type); 83 static int smartreader_set_line_property(S_READER *reader, enum smartreader_bits_type bits,83 static int32_t smartreader_set_line_property(S_READER *reader, enum smartreader_bits_type bits, 84 84 enum smartreader_stopbits_type sbit, enum smartreader_parity_type parity); 85 85 static void smart_flush(S_READER *reader); 86 static int smartreader_set_latency_timer(S_READER *reader, unsigned shortlatency);87 static void EnableSmartReader(S_READER *reader, int clock, unsigned short Fi, unsigned char Di, unsigned char Ni, unsigned char T,unsigned char inv, int parity);86 static int32_t smartreader_set_latency_timer(S_READER *reader, uint16_t latency); 87 static void EnableSmartReader(S_READER *reader, int32_t clock, uint16_t Fi, unsigned char Di, unsigned char Ni, unsigned char T,unsigned char inv, int32_t parity); 88 88 static void *ReaderThread(void *p); 89 static void smart_fastpoll(S_READER *reader, int on);90 91 static int init_count = 0;92 93 int SR_Init (struct s_reader *reader)89 static void smart_fastpoll(S_READER *reader, int32_t on); 90 91 static int32_t init_count = 0; 92 93 int32_t SR_Init (struct s_reader *reader) 94 94 { 95 95 uint8_t out_endpoint; 96 int ret;96 int32_t ret; 97 97 char device[128]; 98 98 char *busname; … … 182 182 183 183 184 int SR_GetStatus (struct s_reader *reader, int * in)185 { 186 int state;184 int32_t SR_GetStatus (struct s_reader *reader, int32_t * in) 185 { 186 int32_t state; 187 187 188 188 smart_fastpoll(reader, TRUE); … … 201 201 } 202 202 203 static int smart_read(S_READER *reader, unsigned char* buff, unsigned int size, int timeout_sec)204 { 205 int ret = 0;206 u nsigned inttotal_read = 0;203 static int32_t smart_read(S_READER *reader, unsigned char* buff, uint32_t size, int32_t timeout_sec) 204 { 205 int32_t ret = 0; 206 uint32_t total_read = 0; 207 207 struct timeval start, now, dif = {0}; 208 208 struct timespec timeout = {0}; … … 240 240 } 241 241 242 int SR_Reset (struct s_reader *reader, ATR *atr)242 int32_t SR_Reset (struct s_reader *reader, ATR *atr) 243 243 { 244 244 unsigned char data[ATR_MAX_SIZE]; 245 int ret;246 int atr_ok;247 u nsigned inti;248 int parity[4] = {EVEN, ODD, NONE, EVEN}; // the last EVEN is to try with different F, D values for irdeto card.245 int32_t ret; 246 int32_t atr_ok; 247 uint32_t i; 248 int32_t parity[4] = {EVEN, ODD, NONE, EVEN}; // the last EVEN is to try with different F, D values for irdeto card. 249 249 static const char * const parity_str[5] = {"NONE", "ODD", "EVEN", "MARK", "SPACE"}; 250 250 … … 331 331 } 332 332 333 static int smart_write(S_READER *reader, unsigned char* buff, unsigned intsize)334 { 335 336 u nsigned intidx;337 338 int write_size;339 u nsigned intoffset = 0;340 int total_written = 0;341 int written;333 static int32_t smart_write(S_READER *reader, unsigned char* buff, uint32_t size) 334 { 335 336 uint32_t idx; 337 338 int32_t write_size; 339 uint32_t offset = 0; 340 int32_t total_written = 0; 341 int32_t written; 342 342 343 343 if(size<reader->sr_config->writebuffer_chunksize) … … 351 351 write_size = size-offset; 352 352 353 int ret = libusb_bulk_transfer(reader->sr_config->usb_dev_handle,353 int32_t ret = libusb_bulk_transfer(reader->sr_config->usb_dev_handle, 354 354 reader->sr_config->in_ep, 355 355 buff+offset, … … 369 369 } 370 370 371 int SR_Transmit (struct s_reader *reader, BYTE * buffer, unsignedsize)372 { 373 u nsigned intret;371 int32_t SR_Transmit (struct s_reader *reader, BYTE * buffer, uint32_t size) 372 { 373 uint32_t ret; 374 374 375 375 smart_fastpoll(reader, TRUE); … … 382 382 } 383 383 384 int SR_Receive (struct s_reader *reader, BYTE * buffer, unsignedsize)385 { 386 u nsigned intret;384 int32_t SR_Receive (struct s_reader *reader, BYTE * buffer, uint32_t size) 385 { 386 uint32_t ret; 387 387 388 388 smart_fastpoll(reader, TRUE); … … 395 395 } 396 396 397 int SR_WriteSettings (struct s_reader *reader, unsigned short F, BYTE D, BYTE N, BYTE T, unsigned shortconvention)397 int32_t SR_WriteSettings (struct s_reader *reader, uint16_t F, BYTE D, BYTE N, BYTE T, uint16_t convention) 398 398 { 399 399 // smartreader supports 3.20, 3.43, 3.69, 4.00, 4.36, 4.80, 5.34, 6.00, 6.86, 8.00, 9.61, 12.0, 16.0 Mhz … … 426 426 } 427 427 428 int SR_SetParity (struct s_reader *reader, unsigned shortparity)429 { 430 int ret;428 int32_t SR_SetParity (struct s_reader *reader, uint16_t parity) 429 { 430 int32_t ret; 431 431 432 432 static const char * const parity_str[5]={"NONE", "ODD", "EVEN", "MARK", "SPACE"}; … … 443 443 } 444 444 445 int SR_Close (struct s_reader *reader)445 int32_t SR_Close (struct s_reader *reader) 446 446 { 447 447 if (!reader->sr_config) return OK; … … 466 466 } 467 467 468 int SR_FastReset(struct s_reader *reader, int delay)468 int32_t SR_FastReset(struct s_reader *reader, int32_t delay) 469 469 { 470 470 unsigned char data[ATR_MAX_SIZE]; 471 int ret;471 int32_t ret; 472 472 473 473 smart_fastpoll(reader, TRUE); … … 488 488 } 489 489 490 static void EnableSmartReader(S_READER *reader, int clock, unsigned short Fi, unsigned char Di, unsigned char Ni, unsigned char T, unsigned char inv,int parity) {491 492 int ret = 0;490 static void EnableSmartReader(S_READER *reader, int32_t clock, uint16_t Fi, unsigned char Di, unsigned char Ni, unsigned char T, unsigned char inv,int32_t parity) { 491 492 int32_t ret = 0; 493 493 unsigned char FiDi[4]; 494 u nsigned shortfreqk;494 uint16_t freqk; 495 495 unsigned char Freq[3]; 496 496 unsigned char N[2]; … … 519 519 // command 2, set the frequency in KHz 520 520 // direct from the source .. 4MHz is the best init frequency for T=0 card, but looks like it's causing issue with some nagra card, reveting to 3.69MHz 521 freqk = clock * 10; //clock with type int couldnt hold freq in Hz on all platforms, so I reverted to 10khz units (like mhz) - dingo521 freqk = clock * 10; //clock with type int32_t couldnt hold freq in Hz on all platforms, so I reverted to 10khz units (like mhz) - dingo 522 522 cs_debug_mask (D_DEVICE, "IO:SR: sending Freq=%04X (%d) to smartreader",freqk,freqk); 523 523 Freq[0]=0x02; … … 570 570 struct libusb_device_descriptor desc; 571 571 struct libusb_config_descriptor *configDesc; 572 int ret;573 int j,k,l;572 int32_t ret; 573 int32_t j,k,l; 574 574 uint8_t tmpEndpointAddress; 575 int nb_endpoint_ok;575 int32_t nb_endpoint_ok; 576 576 577 577 … … 605 605 static struct libusb_device* find_smartreader(const char *busname,const char *devname, uint8_t out_endpoint) 606 606 { 607 int dev_found;607 int32_t dev_found; 608 608 libusb_device *dev; 609 609 libusb_device_handle *usb_dev_handle; 610 610 libusb_device **devs; 611 611 ssize_t cnt; 612 int i = 0;613 int ret;612 int32_t i = 0; 613 int32_t ret; 614 614 struct libusb_device_descriptor desc; 615 615 … … 702 702 703 703 704 static u nsigned intsmartreader_determine_max_packet_size(S_READER *reader)705 { 706 u nsigned intpacket_size;704 static uint32_t smartreader_determine_max_packet_size(S_READER *reader) 705 { 706 uint32_t packet_size; 707 707 struct libusb_device_descriptor desc; 708 708 struct libusb_config_descriptor *configDesc; … … 710 710 struct libusb_interface_descriptor intDesc; 711 711 712 int ret;712 int32_t ret; 713 713 // Determine maximum packet size. Init with default value. 714 714 // New hi-speed devices from FTDI use a packet size of 512 bytes … … 750 750 751 751 752 static int smartreader_usb_close_internal (S_READER *reader)753 { 754 int ret = 0;752 static int32_t smartreader_usb_close_internal (S_READER *reader) 753 { 754 int32_t ret = 0; 755 755 756 756 if (reader->sr_config->usb_dev_handle) … … 764 764 765 765 766 int smartreader_usb_reset(S_READER *reader)766 int32_t smartreader_usb_reset(S_READER *reader) 767 767 { 768 768 if (libusb_control_transfer(reader->sr_config->usb_dev_handle, … … 783 783 784 784 785 int smartreader_usb_open_dev(S_READER *reader)786 { 787 int detach_errno = 0;785 int32_t smartreader_usb_open_dev(S_READER *reader) 786 { 787 int32_t detach_errno = 0; 788 788 struct libusb_device_descriptor desc; 789 int ret;789 int32_t ret; 790 790 791 791 #ifdef __WIN32__ 792 int config;793 int config_val = 1;792 int32_t config; 793 int32_t config_val = 1; 794 794 #endif 795 795 … … 931 931 932 932 933 int smartreader_usb_purge_rx_buffer(S_READER *reader)933 int32_t smartreader_usb_purge_rx_buffer(S_READER *reader) 934 934 { 935 935 if (libusb_control_transfer(reader->sr_config->usb_dev_handle, … … 949 949 } 950 950 951 int smartreader_usb_purge_tx_buffer(S_READER *reader)951 int32_t smartreader_usb_purge_tx_buffer(S_READER *reader) 952 952 { 953 953 if (libusb_control_transfer(reader->sr_config->usb_dev_handle, … … 966 966 } 967 967 968 int smartreader_usb_purge_buffers(S_READER *reader)969 { 970 int result;968 int32_t smartreader_usb_purge_buffers(S_READER *reader) 969 { 970 int32_t result; 971 971 972 972 result = smartreader_usb_purge_rx_buffer(reader); … … 981 981 } 982 982 983 static int smartreader_convert_baudrate(int baudrate, S_READER *reader, unsigned short *value, unsigned short*index)983 static int32_t smartreader_convert_baudrate(int32_t baudrate, S_READER *reader, uint16_t *value, uint16_t *index) 984 984 { 985 985 static const char am_adjust_up[8] = {0, 0, 0, 1, 0, 3, 2, 1}; 986 986 static const char am_adjust_dn[8] = {0, 0, 0, 1, 0, 1, 2, 3}; 987 987 static const char frac_code[8] = {0, 3, 2, 4, 1, 5, 6, 7}; 988 int divisor, best_divisor, best_baud, best_baud_diff;989 u nsigned longencoded_divisor;990 int i;988 int32_t divisor, best_divisor, best_baud, best_baud_diff; 989 uint32_t encoded_divisor; 990 int32_t i; 991 991 992 992 if (baudrate <= 0) … … 1010 1010 for (i = 0; i < 2; i++) 1011 1011 { 1012 int try_divisor = divisor + i;1013 int baud_estimate;1014 int baud_diff;1012 int32_t try_divisor = divisor + i; 1013 int32_t baud_estimate; 1014 int32_t baud_diff; 1015 1015 1016 1016 // Round up to supported divisor value … … 1087 1087 } 1088 1088 // Split into "value" and "index" values 1089 *value = (u nsigned short)(encoded_divisor & 0xFFFF);1089 *value = (uint16_t )(encoded_divisor & 0xFFFF); 1090 1090 if (reader->sr_config->type == TYPE_2232C || reader->sr_config->type == TYPE_2232H || reader->sr_config->type == TYPE_4232H) 1091 1091 { 1092 *index = (u nsigned short)(encoded_divisor >> 8);1092 *index = (uint16_t )(encoded_divisor >> 8); 1093 1093 *index &= 0xFF00; 1094 1094 *index |= reader->sr_config->index; 1095 1095 } 1096 1096 else 1097 *index = (u nsigned short)(encoded_divisor >> 16);1097 *index = (uint16_t )(encoded_divisor >> 16); 1098 1098 1099 1099 // Return the nearest baud rate … … 1101 1101 } 1102 1102 1103 int smartreader_set_baudrate(S_READER *reader, int baudrate)1104 { 1105 u nsigned shortvalue, index;1106 int actual_baudrate;1103 int32_t smartreader_set_baudrate(S_READER *reader, int32_t baudrate) 1104 { 1105 uint16_t value, index; 1106 int32_t actual_baudrate; 1107 1107 1108 1108 if (reader->sr_config->bitbang_enabled) … … 1142 1142 } 1143 1143 1144 int smartreader_setdtr_rts(S_READER *reader, int dtr, int rts)1145 { 1146 u nsigned shortusb_val;1144 int32_t smartreader_setdtr_rts(S_READER *reader, int32_t dtr, int32_t rts) 1145 { 1146 uint16_t usb_val; 1147 1147 1148 1148 if (dtr) … … 1171 1171 } 1172 1172 1173 int smartreader_setflowctrl(S_READER *reader, int flowctrl)1173 int32_t smartreader_setflowctrl(S_READER *reader, int32_t flowctrl) 1174 1174 { 1175 1175 if (libusb_control_transfer(reader->sr_config->usb_dev_handle, … … 1188 1188 } 1189 1189 1190 int smartreader_set_line_property2(S_READER *reader, enum smartreader_bits_type bits,1190 int32_t smartreader_set_line_property2(S_READER *reader, enum smartreader_bits_type bits, 1191 1191 enum smartreader_stopbits_type sbit, enum smartreader_parity_type parity, 1192 1192 enum smartreader_break_type break_type) 1193 1193 { 1194 u nsigned shortvalue = bits;1194 uint16_t value = bits; 1195 1195 1196 1196 switch (parity) … … 1252 1252 1253 1253 1254 int smartreader_set_line_property(S_READER *reader, enum smartreader_bits_type bits,1254 int32_t smartreader_set_line_property(S_READER *reader, enum smartreader_bits_type bits, 1255 1255 enum smartreader_stopbits_type sbit, enum smartreader_parity_type parity) 1256 1256 { … … 1269 1269 } 1270 1270 1271 static int smartreader_set_latency_timer(S_READER *reader, unsigned shortlatency)1272 { 1273 u nsigned shortusb_val;1271 static int32_t smartreader_set_latency_timer(S_READER *reader, uint16_t latency) 1272 { 1273 uint16_t usb_val; 1274 1274 1275 1275 if (latency < 1) { … … 1300 1300 #endif 1301 1301 struct s_reader *reader = (struct s_reader*)transfer->user_data; 1302 int copy_size;1303 int ret;1302 int32_t copy_size; 1303 int32_t ret; 1304 1304 1305 1305 if(transfer->status == LIBUSB_TRANSFER_COMPLETED) { … … 1320 1320 reader->sr_config->modem_status = transfer->buffer[0]; 1321 1321 1322 copy_size = sizeof(reader->sr_config->g_read_buffer) - reader->sr_config->g_read_buffer_size > (u nsigned int)transfer->actual_length-2 ? (unsigned int)transfer->actual_length-2: sizeof(reader->sr_config->g_read_buffer) - reader->sr_config->g_read_buffer_size;1322 copy_size = sizeof(reader->sr_config->g_read_buffer) - reader->sr_config->g_read_buffer_size > (uint32_t )transfer->actual_length-2 ? (uint32_t )transfer->actual_length-2: sizeof(reader->sr_config->g_read_buffer) - reader->sr_config->g_read_buffer_size; 1323 1323 memcpy(reader->sr_config->g_read_buffer+reader->sr_config->g_read_buffer_size,transfer->buffer+2,copy_size); 1324 1324 reader->sr_config->g_read_buffer_size += copy_size; … … 1351 1351 unsigned char usb_buffers[NUM_TXFERS][64]; 1352 1352 struct s_reader *reader; 1353 int ret,idx;1353 int32_t ret,idx; 1354 1354 1355 1355 reader = (struct s_reader *)p; … … 1393 1393 } 1394 1394 1395 static void smart_fastpoll(S_READER *reader, int on)1395 static void smart_fastpoll(S_READER *reader, int32_t on) 1396 1396 { 1397 1397 pthread_mutex_lock(&reader->sr_config->g_usb_mutex);
Note:
See TracChangeset
for help on using the changeset viewer.