]> hackdaworld.org Git - rfid/librfid.git/commitdiff
messing around with usb_*
authorhackbard <hackbard>
Sun, 26 Feb 2006 14:19:34 +0000 (14:19 +0000)
committerhackbard <hackbard>
Sun, 26 Feb 2006 14:19:34 +0000 (14:19 +0000)
gemtag/gemtag.c

index 9656f019614340014e29fde2c4ad931a744cb8f5..bca97eb916a568699199266f374cf96cbd49d162 100644 (file)
@@ -27,7 +27,6 @@
 int hexdump(unsigned char *data,int len) {
        int i;
 
-       printf("dump: ");
        for(i=0;i<len;i++) printf("%02x ",data[i]);
        printf("\n");
 
@@ -98,34 +97,36 @@ int gemtag_transcieve(struct gemtag_handle *gh,unsigned char cmd,
        memcpy(txbuf+size,tx,tx_len);
 
        /* crc check */
-       gh->capabilities=GEMTAG_CAP_CRC;
        if(gh->capabilities&GEMTAG_CAP_CRC) {
                size+=tx_len;
                crcptr=(u_int16_t *)(txbuf+size);
-               *crcptr=gemtag_calc_crc(txbuf,size);
+               *crcptr=htons(gemtag_calc_crc(txbuf,size));
                size+=2;
        }
 
        /* usb write */
+       printf("-> ");
        hexdump(txbuf,size);
+       usb_clear_halt(gh->handle,0x02);
        ret=usb_bulk_write(gh->handle,0x02,txbuf,size,0);
-       if(ret<0) {
+       if(ret<=0) {
                perror("usb bulk write");
                return ret;
        }
-       printf("write of %d bytes successfull\n",ret);
 
        /* usb read */
+       usb_clear_halt(gh->handle,0x81);
        ret=usb_bulk_read(gh->handle,0x81,rxbuf,sizeof(rxbuf),0);
        size=ret;
-       if(ret<0) {
+       if(ret<=0) {
                perror("usb bulk read");
                return ret;
        }
-       printf("received %d bytes\n",ret);
+       printf("-> ");
+       hexdump(rxbuf,ret);
        
        if(rxhdr->seq!=txhdr->seq)
-               puts("transmitted/recieved header are not equal");
+               puts("transmitted/recieved sequence number do not match");
 
        /* crc check */
        
@@ -144,6 +145,7 @@ struct gemtag_handle *gemtag_open(void) {
        unsigned int rlen;
        unsigned int i,numconf;
        unsigned int j,numint;
+       unsigned int k,numalt;
        struct gemtag_handle *gh;
 
        rlen=sizeof(rbuf);
@@ -161,15 +163,22 @@ struct gemtag_handle *gemtag_open(void) {
        memset(gh,0,sizeof(struct gemtag_handle));
 
        numconf=gemtag->descriptor.bNumConfigurations;
-       printf("found gemtag, %u configuration(s)\n",numconf);
+       printf("found gemtag (%02x/%02x), %u configuration(s)\n",
+              gemtag->descriptor.idVendor,
+              gemtag->descriptor.idProduct,numconf);
        for(i=0;i<numconf;i++) {
                numint=gemtag->config[i].bNumInterfaces;
-               printf("config %u [nr %u] has %u interface(s)\n",
+               printf("  config %u [nr %u] has %u interface(s)\n",
                       i,gemtag->config[i].bConfigurationValue,
                       numint);
                for(j=0;j<numint;j++) {
-                       printf("config %u interface %u has %u altsetting(s)\n",
-                              i,j,gemtag->config[i].interface[j].num_altsetting);
+                       numalt=gemtag->config[i].interface[j].num_altsetting;
+                       printf("    interface %u has %u altsetting(s): ",
+                              j,numalt);
+                       for(k=0;k<numalt;k++)
+                               printf("%u ",
+               gemtag->config[i].interface[j].altsetting[k].bAlternateSetting);
+                       printf("\n");
                }
        }
 
@@ -190,16 +199,14 @@ struct gemtag_handle *gemtag_open(void) {
        }
        puts("interface 0 claimed");
 
-/*     if(usb_set_altinterface(gh->handle,1)) {
-               perror("set alt interface");
-               goto out_free;
-       }
-       puts("alt setting 1 selected");
-*/
+       while(usb_set_altinterface(gh->handle,0))
+               printf("trying to set alt interface\n");
+       puts("alt setting 0 selected");
 
        gh->capabilities|=GEMTAG_CAP_CRC;
 
-       gemtag_transcieve(gh,0x22,NULL,0,rbuf,&rlen);
+       gemtag_transcieve(gh,GEMTAG_CMD_GET_FW_VERSION,
+                         NULL,0,rbuf,&rlen);
 
        return gh;