From 411df5ce4ca6463f0af32659d397c91554d73271 Mon Sep 17 00:00:00 2001 From: hackbard Date: Sun, 26 Feb 2006 14:19:34 +0000 Subject: [PATCH] messing around with usb_* --- gemtag/gemtag.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/gemtag/gemtag.c b/gemtag/gemtag.c index 9656f01..bca97eb 100644 --- a/gemtag/gemtag.c +++ b/gemtag/gemtag.c @@ -27,7 +27,6 @@ int hexdump(unsigned char *data,int len) { int i; - printf("dump: "); for(i=0;icapabilities=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;iconfig[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;jconfig[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;kconfig[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; -- 2.20.1