Пример #1
0
usb_driver_t *usb_find_driver(usbdev_t *dev)
{
    usb_device_descr_t *devdescr;
    usb_interface_descr_t *ifdescr;
    usb_drvlist_t *list;
    int dclass,vendor,product;

    devdescr = &(dev->ud_devdescr);

    dclass = devdescr->bDeviceClass;
    if (dclass == 0) {
	ifdescr = usb_find_cfg_descr(dev,USB_INTERFACE_DESCRIPTOR_TYPE,0);
	if (ifdescr) dclass = ifdescr->bInterfaceClass;
	}

    vendor = (int) GETUSBFIELD(devdescr,idVendor);
    product = (int) GETUSBFIELD(devdescr,idProduct);

    printf("USB: Locating Class %02X Vendor %04X Product %04X: ",dclass,vendor,product);

    list = usb_drivers;
    while (list->udl_disp) {
	if (((list->udl_class == dclass) || (list->udl_class == CLASS_ANY)) &&
	    ((list->udl_vendor == vendor) || (list->udl_vendor == VENDOR_ANY)) &&
	    ((list->udl_product == product) || (list->udl_product == PRODUCT_ANY))) {
	    printf("%s\n",list->udl_disp->udrv_name);
	    return list->udl_disp;
	    }
	list++;
	}

    printf("Not found.\n");

    return NULL;
}
Пример #2
0
static int usbhub_attach(usbdev_t *dev,usb_driver_t *drv)
{
    usb_device_status_t devstatus;
    usb_config_descr_t *cfgdscr;
    usb_interface_descr_t *ifdscr;
    usb_endpoint_descr_t *epdscr;
    usbhub_softc_t *softc;
    
    /*
     * Remember the driver dispatch.
     */

    dev->ud_drv = drv;

    softc = KMALLOC(sizeof(usbhub_softc_t),0);
    memset(softc,0,sizeof(usbhub_softc_t));
    softc->uhub_imsg = NULL;
    dev->ud_private = softc;

    /*
     * Dig out the data from the configuration descriptor
     * (we got this from the device before attach time)
     */

    cfgdscr = dev->ud_cfgdescr;
    epdscr = usb_find_cfg_descr(dev,USB_ENDPOINT_DESCRIPTOR_TYPE,0);
    ifdscr = usb_find_cfg_descr(dev,USB_INTERFACE_DESCRIPTOR_TYPE,0);

    /*
     * Get device status (is this really necessary?)
     */

    usb_get_device_status(dev,&devstatus);

    /*
     * Set us to configuration index 0
     */

    usb_set_configuration(dev,cfgdscr->bConfigurationValue);

    /*
     * Get the hub descriptor.
     */

    usbhub_get_hub_descriptor(dev,&softc->uhub_descr,0,sizeof(usb_hub_descr_t));

    /*	
     * remember stuff from the hub descriptor
     */

    softc->uhub_nports = softc->uhub_descr.bNumberOfPorts;

    /*
     * Open the interrupt pipe
     */

    softc->uhub_ipipemps = GETUSBFIELD(epdscr,wMaxPacketSize);
    softc->uhub_imsg = usb_dma_alloc(softc->uhub_ipipemps);
    softc->uhub_ipipe = usb_open_pipe(dev,epdscr);

    /*
     * Mark the bus and the hub as needing service.
     */

    softc->uhub_flags |= UHUB_FLG_NEEDSCAN;
    dev->ud_bus->ub_flags |= UB_FLG_NEEDSCAN;

    /*
     * Okay, that's it.  The top-level USB daemon will notice
     * that the bus needs service and will invoke the exploration code.
     * This may in turn require additional explores until
     * everything settles down.
     */

    return 0;
}
Пример #3
0
static int rtek_attach(usbdev_t *dev, usb_driver_t *drv)
{
    usb_config_descr_t *cfgdscr = dev->ud_cfgdescr;
    usb_endpoint_descr_t *epdscr;
    usb_endpoint_descr_t *indscr = NULL;
    usb_endpoint_descr_t *outdscr = NULL;
    usb_interface_descr_t *ifdscr;
    rtek_softc_t *softc;
    int idx;

    dev->ud_drv = drv;

    softc = (rtek_softc_t *) KMALLOC( sizeof(rtek_softc_t), 0 );
    if( softc == NULL )	{
	xprintf( "Failed to allocate softc memory.\n" );
	return -1;
	}
    memset( softc, 0, sizeof(rtek_softc_t) );
    dev->ud_private = softc;
    softc->dev = dev;

    ifdscr = usb_find_cfg_descr(dev,USB_INTERFACE_DESCRIPTOR_TYPE,0);
    if (ifdscr == NULL) {
	xprintf("USBETH: ERROR...no interace descriptor\n");
	return -1;
	}

    for (idx = 0; idx < 2; idx++) {
	epdscr = usb_find_cfg_descr(dev,USB_ENDPOINT_DESCRIPTOR_TYPE,idx);
	if (USB_ENDPOINT_DIR_OUT(epdscr->bEndpointAddress))
	    outdscr = epdscr;
	else
	    indscr = epdscr;
	}

    if (!indscr || !outdscr) {
	/*
	 * Could not get descriptors, something is very wrong.
	 * Leave device addressed but not configured.
	 */
	xprintf("USBETH: ERROR...no endpoint descriptors\n");
	return -1;
	}

    /* Choose the standard configuration. */
    usb_set_configuration(dev,cfgdscr->bConfigurationValue);

    /* Quit if not able to initialize the device */
    if (rtek_init_device(softc) < 0)
	return -1;

    /* Open the pipes. */
    softc->bulk_inpipe     = usb_open_pipe(dev,indscr);
    softc->bulk_outpipe    = usb_open_pipe(dev,outdscr);

    /* Register the device */
    usbeth_register(&usbeth_rtek,softc);

    /* Open the device */
    rtek_open_device( softc );

    return 0;
}
Пример #4
0
static int usbctrl_attach(usbdev_t *dev,usb_driver_t *drv)
{
	usb_config_descr_t *cfgdscr = dev->ud_cfgdescr;
	//printf("Number of interfaces: %i\n", cfgdscr->bNumInterfaces);



	dev->ud_drv = drv;

	usbctrl_softc_t *softc;

	



	//printf("Number of endpoints: %i\n", ifdscr->bNumEndpoints);

	usb_endpoint_descr_t *epdscr;
	usb_interface_descr_t *ifdscr;

	int wireless = (GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x291) || 
			(GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x2aa) ||
			(GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x2a9);

	if(wireless)
	{

		dev->ud_private = NULL;


		int i;
		for(i = 0; i < 4; i++)
		{
			softc = KMALLOC(sizeof(usbctrl_softc_t),0);
			softc->dev = dev;
			softc->is_wireless = (wireless);
			epdscr = usb_find_cfg_descr(dev,USB_ENDPOINT_DESCRIPTOR_TYPE,i * 4);
			ifdscr = usb_find_cfg_descr(dev,USB_INTERFACE_DESCRIPTOR_TYPE,i * 2);

			if (!epdscr || !ifdscr) {
				printf("couldn't find descriptor for controller %i!\n", i);
				return 0;
			}
		

			//printf("Initializing wireless controller %d\n", i);
			softc->index = -1;
			softc->wireless_index = i;
			//controller_mask |= 1<<i; //Dont set this right now, let wired controllers use the slots

			/*
			 * Allocate a DMA buffer
			 */

			softc->uhid_imsg = usb_dma_alloc(UBR_KBD_MAX);
			if (softc->uhid_imsg == NULL) {
				printf("couldn't alloc buffer\n");
				/* Could not allocate a buffer, fail. */
				return -1;
			}
	
			/*
			 * Choose the standard configuration.
	 		*/

			usb_set_configuration(dev,cfgdscr->bConfigurationValue);

			/*
	 		* Open the interrupt pipe.
	 		*/

			softc->uhid_ipipe = usb_open_pipe(dev,epdscr);
			
			usb_endpoint_descr_t *txdscr = usb_find_cfg_descr(dev, USB_ENDPOINT_DESCRIPTOR_TYPE, (i * 4) + 1);
			//if (USB_ENDPOINT_DIR_OUT(txdscr->bEndpointAddress))
			//	printf("Opened an outgoing endpoint\n");

			softc->uhid_ipipe_tx = usb_open_pipe(dev, txdscr);

			

			softc->uhid_ipipemps = GETUSBFIELD(epdscr,wMaxPacketSize);
			softc->uhid_ipipemps_tx = GETUSBFIELD(epdscr,wMaxPacketSize);

			usbctrl_set_leds(softc, 1); //Clear leds, FIXME: Implement controller shutdown somewhere
			usbctrl_poll(softc);

			/*
			 * Queue a transfer on the interrupt endpoint to catch
			 * our first characters.
	 		*/

			usbctrl_queue_intreq(dev,softc);

			

		}


	}
	else
	{

	softc = KMALLOC(sizeof(usbctrl_softc_t),0);
	memset(softc,0,sizeof(usbctrl_softc_t));
	softc->dev = dev;
	dev->ud_private = softc;

	softc->is_wireless = (wireless);

	epdscr = usb_find_cfg_descr(dev,USB_ENDPOINT_DESCRIPTOR_TYPE,0);
	ifdscr = usb_find_cfg_descr(dev,USB_INTERFACE_DESCRIPTOR_TYPE,0);

	usb_endpoint_descr_t *txdscr = usb_find_cfg_descr(dev, USB_ENDPOINT_DESCRIPTOR_TYPE,1);

	
	//if (USB_ENDPOINT_DIR_OUT(txdscr->bEndpointAddress))
	//	printf("Opened an outgoing endpoint\n");

	softc->uhid_ipipe_tx = usb_open_pipe(dev, txdscr);

	if (!epdscr || !ifdscr) {
		printf("couldn't find descriptor!\n");
		return 0;
	}
	

	
	int i;
	for (i = 0; controller_mask & (1<<i); ++i);
	printf("attached controller %d\n", i);
	softc->index = i;
	setcontroller(softc, i);
	controller_mask |= 1<<i;

	/*
	 * Allocate a DMA buffer
	 */

	softc->uhid_imsg = usb_dma_alloc(UBR_KBD_MAX);
	if (softc->uhid_imsg == NULL) {
		printf("couldn't alloc buffer\n");
		/* Could not allocate a buffer, fail. */
		return -1;
	}
	
	/*
	 * Choose the standard configuration.
	 */

	usb_set_configuration(dev,cfgdscr->bConfigurationValue);

	/*
	 * Open the interrupt pipe.
	 */

	softc->uhid_ipipe = usb_open_pipe(dev,epdscr);
	softc->uhid_ipipemps = GETUSBFIELD(epdscr,wMaxPacketSize);

	/*
	 * Queue a transfer on the interrupt endpoint to catch
	 * our first characters.
	 */
	usbctrl_set_leds(softc, 0);
	usbctrl_queue_intreq(dev,softc);


	}

	return 0;


}
Пример #5
0
static int usbhid_attach(usbdev_t *dev,usb_driver_t *drv)
{
    usb_config_descr_t *cfgdscr = dev->ud_cfgdescr;
    usb_endpoint_descr_t *epdscr;
    usb_interface_descr_t *ifdscr;
    usbhid_softc_t *softc;

    dev->ud_drv = drv;

    softc = KMALLOC(sizeof(usbhid_softc_t),0);
    memset(softc,0,sizeof(usbhid_softc_t));
    dev->ud_private = softc;

    epdscr = usb_find_cfg_descr(dev,USB_ENDPOINT_DESCRIPTOR_TYPE,0);
    ifdscr = usb_find_cfg_descr(dev,USB_INTERFACE_DESCRIPTOR_TYPE,0);

    if (!epdscr || !ifdscr) {
	/*
	 * Could not get descriptors, something is very wrong.
	 * Leave device addressed but not configured.
	 */
	return 0;
	}

    /*
     * Allocate a DMA buffer
     */

    softc->uhid_imsg = usb_dma_alloc(UBR_KBD_MAX);
    if (softc->uhid_imsg == NULL) {
	/* Could not allocate a buffer, fail. */
	return -1;
	}

    /*
     * Choose the standard configuration.
     */

    usb_set_configuration(dev,cfgdscr->bConfigurationValue);

    /*
     * Set the protocol to the "boot" protocol, so we don't
     * have to deal with fancy HID stuff.
     */

    usbhid_set_protocol(dev,HID_BOOT_PROTOCOL,ifdscr->bInterfaceNumber);

    /*
     * Open the interrupt pipe.
     */

    softc->uhid_ipipe = usb_open_pipe(dev,epdscr);
    softc->uhid_ipipemps = GETUSBFIELD(epdscr,wMaxPacketSize);

    /*
     * Figure out the device type from the protocol.  Keyboards,
     * mice use this field to distinguish themselves.
     */

    softc->uhid_devtype = ifdscr->bInterfaceProtocol;
    if (softc->uhid_devtype > HID_DEVTYPE_MAX) {
	softc->uhid_devtype = HID_DEVTYPE_UNKNOWN;
	}

    console_log("USBHID: %s Configured.\n",
	   usbhid_devtypes[softc->uhid_devtype]);

    /*
     * Queue a transfer on the interrupt endpoint to catch
     * our first characters.
     */

    usbhid_queue_intreq(dev,softc);

    return 0;
}
Пример #6
0
static int usbmass_attach(usbdev_t *dev,usb_driver_t *drv)
{
    usb_config_descr_t *cfgdscr = dev->ud_cfgdescr;
    usb_endpoint_descr_t *epdscr;
    usb_endpoint_descr_t *indscr = NULL;
    usb_endpoint_descr_t *outdscr = NULL;
    usb_interface_descr_t *ifdscr;
    usbmass_softc_t *softc;
    int idx;
    dev->ud_drv = drv;

    softc = KMALLOC(sizeof(usbmass_softc_t),0);
    memset(softc,0,sizeof(usbmass_softc_t));
    dev->ud_private = softc;

    ifdscr = usb_find_cfg_descr(dev,USB_INTERFACE_DESCRIPTOR_TYPE,0);
    if (ifdscr == NULL) {
	return -1;
	}

    if ((ifdscr->bInterfaceSubClass != USBMASS_SUBCLASS_SCSI) ||
	(ifdscr->bInterfaceProtocol != USBMASS_BULKONLY_PROTOCOL)) {
	console_log("USBMASS: Do not understand devices with SubClass 0x%02X, Protocol 0x%02X",
		    ifdscr->bInterfaceSubClass,
		    ifdscr->bInterfaceProtocol);
	return -1;
	}

    for (idx = 0; idx < 2; idx++) {
	epdscr = usb_find_cfg_descr(dev,USB_ENDPOINT_DESCRIPTOR_TYPE,idx);

	if (USB_ENDPOINT_DIR_OUT(epdscr->bEndpointAddress)) {
	    outdscr = epdscr;
	    }
	else {
	    indscr = epdscr;
	    }
	}


    if (!indscr || !outdscr) {
	/*
	 * Could not get descriptors, something is very wrong.
	 * Leave device addressed but not configured.
	 */
	return -1;
	}

    /*
     * Choose the standard configuration.
     */

    usb_set_configuration(dev,cfgdscr->bConfigurationValue);

    /*
     * Open the pipes.
     */

    softc->umass_inpipe     = usb_open_pipe(dev,indscr);
    softc->umass_outpipe    = usb_open_pipe(dev,outdscr);
    softc->umass_curtag     = 0x12345678;
    softc->dev = dev;

    /*
     * Save pointer in global unit table so we can
     * match CFE devices up with USB ones
     */

    // = 0;
	//num = 0;
 //   char name[10];
 //   sprintf(name, "ud%c", 'a' + num); num++; num %= 26;
 //   softc->bdev = register_bdev(softc, &usbmass_ops, name);

 //   usbmass_dev = dev;

    return 0;
}