Discussion:
[libhid-discuss] cannat find path to read and write
sajjad gerami
2009-08-31 05:22:25 UTC
Permalink
hi

i have problem with finding path to read and write with libhid
my device parsing :

path: 0xff000001.0xff000001; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0xff000001; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0

no 0x80 exist!!!!!
i used 0xff000001.0xff000001 as a path with lenght=2
that works for writing (no ERROR) but i cant read any way with
0xff000001.0xff000001
or 0xff000001.0x00000000

i don't know how to find the path

thanks for helping in advance

feel good

------------------------------------------------------------------------------------------------------
my code :::::

/*-----------------------------writing-----------------------------*/
//writing to device


unsigned char const PATHLEN = 2;
int PATH_OUT[PATHLEN];// = { 0xff000001, 0xff000001,
0xff000001,0xff000001,0xff000001,0xff000001 };
PATH_OUT[0]= 0xff000001;
PATH_OUT[1]= 0xff000001;


unsigned char const SEND_PACKET_LENGHT=8;
char PACKET[SEND_PACKET_LENGHT];//={0x0,0x1,0x2,0x6};
PACKET[0]=0x0;
PACKET[1]=0x9;
PACKET[2]=0x2;
PACKET[3]=0x3;
PACKET[4]=0x4;
PACKET[5]=0x5;
PACKET[6]=0x6;
PACKET[7]=0x7;

hid_return write_ret;
// write_ret=hid_set_output_report(hid,PATH_OUT,PATHLEN,PACKET,SEND_PACKET_LENGHT);
if(write_ret!=HID_RET_SUCCESS)
printf("***Writing failed_____----___--___-__-_\n");
else
printf("***Writing successfuly DONE_____----___--___-__-_\n");
/*
path: 0xff000001.0xff000001; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0xff000001; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
*/

/*-----------------------------Reading-----------------------------*/

int PATH_IN[PATHLEN];
PATH_IN[0]=0xff000001;
PATH_IN[1]=0xff000001;

int recive_packet_len=8;
char Recive_packet[recive_packet_len];
//ret = hid_get_input_report(hid, PATH_OUT, PATHLEN, Recive_packet,
recive_packet_len);
int i;
printf("\n------------------recived data-----------------\n");
for (i=0; i<recive_packet_len ; i++)
printf("%hx\n",Recive_packet[i]);

printf("\n------------------END of recived data-----------------\n");


/*-----------------------------END Reading-----------------------------*/
Charles Lepple
2009-08-31 23:23:46 UTC
Permalink
Post by sajjad gerami
i have problem with finding path to read and write with libhid
path: 0xff000001.0xff000001; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0xff000001; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
no 0x80 exist!!!!!
What does 'lsusb' say?

Also, please provide some basic information about your setup:

* OS
* Distribution (if Linux)
* version of libhid
sajjad gerami
2009-09-02 08:16:35 UTC
Permalink
Post by sajjad gerami
i have problem with finding path to read and write with libhid
Post by sajjad gerami
path: 0xff000001.0xff000001; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0x00000000; type: 0x90
path: 0xff000001.0xff000001; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
path: 0xff000001.0x00000000; type: 0xb0
no 0x80 exist!!!!!
What does 'lsusb' say?
* OS
* Distribution (if Linux)
* version of libhid
hi
absolutly

lsusb result :

root at sajjad-laptop:/media/laptop-bullshit# lsusb -d 0x1114:0x1028 -vvv

Bus 003 Device 002: ID 1114:1028
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x1114
idProduct 0x1028
bcdDevice 1.00
iManufacturer 1 IBECo
iProduct 2 Safe Hardware Lock
iSerial 3 IBECo525085
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 34
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 20mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.01
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 40
Report Descriptor: (length is 40)
Item(Global): Usage Page, data= [ 0x00 0xff ] 65280
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Main ): Collection, data= [ 0x01 ] 1
Application
Item(Global): Report ID, data= [ 0x01 ] 1
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x07 ] 7
Item(Main ): Output, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile
Bitfield
Item(Global): Report ID, data= [ 0x02 ] 2
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x07 ] 7
Item(Main ): Feature, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile
Bitfield
Item(Main ): End Collection, data=none
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 100
Device Status: 0x0000
(Bus Powered)

/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\

I use ubuntu 9.04 kernel 2.6.28-13-generic
ubuntu Synaptic package manager say my libhid version is
0.2.15+20060325.2ubuntu1
but i think i've compiled 2.16 version
(do they deffers lot?)

is it possible that both input and output path of that device be equal?
path: 0xff000001.0xff000001; type: 0x90
path: 0xff000001.0xff000001; type: 0xb0

i thinks this should be 0x80 for output

i'm really confused about this pathes

i'm interested about finding the path from lsusb -v result
Item(Global): Usage Page, data= [ 0x00 0xff ] 65280
...
Item(Local ): Usage, data= [ 0x01 ] 1
0xff00+0001


/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\


here is my whole testing code :

/*
* File: main.c
* Author: sajjad
*
* Created on August 30, 2009, 2:07 PM
*/

#include <stdio.h>
#include <stdlib.h>
#include <hid.h>

#define _debug__ 0

int main(int argc, char** argv)

{
printf("\n------******* program started *******--------\n");

/*
typedef struct HIDInterface_t {
struct usb_dev_handle *dev_handle;
struct usb_device *device;
int interface;
char id[32];
HIDData* hid_data;
HIDParser* hid_parser;
} HIDInterface;
*/

HIDInterface* safe1_hid ;
hid_return safe1_return;
//char const* const serial="IBECo525055";//IBECo524229
HIDInterfaceMatcher safeMatcher={0x1114 , 0x1028 , NULL ,NULL , 0};
//HIDInterfaceMatcher safeMatcher={0x16c0 , 0x05df , NULL ,NULL , 0};

//enabling debuging
#if _debug__
hid_set_debug(HID_DEBUG_ALL);
hid_set_debug_stream(stderr);
hid_set_usb_debug(0);/* passed directly to libusb */
#endif

//initiazization don't work!!!!
safe1_return = hid_init();
#if _debug__
if (safe1_return!=HID_RET_SUCCESS)
printf("ERROR : Initialize libhid: scan for USB busses and devices
using libusb.\n");
else
printf("SUCCESS : Initialize libhid: scan for USB busses and devices
using libusb.\n");
#endif
safe1_hid=hid_new_HIDInterface();
#if _debug__
if(safe1_hid==0)
printf("ERROR : your out of memory hid_new_HIDInterface()
faild!!\n");
else
printf("SUCCESS : hid_new_HIDInterface() \n");
#endif
//opennig devices

//safe1_return=hid_open(safe1_hid,0,&safeMatcher);
safe1_return=hid_force_open(safe1_hid,0,&safeMatcher,3);
if(safe1_return!=HID_RET_SUCCESS)
printf("ERROR : hid_open failed!!!\n");
else
printf("SUCCESS : hid_open SUCCESSFULY!!!\n");
//opennig devices DONE

printf("************\nVIP=%hx PID=%hx
\n************\n",safeMatcher.vendor_id,safeMatcher.product_id);

/*
//opennig tiny
HIDInterfaceMatcher tiny = { 0x16c0 , 0x05df ,NULL,NULL , 0};
HIDInterface* hid4tiny;
hid_return tinyReturn;

tinyReturn = hid_force_open(hid4tiny, 0, &tiny, 3);

if (tinyReturn != HID_RET_SUCCESS) {
printf("ERROR : Openning tiny failed!!!!\n");
// return 1;
}

printf("\n************\nVIP=%hx \nPID=%hx
\n************\n",tiny.vendor_id,tiny.product_id);
*/

//device identification of HIDInterface
safe1_return = hid_write_identification(stdout, safe1_hid);
#if _debug__
if (safe1_return != HID_RET_SUCCESS)
printf("ERROR : hid_write_identification failed with return code
%d\n", safe1_return);
else
printf("SUCCESS : hid_write_identification \n");
#endif
//dumping hid tree
#if _debug__
safe1_return=hid_dump_tree(stdout,safe1_hid);

if (safe1_return!=HID_RET_SUCCESS)
printf("ERROR : Dump_tree failed!!!!\n");
else
printf("SUCCESS : hid_dump_tree \n");
#endif

//*******************************************************************
//*******************************************************************
//*******************************************************************

//------------------ Writing to device --------------------------------
unsigned int const PATHLEN = 2;
int PATH_OUT[PATHLEN];
PATH_OUT[0]=0xff000001;
PATH_OUT[1]=0xff000001;


unsigned int const SEND_PACKET_LENGHT=8;
char PACKET[SEND_PACKET_LENGHT];
PACKET[0]=0x0;PACKET[1]=0x10;PACKET[2]=0x2;PACKET[3]=0x3;
PACKET[4]=0x1;PACKET[5]=0x12;PACKET[6]=0x3;PACKET[7]=0x7;
int timeout = 1000; // milliseconds

safe1_return =
hid_set_output_report(safe1_hid,PATH_OUT,PATHLEN,PACKET,SEND_PACKET_LENGHT);
//safe1_return = hid_set_feature_report(safe1_hid , PATH_OUT , PATHLEN ,
PACKET ,SEND_PACKET_LENGHT);
//safe1_return = hid_interrupt_write(safe1_hid , 0x02 , PACKET , 8 ,
timeout);

if(safe1_return!=HID_RET_SUCCESS)
printf("ERROR : Writing failed !!!\n");
else
{
printf("SUCCESS : Writing successfuly DONE\n");
int i;
printf("writed packet : \n***********************\n");
for (i=0 ; i<SEND_PACKET_LENGHT ; i++)
printf("%hx ",PACKET[i]);
printf("\n");
}

//--------------- reading from device --------------------

int PATH_IN[PATHLEN];
PATH_IN[0] = 0xff000001 ;
PATH_IN[1] = 0xff000001 ;
//printf("---------%lx------\n",sizeof(PATH_IN)); !!!!!!!!!!!!!!

char recived_packet[8];
unsigned int RECIVE_PACKET_LENGHT=8;

safe1_return = hid_get_feature_report(safe1_hid,PATH_IN , PATHLEN ,
recived_packet , RECIVE_PACKET_LENGHT);
//safe1_return = hid_get_input_report(safe1_hid,PATH_IN
,PATHLEN,recived_packet,RECIVE_PACKET_LENGHT);
//!!!//safe1_return = hid_interrupt_read(safe1_hid , 0x02 ,
recived_packet , RECIVE_PACKET_LENGHT , timeout);
if (safe1_return!=HID_RET_SUCCESS)
printf("ERROR : hid_interrupt_read failed !!!!\n");
else
{
int i=0;
printf("SUCCESS : hid_interrupt_read \n***********************\n");
for (i=0 ; i < RECIVE_PACKET_LENGHT ; i++)
printf("%hx ",recived_packet[i]);
printf("\n");
}


//*******************************************************************
//*******************************************************************
//*******************************************************************
//---------- end of program -------------

//closing hid interface
safe1_return=hid_close(safe1_hid);
#if _debug__
if(safe1_return!=HID_RET_SUCCESS)
printf("ERROR : hid_close failed!!!\n");
else
printf("SUCCESS : hid_close \n");
#endif
//delete interface
hid_delete_HIDInterface(&safe1_hid);

//cleaning up - release allocated memory
safe1_return=hid_cleanup();
#if _debug__
if (safe1_return!=HID_RET_SUCCESS)
printf("ERROR : hid_cleanup() failed !!!\n");
else
printf("SUCCESS : hid_cleanup \n");
#endif
return (EXIT_SUCCESS);
}


/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\

maybe i've founded the right path but my writing and reading part has
problem !!???!!!

anything is possible

thanks for your help
god bless you.

//sajjadG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20090902/fc22c2aa/attachment-0001.htm>
Charles Lepple
2009-09-05 13:48:31 UTC
Permalink
Please send libhid-related questions to the mailing list. The list is
CC'd.
hi
another problem .
i try to enumerate my usb devices but i encouterd a problem
--------------------------------------------
#include <hid.h>
#include <stdio.h>
#include <string.h>
char *hid_id[32]; /* FIXME: 32 devices MAX */
struct usb_dev_handle;
bool device_iterator (struct usb_dev_handle const* usbdev, void*
custom,
unsigned int len)
{
bool ret = false;
int i;
char current_dev_path[10];
const struct usb_device *device = usb_device((struct usb_dev_handle
*)usbdev);
/* only here to prevent the unused warning */
/* TODO remove */
len = *((unsigned long*)custom);
/* Obtain the device's full path */
//sprintf(current_dev_path, "%s/%s", usbdev->bus->dirname,
usbdev->device->filename);
sprintf(current_dev_path, "%s/%s", device->bus->dirname,
device->filename);
/* Check if we already saw this dev */
for ( i = 0 ; ( hid_id[i] != NULL ) ; i++ )
{
if (!strcmp(hid_id[i], current_dev_path ) )
break;
}
/* Append device to the list if needed */
if (hid_id[i] == NULL)
{
hid_id[i] = (char *) malloc (strlen(device->filename) +
strlen(device->bus->dirname) );
sprintf(hid_id[i], "%s/%s", device->bus->dirname, device-
filename);
}
else /* device already seen */
{
return false;
}
/* Filter non HID device */
if ( (device->descriptor.bDeviceClass == 0) /* Class defined at
interface level */
&& device->config
&& device->config->interface->altsetting->bInterfaceClass ==
USB_CLASS_HID)
ret = true;
else
ret = false;
return ret;
}
int main(void)
{
int i;
hid_return ret;
HIDInterface* hid;
HIDInterfaceMatcher matcher;
/* hid_write_library_config(stdout); */
/* hid_set_debug(HID_DEBUG_NOTRACES); */
// hid_set_debug(HID_DEBUG_NONE);
hid_set_debug(HID_DEBUG_ALL);
hid_set_debug_stream(stderr);
hid_set_usb_debug(0);
/* data init */
for (i = 0 ; i < 32 ; i++)
hid_id[i] = NULL;
ret = hid_init();
hid = hid_new_HIDInterface();
/* //tested - not working
matcher.vendor_id = HID_ID_MATCH_ANY;
matcher.product_id = HID_ID_MATCH_ANY;
matcher.matcher_fn = device_iterator;
*/
matcher.vendor_id = 0x1114;
matcher.product_id = 0x1028;
matcher.matcher_fn = device_iterator;
// matcher.matcher_fn = NULL; //WARNNING : infinity loop
/* open recursively all HID devices found */
while ( (ret = hid_force_open(hid, 0, &matcher, 3)) !=
HID_RET_DEVICE_NOT_FOUND)//Segmentation fault accures here!!!
{
printf
("************************************************************************\n
");
hid_write_identification(stdout, hid);
/* Only dump HID tree if asked */
/* hid_dump_tree(stdout, hid); */
hid_close(hid);
}
hid_delete_HIDInterface(&hid);
ret = hid_cleanup();
return 0;
}
/* COPYRIGHT --
*
* This file is part of libhid, a user-space HID access library.
* libhid is (c) 2003-2005
* Martin F. Krafft <libhid at pobox.madduck.net>
* Charles Lepple <clepple at ghz.cc>
* Arnaud Quette <arnaud.quette at free.fr> &&
<arnaud.quette at mgeups.com>
* and distributed under the terms of the GNU General Public License.
* See the file ./COPYING in the source distribution for more
information.
*
* THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
* OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
--------------------------------------------
root at sajjad-laptop:/home/sajjad/NetBeansProjects/libhid1/dist/Debug/
GNU-Linux-x86# ./libhid1
NOTICE: hid_init(): libhid 0.2.15+20060325.0.0 is being initialized.
TRACE: hid_init(): initialising USB subsystem...
TRACE: hid_init(): scanning for USB busses...
TRACE: hid_init(): scanning for USB devices...
NOTICE: hid_init(): successfully initialised HID library.
TRACE: hid_new_HIDInterface(): creating a new HIDInterface
instance...
TRACE: hid_force_open(): forcefully opening a device interface
according to matching criteria...
TRACE: hid_get_usb_handle(): acquiring handle for a USB device...
TRACE: hid_find_usb_device(): enumerating USB busses...
TRACE: hid_find_usb_device(): enumerating USB devices on bus 001...
TRACE: hid_find_usb_device(): inspecting USB device 001/001[0]...
TRACE: hid_compare_usb_device(): comparing match specifications to
USB
device...
TRACE: hid_compare_usb_device(): inspecting vendor ID...
TRACE: hid_compare_usb_device(): no match on vendor ID.
TRACE: hid_compare_usb_device(): inspecting product ID...
TRACE: hid_compare_usb_device(): no match on product ID.
TRACE: hid_compare_usb_device(): calling custom matching function...
Segmentation fault
root at sajjad-laptop:/home/sajjad/NetBeansProjects/libhid1/dist/Debug/
GNU-Linux-x86#
--------------------------------------------
Segmentation fault ????!!!??!?!?!?!?
A debugger is very helpful if you get a segmentation fault.
and when i changed
matcher.matcher_fn = device_iterator;
to
matcher.matcher_fn = NULL;
it fall in the loop and check the same 1st find matching bus again and
again.
custom matching function !!!!????
what is this ?
i search in libhid documentation but i found nothing
even in libhid codes again nothing
then discuss list , nothing relative
Look again.
thanks for helping.
god bless you.
--
Sajjad Gerami <myworkmail2010 at gmail.com>
Loading...