Esempio n. 1
0
/* Comment    : Must be called before any other devi_hid... function                */
void devi_unregister_usb_client(void * h)
{
   int rc;
   pModule_data_t pModule = (pModule_data_t)h;
   struct timespec t;
   
   assert(pModule);

   
   if(pModule -> ep_int)
     {
     usbd_reset_pipe(pModule -> ep_int);
     usbd_abort_pipe(pModule -> ep_int);
     }

   if(pModule -> ep_cntl)
     usbd_abort_pipe(pModule -> ep_cntl);

   if(pModule -> urb)
     usbd_free_urb(pModule -> urb);
   
   if(pModule -> ep_int_buf)
     usbd_free(pModule -> ep_int_buf);
   
   if(pModule -> ep_cnt_buf)
     usbd_free(pModule -> ep_cnt_buf);

   sleep(1);
   
   if(EOK != (rc = usbd_detach(pModule -> pDevice)))
     {
     if(verbosity)
	fprintf(stderr, "Detach device: error %i\n", rc);
     }
   
   clock_gettime(CLOCK_REALTIME, &t);
   t.tv_sec += MAX_TIME_WAIT;
   if(EOK !=  pthread_mutex_timedlock(&mod_mutex, &t))
      return ;
   
   LIST_REMOVE(pModule, lst_conn);
  
   pthread_mutex_unlock(&mod_mutex);

   free(pModule);

}
Esempio n. 2
0
void usbd_list_free(usbd *s) {
    usbd *n;
    while(s != NULL) {
        n = s->next;
        usbd_free(s);
        s = n;
    }
}
Esempio n. 3
0
usbd *usb_get_device(int bus, int dev) {
    usbd *s = usbd_new();
    int ok = 0;
    if (s) {
        /* try lsusb */
        ok = usb_get_device_lsusb(bus, dev, s);

        /* TODO: other methods */

        if (!ok) {
            usbd_free(s);
            s = NULL;
        }
    }
    return s;
}
Esempio n. 4
0
/* Return     : None                                                                */
void removal( struct usbd_connection * pConnection, usbd_device_instance_t * pInstance )
{
   struct usbd_device	* pDevice;
   pModule_data_t pModule;
   int rc;

   if(NULL != ( pDevice = usbd_device_lookup( pConnection, pInstance )))
      {
      pModule = usbd_device_extra( pDevice );
      if( pModule -> ep_int ) 
	   {						// Stop the Interrupt In endpoint
	   usbd_abort_pipe( pModule -> ep_int );        // Abort pipe
	   usbd_free_urb( pModule -> urb );             // Free request block
	   usbd_free( pModule -> ep_int_buf );
	   if( rc = usbd_detach( pModule -> pDevice ) ) 
		fprintf( stderr, "usbd_detach %i\n", rc );
	   }
      }
}
Esempio n. 5
0
/* Return     : None                                                                */
void insertion( struct usbd_connection *pConnection, usbd_device_instance_t *pInstance )
{
   int rc;
   struct usbd_device * pDevice;
   pModule_data_t pModule, * ppModule;
   
   if(verbosity)
     printf("Try to inser device\n");
   if( EOK != (rc = usbd_attach( pConnection, pInstance, sizeof(module_data_t **), &pDevice ) ))
     {
     char * pMsgTxt = "Error: cannot attach USB device #%i (error code is %i)\n";
     fprintf(stderr, pMsgTxt, (int)(pInstance -> devno), rc);
     slogf(_SLOG_SETCODE(_SLOGC_INPUT, 0), _SLOG_ERROR, pMsgTxt, (int)(pInstance -> devno), rc);
     return;
     }
   ppModule = (pModule_data_t *)usbd_device_extra(pDevice);
	
	
   // Try to find if somebody cares about keyboard reports
   for(pModule = LIST_FIRST_ITEM(&modList); NULL != pModule; pModule = LIST_NEXT_ITEM(pModule, lst_conn))
        {
	// Check device number if specified
        if( (USBD_CONNECT_WILDCARD != pModule -> nDev) && (pModule -> nDev != pInstance -> devno))
	     continue;

        if( (USBD_CONNECT_WILDCARD != pModule -> nVendor) && (pModule -> nVendor != pInstance -> ident.vendor))
             continue; // Wrong vendor - ignore
	   
        if((USBD_CONNECT_WILDCARD != pModule -> nClass) && (pModule -> nClass != pInstance -> ident.dclass))
             continue;
   
        if((USBD_CONNECT_WILDCARD != pModule -> nSubClass) && (pModule -> nSubClass != pInstance -> ident.subclass))
             continue;

	pModule -> pInstance = pInstance;
	pModule -> pDevice   = pDevice;
        if( EOK == parse_descriptors( pModule) )
	   {
	   if( pModule -> ep_int_buf = usbd_alloc( pModule -> ep_int_size ) )
	      {
	      if( pModule -> urb = usbd_alloc_urb( NULL ) )
		 {
		 // Initialize request block
		 usbd_setup_interrupt( pModule -> urb,  
				      URB_DIR_IN, 
				      pModule -> ep_int_buf, 
				      pModule->ep_int_size );
		 // Initialize Interrupt callback function
		 if( EOK == usbd_io( pModule -> urb, 
				   pModule -> ep_int, 
				   usb_dev_int, 
				   pModule, USBD_TIME_INFINITY ) ) 
		      {
		      pModule -> flags |= USB_DEVICE_ON |  USB_DEVICE_PRESENT;
		      *ppModule = pModule;
                      if(verbosity)
                         printf("Attach device\n");
		      return;
		      }
		 else
		      {
                      if(verbosity)
                         printf("Cannot attach device\n");
		      }
		 }
               usbd_free( pModule -> ep_int_buf );
	       }
	   usbd_detach( pDevice );
	   }
         }
}