[libhid-discuss] cannat find path to read and write

sajjad gerami myworkmail2010 at gmail.com
Wed Sep 2 08:16:35 UTC 2009


On Tue, Sep 1, 2009 at 3:53 AM, Charles Lepple <clepple at ghz.cc> wrote:

>
> On Aug 31, 2009, at 1:22 AM, sajjad gerami wrote:
>
>  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!!!!!
>>
>
> What does 'lsusb' say?
>
> Also, please provide some basic information about your setup:
>
> * 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>


More information about the libhid-discuss mailing list