static int usbhub_ireq_callback(usbreq_t *ur) { int idx; usbhub_softc_t *uhub = (ur->ur_dev->ud_private); /* * Check to see if the request was cancelled by someone * deleting our endpoint. We also check for "device not responding" * which typically happens when a device is removed. * * XXX this is not correct, it appears that hubs sometimes do * return this error. We'll need to redo the whole way * surprise detach works eventually... */ if ((ur->ur_status == UR_ERR_CANCELLED) || (ur->ur_status == UR_ERR_DEVICENOTRESPONDING)) { usb_free_request(ur); return 0; } /* * Check to see if any of our ports need attention */ for (idx = 1; idx <= uhub->uhub_nports; idx++) { if (ur->ur_buffer[0] & (1<<idx)) { /* * Mark the hub as needing a scan, and mark the bus as well * so the top-level polling will notice. */ uhub->uhub_flags |= UHUB_FLG_NEEDSCAN; ur->ur_dev->ud_bus->ub_flags |= UB_FLG_NEEDSCAN; } } /* * Do NOT requeue the request here. We will do this * during exploration. */ usb_free_request(ur); return 0; }
static int rtek_send_eth_frame( void *ctx, hsaddr_t buf, int len ) { rtek_softc_t *softc = (rtek_softc_t *) ctx; usbreq_t *ur; int txlen = len; unsigned char *txbuf; /* First some Realtek chip workarounds */ if( txlen < 60 ) /* some strange limitation */ txlen = 60; else if( !(txlen % 64) ) /* to handle module 64 packets */ ++txlen; txbuf = usb_dma_alloc(txlen); hs_memcpy_from_hs( txbuf, buf, txlen ); #if USBETH_DEBUG xprintf( "Outgoing packet :\n" ); hexdump( txbuf, txlen, 16, txlen / 16 + 1 ); #endif ur = usb_make_request(softc->dev, softc->bulk_outpipe, txbuf, txlen, UR_FLAG_OUT); usb_sync_request(ur); usb_free_request(ur); usb_dma_free(txbuf); return( len ); }
static int usbhub_ireq_callback(usbreq_t *ur) { int idx; usbhub_softc_t *uhub = (ur->ur_dev->ud_private); /* * Check to see if the request was cancelled by someone * deleting our endpoint. */ if (ur->ur_status == 0xFF) { usb_free_request(ur); return 0; } /* * Check to see if any of our ports need attention */ for (idx = 1; idx <= uhub->uhub_nports; idx++) { if (ur->ur_buffer[0] & (1<<idx)) { /* * Mark the hub as needing a scan, and mark the bus as well * so the top-level polling will notice. */ uhub->uhub_flags |= UHUB_FLG_NEEDSCAN; ur->ur_dev->ud_bus->ub_flags |= UB_FLG_NEEDSCAN; } } /* * Do NOT requeue the request here. We will do this * during exploration. */ usb_free_request(ur); return 0; }
static int usbhid_ireq_callback(usbreq_t *ur) { usbhid_softc_t *uhid = (ur->ur_dev->ud_private); /* * If the driver is unloaded, the request will be cancelled. */ if (ur->ur_status == 0xFF) { usb_free_request(ur); return 0; } /* * What we do now depends on the type of device. */ switch (uhid->uhid_devtype) { case HID_DEVTYPE_KBD: /* * Handle keyboard event */ usbhid_kbd_scan(uhid); /* * Save old event to compare for next time. */ memcpy(uhid->uhid_lastmsg,uhid->uhid_imsg,UBR_KBD_MAX); break; case HID_DEVTYPE_MOUSE: #if 0 /* * No need to handle mice, but here's the good stuff. */ printf("Mouse: [%s %s %s] X:%d Y:%d Wheel:%d\n", (ur->ur_buffer[0] & 1) ? "left" : "", (ur->ur_buffer[0] & 4) ? "middle" : "", (ur->ur_buffer[0] & 2) ? "right" : "", (int)(signed char)ur->ur_buffer[1], (int)(signed char)ur->ur_buffer[2], (int)(signed char)ur->ur_buffer[3]); #endif break; } /* * Re-queue request to get next keyboard event. */ usb_queue_request(ur); return 0; }
static int rtek_get_eth_frame( void *ctx, hsaddr_t buf ) { int len = 0; rtek_softc_t *softc = (rtek_softc_t *) ctx; uint8_t *rxbuf; if( !softc->rx_ur->ur_inprogress ) { rxbuf = softc->rxbuf; len = softc->rx_ur->ur_xferred; if (len > 0) { #if USBETH_DEBUG xprintf( "Incoming packet :\n" ); hexdump( rxbuf, len, 16, len / 16 + 1 ); #endif hs_memcpy_to_hs( buf, rxbuf, len ); } usb_free_request(softc->rx_ur); rtek_queue_rx( softc ); } else xprintf( "Bulk data is not available yet!\n" ); return( len ); }
static int usbctrl_ireq_callback(usbreq_t *ur) { usbctrl_softc_t *uhid = (ur->ur_ref); //FIXME: are we allowed to use ur_ref for this purpose? /* int i; for (i = 0; i < uhid->uhid_ipipemps; ++i) printf("%02x ", ur->ur_buffer[i]); printf("\n"); */ /* * If the driver is unloaded, the request will be cancelled. */ if (ur->ur_status == 0xFF) { usb_free_request(ur); return 0; } /* printf("Dump:\n"); int i; for (i = 0; i < uhid->uhid_ipipemps; ++i) printf("%02x ", ur->ur_buffer[i]); printf("\n\n\n"); */ struct controller_data_s c; unsigned char *b = ur->ur_buffer; if (uhid->is_wireless) { //FIXME: A polled, disconnected controller may cause uneeded spam of the controller status message if(uhid->index == -1) { //printf("Wireless controller %i has connected\n", uhid->wireless_index); int i; for (i = 0; controller_mask & (1<<i); ++i); //printf("attached controller %d\n", i); uhid->index = i; setcontroller(uhid, uhid->index); controller_mask |= 1<<i; usbctrl_set_leds(uhid, 0); } if (b[0] == 0x8 && b[1] == 0x0) { //printf("Wireless controller %i has disconnected\n", uhid->wireless_index); printf("detatched controller %d\n", uhid->index); setcontroller(NULL, uhid->index); controller_mask &= ~(1<<uhid->index); uhid->index = -1; goto ignore; } if (b[5] == 0x13) { #if 0 if (b[6] == 2) /* CHECKME: is this required for the Xbox racing wheel? */ b++; #endif b += 4; } else goto ignore; } c.s1_x = (b[7] << 8) | b[6]; c.s1_y = (b[9] << 8) | b[8]; c.s2_x = (b[11] << 8) | b[10]; c.s2_y = (b[13] << 8) | b[12]; c.s1_z = !!(b[2] & 0x40); c.s2_z = !!(b[2] & 0x80); c.lt = b[4]; c.rt = b[5]; c.lb = !!(b[3] & 1); c.rb = !!(b[3] & 2); c.a = !!(b[3] & 0x10); c.b = !!(b[3] & 0x20); c.x = !!(b[3] & 0x40); c.y = !!(b[3] & 0x80); c.start = !!(b[2] & 0x10); c.back = !!(b[2] & 0x20); c.up = !!(b[2] & 1); c.down = !!(b[2] & 2); c.left = !!(b[2] & 4); c.right = !!(b[2] & 8); c.logo = !!(b[3] & 0x4); set_controller_data(uhid->index, &c); ignore: usb_queue_request(ur); return 0; }
static int usbctrl_set_led_callback(usbreq_t *ur) { usb_dma_free(ur->ur_buffer); //Don't leak the buffer //printf("Got callback for set leds\n"); usb_free_request(ur); return 0; }