这篇教程C++ usb_driver_claim_interface函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中usb_driver_claim_interface函数的典型用法代码示例。如果您正苦于以下问题:C++ usb_driver_claim_interface函数的具体用法?C++ usb_driver_claim_interface怎么用?C++ usb_driver_claim_interface使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了usb_driver_claim_interface函数的21个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: xusbatm_capture_intfstatic int xusbatm_capture_intf(struct usbatm_data *usbatm, struct usb_device *usb_dev, struct usb_interface *intf, int altsetting, int claim){ int ifnum = intf->altsetting->desc.bInterfaceNumber; int ret; if (claim && (ret = usb_driver_claim_interface(&xusbatm_usb_driver, intf, usbatm))) { usb_err(usbatm, "%s: failed to claim interface %2d (%d)!/n", __func__, ifnum, ret); return ret; } if ((ret = usb_set_interface(usb_dev, ifnum, altsetting))) { usb_err(usbatm, "%s: altsetting %2d for interface %2d failed (%d)!/n", __func__, altsetting, ifnum, ret); return ret; } return 0;}
开发者ID:CSCLOG,项目名称:beaglebone,代码行数:16,
示例2: usbnet_generic_cdc_bind//.........这里部分代码省略......... /* because of Zaurus, we may be ignoring the host * side link address we were given. */ } if (header.usb_cdc_mdlm_desc && memcmp(header.usb_cdc_mdlm_desc->bGUID, mbm_guid, 16)) { dev_dbg(&intf->dev, "GUID doesn't match/n"); goto bad_desc; } if (header.usb_cdc_mdlm_detail_desc && header.usb_cdc_mdlm_detail_desc->bLength < (sizeof(struct usb_cdc_mdlm_detail_desc) + 1)) { dev_dbg(&intf->dev, "Descriptor too short/n"); goto bad_desc; } /* Microsoft ActiveSync based and some regular RNDIS devices lack the * CDC descriptors, so we'll hard-wire the interfaces and not check * for descriptors. * * Some Android RNDIS devices have a CDC Union descriptor pointing * to non-existing interfaces. Ignore that and attempt the same * hard-wired 0 and 1 interfaces. */ if (rndis && (!info->u || android_rndis_quirk)) { info->control = usb_ifnum_to_if(dev->udev, 0); info->data = usb_ifnum_to_if(dev->udev, 1); if (!info->control || !info->data || info->control != intf) { dev_dbg(&intf->dev, "rndis: master #0/%p slave #1/%p/n", info->control, info->data); goto bad_desc; } } else if (!info->header || !info->u || (!rndis && !info->ether)) { dev_dbg(&intf->dev, "missing cdc %s%s%sdescriptor/n", info->header ? "" : "header ", info->u ? "" : "union ", info->ether ? "" : "ether "); goto bad_desc; } /* claim data interface and set it up ... with side effects. * network traffic can't flow until an altsetting is enabled. */ if (info->data != info->control) { status = usb_driver_claim_interface(driver, info->data, dev); if (status < 0) return status; } status = usbnet_get_endpoints(dev, info->data); if (status < 0) { /* ensure immediate exit from usbnet_disconnect */ usb_set_intfdata(info->data, NULL); if (info->data != info->control) usb_driver_release_interface(driver, info->data); return status; } /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */ if (info->data != info->control) dev->status = NULL; if (info->control->cur_altsetting->desc.bNumEndpoints == 1) { struct usb_endpoint_descriptor *desc; dev->status = &info->control->cur_altsetting->endpoint [0]; desc = &dev->status->desc; if (!usb_endpoint_is_int_in(desc) || (le16_to_cpu(desc->wMaxPacketSize) < sizeof(struct usb_cdc_notification)) || !desc->bInterval) { dev_dbg(&intf->dev, "bad notification endpoint/n"); dev->status = NULL; } } if (rndis && !dev->status) { dev_dbg(&intf->dev, "missing RNDIS status endpoint/n"); usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); return -ENODEV; } /* Some devices don't initialise properly. In particular * the packet filter is not reset. There are devices that * don't do reset all the way. So the packet filter should * be set to a sane initial value. */ usbnet_cdc_update_filter(dev); return 0;bad_desc: dev_info(&dev->udev->dev, "bad CDC descriptors/n"); return -ENODEV;}
开发者ID:OSPro,项目名称:wpj344_compatwireless,代码行数:101,
示例3: usbnet_generic_cdc_bind//.........这里部分代码省略......... info->ether = (void *) buf; if (info->ether->bLength != sizeof *info->ether) { dev_dbg(&intf->dev, "CDC ether len %u/n", info->ether->bLength); goto bad_desc; } dev->hard_mtu = le16_to_cpu( info->ether->wMaxSegmentSize); break; case USB_CDC_MDLM_TYPE: if (desc) { dev_dbg(&intf->dev, "extra MDLM descriptor/n"); goto bad_desc; } desc = (void *)buf; if (desc->bLength != sizeof(*desc)) goto bad_desc; if (memcmp(&desc->bGUID, mbm_guid, 16)) goto bad_desc; break; case USB_CDC_MDLM_DETAIL_TYPE: if (detail) { dev_dbg(&intf->dev, "extra MDLM detail descriptor/n"); goto bad_desc; } detail = (void *)buf; if (detail->bGuidDescriptorType == 0) { if (detail->bLength < (sizeof(*detail) + 1)) goto bad_desc; } else goto bad_desc; break; }next_desc: len -= buf [0]; buf += buf [0]; } if (rndis && (!info->u || android_rndis_quirk)) { info->control = usb_ifnum_to_if(dev->udev, 0); info->data = usb_ifnum_to_if(dev->udev, 1); if (!info->control || !info->data || info->control != intf) { dev_dbg(&intf->dev, "rndis: master #0/%p slave #1/%p/n", info->control, info->data); goto bad_desc; } } else if (!info->header || !info->u || (!rndis && !info->ether)) { dev_dbg(&intf->dev, "missing cdc %s%s%sdescriptor/n", info->header ? "" : "header ", info->u ? "" : "union ", info->ether ? "" : "ether "); goto bad_desc; } status = usb_driver_claim_interface(driver, info->data, dev); if (status < 0) return status; status = usbnet_get_endpoints(dev, info->data); if (status < 0) { usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); return status; } dev->status = NULL; if (info->control->cur_altsetting->desc.bNumEndpoints == 1) { struct usb_endpoint_descriptor *desc; dev->status = &info->control->cur_altsetting->endpoint [0]; desc = &dev->status->desc; if (!usb_endpoint_is_int_in(desc) || (le16_to_cpu(desc->wMaxPacketSize) < sizeof(struct usb_cdc_notification)) || !desc->bInterval) { dev_dbg(&intf->dev, "bad notification endpoint/n"); dev->status = NULL; } } if (rndis && !dev->status) { dev_dbg(&intf->dev, "missing RNDIS status endpoint/n"); usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); return -ENODEV; } return 0;bad_desc: dev_info(&dev->udev->dev, "bad CDC descriptors/n"); return -ENODEV;}
开发者ID:droidcore,项目名称:kangaroo-m7-mkv,代码行数:101,
示例4: cdc_ncm_bind_common//.........这里部分代码省略......... if (buf[0] < sizeof(*(ctx->func_desc))) break; ctx->func_desc = (const struct usb_cdc_ncm_desc *)buf; break; case USB_CDC_MBIM_TYPE: if (buf[0] < sizeof(*(ctx->mbim_desc))) break; ctx->mbim_desc = (const struct usb_cdc_mbim_desc *)buf; break; default: break; }advance: /* advance to next descriptor */ temp = buf[0]; buf += temp; len -= temp; } /* some buggy devices have an IAD but no CDC Union */ if (!ctx->union_desc && intf->intf_assoc && intf->intf_assoc->bInterfaceCount == 2) { ctx->control = intf; ctx->data = usb_ifnum_to_if(dev->udev, intf->cur_altsetting->desc.bInterfaceNumber + 1); dev_dbg(&intf->dev, "CDC Union missing - got slave from IAD/n"); } /* check if we got everything */ if ((ctx->control == NULL) || (ctx->data == NULL) || ((!ctx->mbim_desc) && ((ctx->ether_desc == NULL) || (ctx->control != intf)))) goto error; /* claim data interface, if different from control */ if (ctx->data != ctx->control) { temp = usb_driver_claim_interface(driver, ctx->data, dev); if (temp) goto error; } iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber; /* reset data interface */ temp = usb_set_interface(dev->udev, iface_no, 0); if (temp) goto error2; /* initialize data interface */ if (cdc_ncm_setup(ctx)) goto error2; /* configure data interface */ temp = usb_set_interface(dev->udev, iface_no, data_altsetting); if (temp) goto error2; cdc_ncm_find_endpoints(ctx, ctx->data); cdc_ncm_find_endpoints(ctx, ctx->control); if ((ctx->in_ep == NULL) || (ctx->out_ep == NULL) || (ctx->status_ep == NULL)) goto error2; dev->net->ethtool_ops = &cdc_ncm_ethtool_ops; usb_set_intfdata(ctx->data, dev); usb_set_intfdata(ctx->control, dev); usb_set_intfdata(ctx->intf, dev); if (ctx->ether_desc) { temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress); if (temp) goto error2; dev_info(&dev->udev->dev, "MAC-Address: %pM/n", dev->net->dev_addr); } dev->in = usb_rcvbulkpipe(dev->udev, ctx->in_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); dev->out = usb_sndbulkpipe(dev->udev, ctx->out_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); dev->status = ctx->status_ep; dev->rx_urb_size = ctx->rx_max; ctx->tx_speed = ctx->rx_speed = 0; return 0;error2: usb_set_intfdata(ctx->control, NULL); usb_set_intfdata(ctx->data, NULL); if (ctx->data != ctx->control) usb_driver_release_interface(driver, ctx->data);error: cdc_ncm_free((struct cdc_ncm_ctx *)dev->data[0]); dev->data[0] = 0; dev_info(&dev->udev->dev, "bind() failure/n"); return -ENODEV;}
开发者ID:smx-smx,项目名称:dsl-n55u,代码行数:101,
示例5: btusb_probe//.........这里部分代码省略......... data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { ep_desc = &intf->cur_altsetting->endpoint[i].desc; if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) { data->intr_ep = ep_desc; continue; } if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { data->bulk_tx_ep = ep_desc; continue; } if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { data->bulk_rx_ep = ep_desc; continue; } } if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) { kfree(data); return -ENODEV; } data->cmdreq_type = USB_TYPE_CLASS; data->udev = interface_to_usbdev(intf); data->intf = intf; spin_lock_init(&data->lock); INIT_WORK(&data->work, btusb_work); INIT_WORK(&data->waker, btusb_waker); spin_lock_init(&data->txlock); init_usb_anchor(&data->tx_anchor); init_usb_anchor(&data->intr_anchor); init_usb_anchor(&data->bulk_anchor); init_usb_anchor(&data->isoc_anchor); init_usb_anchor(&data->deferred); hdev = hci_alloc_dev(); if (!hdev) { kfree(data); return -ENOMEM; } HDEV_BUS = HCI_USB; data->hdev = hdev; SET_HCIDEV_DEV(hdev, &intf->dev); hdev->open = btusb_open; hdev->close = btusb_close; hdev->flush = btusb_flush; hdev->send = btusb_send_frame; hdev->notify = btusb_notify;#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 4, 0) hci_set_drvdata(hdev, data);#else hdev->driver_data = data; hdev->destruct = btusb_destruct; hdev->owner = THIS_MODULE;#endif /* Interface numbers are hardcoded in the specification */ data->isoc = usb_ifnum_to_if(data->udev, 1); if (data->isoc) { err = usb_driver_claim_interface(&btusb_driver, data->isoc, data); if (err < 0) { hci_free_dev(hdev); kfree(data); return err; } } err = hci_register_dev(hdev); if (err < 0) { hci_free_dev(hdev); kfree(data); return err; } usb_set_intfdata(intf, data); return 0;}
开发者ID:mattgorski,项目名称:platform_hardware_realtek,代码行数:101,
示例6: acm_probe//.........这里部分代码省略......... for (i = 0; i < num_rx_buf; i++) { struct acm_ru *rcv = &(acm->ru[i]); if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)/n"); goto alloc_fail7; } rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; rcv->instance = acm; } for (i = 0; i < num_rx_buf; i++) { struct acm_rb *buf = &(acm->rb[i]); if (!(buf->base = usb_buffer_alloc(acm->dev, readsize, GFP_KERNEL, &buf->dma))) { dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)/n"); goto alloc_fail7; } } for(i = 0; i < ACM_NW; i++) { struct acm_wb *snd = &(acm->wb[i]); if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { dev_dbg(&intf->dev, "out of memory (write urbs usb_alloc_urb)"); goto alloc_fail7; } usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), NULL, acm->writesize, acm_write_bulk, snd); snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; snd->instance = acm; } usb_set_intfdata (intf, acm); i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); if (i < 0) goto alloc_fail8; if (cfd) { /* export the country data */ acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); if (!acm->country_codes) goto skip_countries; acm->country_code_size = cfd->bLength - 4; memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); acm->country_rel_date = cfd->iCountryCodeRelDate; i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); if (i < 0) { kfree(acm->country_codes); goto skip_countries; } i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); if (i < 0) { kfree(acm->country_codes); goto skip_countries; } }skip_countries: usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; acm->ctrlurb->transfer_dma = acm->ctrl_dma; dev_info(&intf->dev, "ttyACM%d: USB ACM device/n", minor); acm_set_control(acm, acm->ctrlout); acm->line.dwDTERate = cpu_to_le32(9600); acm->line.bDataBits = 8; acm_set_line(acm, &acm->line); usb_driver_claim_interface(&acm_driver, data_interface, acm); usb_get_intf(control_interface); tty_register_device(acm_tty_driver, minor, &control_interface->dev); acm_table[minor] = acm; return 0;alloc_fail8: for (i = 0; i < ACM_NW; i++) usb_free_urb(acm->wb[i].urb);alloc_fail7: acm_read_buffers_free(acm); for (i = 0; i < num_rx_buf; i++) usb_free_urb(acm->ru[i].urb); usb_free_urb(acm->ctrlurb);alloc_fail5: acm_write_buffers_free(acm);alloc_fail4: usb_buffer_free(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);alloc_fail2: kfree(acm);alloc_fail: return -ENOMEM;}
开发者ID:IgnasD,项目名称:Tomato-RAF,代码行数:101,
示例7: btusb_probe//.........这里部分代码省略......... INIT_WORK(&data->waker, btusb_waker); spin_lock_init(&data->txlock); init_usb_anchor(&data->tx_anchor); init_usb_anchor(&data->intr_anchor); init_usb_anchor(&data->bulk_anchor); init_usb_anchor(&data->isoc_anchor); init_usb_anchor(&data->deferred); hdev = hci_alloc_dev(); if (!hdev) { kfree(data); return -ENOMEM; } hdev->bus = HCI_USB; hdev->driver_data = data; data->hdev = hdev; SET_HCIDEV_DEV(hdev, &intf->dev); hdev->open = btusb_open; hdev->close = btusb_close; hdev->flush = btusb_flush; hdev->send = btusb_send_frame; hdev->destruct = btusb_destruct; hdev->notify = btusb_notify; hdev->owner = THIS_MODULE; /* Interface numbers are hardcoded in the specification */ data->isoc = usb_ifnum_to_if(data->udev, 1); if (!reset) set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) { if (!disable_scofix) set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks); } if (id->driver_info & BTUSB_BROKEN_ISOC) data->isoc = NULL; if (id->driver_info & BTUSB_DIGIANSWER) { data->cmdreq_type = USB_TYPE_VENDOR; set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); } if (id->driver_info & BTUSB_CSR) { struct usb_device *udev = data->udev; /* Old firmware would otherwise execute USB reset */ if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117) set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); } if (id->driver_info & BTUSB_SNIFFER) { struct usb_device *udev = data->udev; /* New sniffer firmware has crippled HCI interface */ if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997) set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); data->isoc = NULL; } if (id->driver_info & BTUSB_BCM92035) { unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 }; struct sk_buff *skb; skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL); if (skb) { memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd)); skb_queue_tail(&hdev->driver_init, skb); } } if (data->isoc) { err = usb_driver_claim_interface(&btusb_driver, data->isoc, data); if (err < 0) { hci_free_dev(hdev); kfree(data); return err; } } err = hci_register_dev(hdev); if (err < 0) { hci_free_dev(hdev); kfree(data); return err; } usb_set_intfdata(intf, data); return 0;}
开发者ID:Rukusx7,项目名称:Rockchip-GPL-Kernel,代码行数:101,
示例8: qmi_wwan_bindstatic int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf){ int status = -1; u8 *buf = intf->cur_altsetting->extra; int len = intf->cur_altsetting->extralen; struct usb_interface_descriptor *desc = &intf->cur_altsetting->desc; struct usb_cdc_union_desc *cdc_union; struct usb_cdc_ether_desc *cdc_ether; struct usb_driver *driver = driver_of(intf); struct qmi_wwan_state *info = (void *)&dev->data; struct usb_cdc_parsed_header hdr; BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) < sizeof(struct qmi_wwan_state))); /* set up initial state */ info->control = intf; info->data = intf; /* and a number of CDC descriptors */ cdc_parse_cdc_header(&hdr, intf, buf, len); cdc_union = hdr.usb_cdc_union_desc; cdc_ether = hdr.usb_cdc_ether_desc; /* Use separate control and data interfaces if we found a CDC Union */ if (cdc_union) { info->data = usb_ifnum_to_if(dev->udev, cdc_union->bSlaveInterface0); if (desc->bInterfaceNumber != cdc_union->bMasterInterface0 || !info->data) { dev_err(&intf->dev, "bogus CDC Union: master=%u, slave=%u/n", cdc_union->bMasterInterface0, cdc_union->bSlaveInterface0); /* ignore and continue... */ cdc_union = NULL; info->data = intf; } } /* errors aren't fatal - we can live with the dynamic address */ if (cdc_ether) { dev->hard_mtu = le16_to_cpu(cdc_ether->wMaxSegmentSize); usbnet_get_ethernet_addr(dev, cdc_ether->iMACAddress); } /* claim data interface and set it up */ if (info->control != info->data) { status = usb_driver_claim_interface(driver, info->data, dev); if (status < 0) goto err; } status = qmi_wwan_register_subdriver(dev); if (status < 0 && info->control != info->data) { usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); } /* disabling remote wakeup on MDM9x30 devices has the same * effect as clearing DTR. The device will not respond to QMI * requests until we set DTR again. This is similar to a * QMI_CTL SYNC request, clearing a lot of firmware state * including the client ID allocations. * * Our usage model allows a session to span multiple * open/close events, so we must prevent the firmware from * clearing out state the clients might need. * * MDM9x30 is the first QMI chipset with USB3 support. Abuse * this fact to enable the quirk. */ if (le16_to_cpu(dev->udev->descriptor.bcdUSB) >= 0x0201) { qmi_wwan_manage_power(dev, 1); qmi_wwan_change_dtr(dev, true); } /* Never use the same address on both ends of the link, even if the * buggy firmware told us to. Or, if device is assigned the well-known * buggy firmware MAC address, replace it with a random address, */ if (ether_addr_equal(dev->net->dev_addr, default_modem_addr) || ether_addr_equal(dev->net->dev_addr, buggy_fw_addr)) eth_hw_addr_random(dev->net); /* make MAC addr easily distinguishable from an IP header */ if (possibly_iphdr(dev->net->dev_addr)) { dev->net->dev_addr[0] |= 0x02; /* set local assignment bit */ dev->net->dev_addr[0] &= 0xbf; /* clear "IP" bit */ } dev->net->netdev_ops = &qmi_wwan_netdev_ops; dev->net->sysfs_groups[0] = &qmi_wwan_sysfs_attr_group;err: return status;}
开发者ID:020gzh,项目名称:linux,代码行数:96,
示例9: CDCEther_probe//.........这里部分代码省略......... // Let's see if we can find a configuration we can use. rc = find_valid_configuration( usb, ether_dev ); if (rc) { // Nope we couldn't find one we liked. // This device was not meant for us to control. kfree( ether_dev ); return NULL; } // Now that we FOUND a configuration. let's try to make the // device go into it. if ( usb_set_configuration( usb, ether_dev->bConfigurationValue ) ) { err("usb_set_configuration() failed"); kfree( ether_dev ); return NULL; } // Now set the communication interface up as required. if (usb_set_interface(usb, ether_dev->comm_bInterfaceNumber, ether_dev->comm_bAlternateSetting)) { err("usb_set_interface() failed"); kfree( ether_dev ); return NULL; } // Only turn traffic on right now if we must... if (ether_dev->data_interface_altset_num_without_traffic >= 0) { // We found an alternate setting for the data // interface that allows us to turn off traffic. // We should use it. if (usb_set_interface( usb, ether_dev->data_bInterfaceNumber, ether_dev->data_bAlternateSetting_without_traffic)) { err("usb_set_interface() failed"); kfree( ether_dev ); return NULL; } } else { // We didn't find an alternate setting for the data // interface that would let us turn off traffic. // Oh well, let's go ahead and do what we must... if (usb_set_interface( usb, ether_dev->data_bInterfaceNumber, ether_dev->data_bAlternateSetting_with_traffic)) { err("usb_set_interface() failed"); kfree( ether_dev ); return NULL; } } // Now we need to get a kernel Ethernet interface. net = init_etherdev( NULL, 0 ); if ( !net ) { // Hmm... The kernel is not sharing today... // Fine, we didn't want it anyway... err( "Unable to initialize ethernet device" ); kfree( ether_dev ); return NULL; } // Now that we have an ethernet device, let's set it up // (And I don't mean "set [it] up the bomb".) net->priv = ether_dev; net->open = CDCEther_open; net->stop = CDCEther_close; net->watchdog_timeo = CDC_ETHER_TX_TIMEOUT; net->tx_timeout = CDCEther_tx_timeout; // TX timeout function net->do_ioctl = CDCEther_ioctl; net->hard_start_xmit = CDCEther_start_xmit; net->set_multicast_list = CDCEther_set_multicast; net->get_stats = CDCEther_netdev_stats; net->mtu = ether_dev->wMaxSegmentSize - 14; // We'll keep track of this information for later... ether_dev->usb = usb; ether_dev->net = net; // and don't forget the MAC address. set_ethernet_addr( ether_dev ); // Send a message to syslog about what we are handling log_device_info( ether_dev ); // I claim this interface to be a CDC Ethernet Networking device usb_driver_claim_interface( &CDCEther_driver, &(usb->config[ether_dev->configuration_num].interface[ether_dev->comm_interface]), ether_dev ); // I claim this interface to be a CDC Ethernet Networking device usb_driver_claim_interface( &CDCEther_driver, &(usb->config[ether_dev->configuration_num].interface[ether_dev->data_interface]), ether_dev ); // Does this REALLY do anything??? usb_inc_dev_use( usb ); // TODO - last minute HACK ether_dev->comm_ep_in = 5; // Okay, we are finally done... return NULL;}
开发者ID:liexusong,项目名称:Linux-2.4.16,代码行数:101,
示例10: cdc_ncm_bind_common//.........这里部分代码省略......... ctx->mbim_desc = (const struct usb_cdc_mbim_desc *)buf; break; case USB_CDC_MBIM_EXTENDED_TYPE: if (buf[0] < sizeof(*(ctx->mbim_extended_desc))) break; ctx->mbim_extended_desc = (const struct usb_cdc_mbim_extended_desc *)buf; break; default: break; }advance: /* advance to next descriptor */ temp = buf[0]; buf += temp; len -= temp; } /* some buggy devices have an IAD but no CDC Union */ if (!union_desc && intf->intf_assoc && intf->intf_assoc->bInterfaceCount == 2) { ctx->data = usb_ifnum_to_if(dev->udev, intf->cur_altsetting->desc.bInterfaceNumber + 1); dev_dbg(&intf->dev, "CDC Union missing - got slave from IAD/n"); } /* check if we got everything */ if (!ctx->data || (!ctx->mbim_desc && !ctx->ether_desc)) { dev_dbg(&intf->dev, "CDC descriptors missing/n"); goto error; } /* claim data interface, if different from control */ if (ctx->data != ctx->control) { temp = usb_driver_claim_interface(driver, ctx->data, dev); if (temp) { dev_dbg(&intf->dev, "failed to claim data intf/n"); goto error; } } iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber; /* reset data interface */ temp = usb_set_interface(dev->udev, iface_no, 0); if (temp) { dev_dbg(&intf->dev, "set interface failed/n"); goto error2; } /* configure data interface */ temp = usb_set_interface(dev->udev, iface_no, data_altsetting); if (temp) { dev_dbg(&intf->dev, "set interface failed/n"); goto error2; } cdc_ncm_find_endpoints(dev, ctx->data); cdc_ncm_find_endpoints(dev, ctx->control); if (!dev->in || !dev->out || !dev->status) { dev_dbg(&intf->dev, "failed to collect endpoints/n"); goto error2; } /* initialize data interface */ if (cdc_ncm_setup(dev)) { dev_dbg(&intf->dev, "cdc_ncm_setup() failed/n"); goto error2; } usb_set_intfdata(ctx->data, dev); usb_set_intfdata(ctx->control, dev); if (ctx->ether_desc) { temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress); if (temp) { dev_dbg(&intf->dev, "failed to get mac address/n"); goto error2; } dev_info(&intf->dev, "MAC-Address: %pM/n", dev->net->dev_addr); } /* usbnet use these values for sizing tx/rx queues */ dev->hard_mtu = ctx->tx_max; dev->rx_urb_size = ctx->rx_max; return 0;error2: usb_set_intfdata(ctx->control, NULL); usb_set_intfdata(ctx->data, NULL); if (ctx->data != ctx->control) usb_driver_release_interface(driver, ctx->data);error: cdc_ncm_free((struct cdc_ncm_ctx *)dev->data[0]); dev->data[0] = 0; dev_info(&intf->dev, "bind() failure/n"); return -ENODEV;}
开发者ID:Mr-Aloof,项目名称:wl500g,代码行数:101,
示例11: usbsvn_probe//.........这里部分代码省略......... if (data[1] == USB_DT_CS_INTERFACE) { /* bDescriptorSubType */ switch (data[2]) { case USB_CDC_UNION_TYPE: if (union_header) break; union_header = (struct usb_cdc_union_desc *)data; break; default: break; } } data += data[0]; len -= data[0]; } if (!union_header) { dev_err(&intf->dev, "USB CDC isn't union type/n"); return -EINVAL; } data_intf = usb_ifnum_to_if(usbdev, union_header->bSlaveInterface0); if (!data_intf) return -ENODEV; data_desc = data_intf->altsetting; /* To detect usb device order probed */ dev_id = intf->altsetting->desc.bInterfaceNumber / 2; if (dev_id >= USBSVN_DEVNUM_MAX) { dev_err(&intf->dev, "Device id %d cannot support/n", dev_id); return -EINVAL; } printk(KERN_ERR "%s: probe dev_id=%d/n", __func__, dev_id); if (dev_id > 0) goto skip_netdev; svn->usbdev = usbdev; svn->driver_info = (unsigned long)id->driver_info; /* FIXME: Does need this indeed? */ usbdev->autosuspend_delay = msecs_to_jiffies(200); /* 200ms */ if (!svn->driver_info) { schedule_delayed_work(&svn->pm_runtime_work, msecs_to_jiffies(10000)); } svn->usbsvn_connected = 1; svn->flow_suspend = 0;skip_netdev: if (!svn->driver_info) { svn = share_svn; if (!svn) { dev_err(&intf->dev, "svnet device doesn't be allocated/n"); err = ENOMEM; goto out; } } usb_get_dev(usbdev); svn->devdata[dev_id].data_intf = data_intf; /* Endpoints */ if (usb_pipein(data_desc->endpoint[0].desc.bEndpointAddress)) { svn->devdata[dev_id].rx_pipe = usb_rcvbulkpipe(usbdev, data_desc->endpoint[0].desc.bEndpointAddress); svn->devdata[dev_id].tx_pipe = usb_sndbulkpipe(usbdev, data_desc->endpoint[1].desc.bEndpointAddress); } else { svn->devdata[dev_id].rx_pipe = usb_rcvbulkpipe(usbdev, data_desc->endpoint[1].desc.bEndpointAddress); svn->devdata[dev_id].tx_pipe = usb_sndbulkpipe(usbdev, data_desc->endpoint[0].desc.bEndpointAddress); } err = usb_driver_claim_interface(&usbsvn_driver, data_intf, svn); if (err < 0) goto out; usb_set_intfdata(intf, svn); svn->dev_count++; if (dev_id == 0) dev_info(&usbdev->dev, "USB CDC SVNET device found/n"); pm_suspend_ignore_children(&intf->dev, true); svn->devdata[dev_id].disconnected = 0; return 0;out: usb_set_intfdata(intf, NULL); return err;}
开发者ID:myfluxi,项目名称:xxKernel,代码行数:101,
示例12: cnxthwusb_probe//.........这里部分代码省略......... !pUsbOsHal->DcpInPipe || !pUsbOsHal->DownloadPipe ||#endif !pUsbOsHal->NotifyPipe) { err("Missing endpoint(s)"); goto exit; } if(!pUsbOsHal->NotifyInterval) pUsbOsHal->NotifyInterval = 1; // ms pUsbOsHal->pUsbDevice = pUsbDevice; pUsbOsHal->pUsbCommInterface = pUsbCommInterface; pUsbOsHal->pUsbDataInterface = pUsbDataInterface; pUsbOsHal->ControlRequestEvent = OsEventCreate("USB ControlRequestEvent"); if(!pUsbOsHal->ControlRequestEvent) { goto exit; } pDevNode = kmalloc(sizeof(*pDevNode), GFP_KERNEL); if(!pDevNode) { err ("Out of memory"); goto exit; } memset(pDevNode, 0, sizeof(*pDevNode)); pDevNode->hwDev = pUsbOsHal;#if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) ) pDevNode->hwDevLink = &pUsbDevice->dev;#endif pDevNode->hwModule = THIS_MODULE; strncpy(pDevNode->hwProfile, (char*)CNXTHWCFG("cadmus2"), sizeof(pDevNode->hwProfile)); pDevNode->hwProfile[sizeof(pDevNode->hwProfile)-1] = '/0'; snprintf(pDevNode->hwInstName, sizeof(pDevNode->hwInstName), "USB-%04x:%04x", USB_BYTEORDER16(pUsbDevice->descriptor.idVendor), USB_BYTEORDER16(pUsbDevice->descriptor.idProduct));#ifdef CNXTHWUSB_TYPE pDevNode->hwType = CNXTHWUSB_TYPE; pDevNode->hwIf = GetHwFuncs();#endif pDevNode->pmControl = cnxthw_DevMgrPMControl; pDevNode->osPageOffset = PAGE_OFFSET; usb_driver_claim_interface(&cnxthwusb_driver, pUsbCommInterface, pDevNode); if(!OsUsbAllocateUrbs(pUsbOsHal)) { err("Cannot allocate URBs");#if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) ) usb_set_intfdata (pUsbCommInterface, NULL);#endif usb_driver_release_interface(&cnxthwusb_driver, pUsbCommInterface); goto exit; } pUsbOsHal->bActive = TRUE; if(OsUsbFWDownload (pUsbOsHal)) { err("Firmware download failed"); pUsbOsHal->bActive = FALSE; OsUsbFreeUrbs(pUsbOsHal);#if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) ) usb_set_intfdata (pUsbCommInterface, NULL);#endif usb_driver_release_interface(&cnxthwusb_driver, pUsbCommInterface); goto exit; } if (cnxt_serial_add(pDevNode, 0, pUsbDevice, ifnum, THIS_MODULE) < 0) { pUsbOsHal->bActive = FALSE; OsUsbFreeUrbs(pUsbOsHal);#if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) ) usb_set_intfdata (pUsbCommInterface, NULL);#endif usb_driver_release_interface(&cnxthwusb_driver, pUsbCommInterface); goto exit; }#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) ) return pDevNode;#else usb_set_intfdata (intf, pDevNode); return 0;#endifexit: if(pDevNode) { kfree(pDevNode); } if(pUsbOsHal) { if(pUsbOsHal->ControlRequestEvent) OsEventDestroy(pUsbOsHal->ControlRequestEvent); kfree(pUsbOsHal); }#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) ) return NULL;#else return -ENODEV;#endif}
开发者ID:jordiclariana,项目名称:hsfmodem,代码行数:101,
示例13: cdc_ncm_bindint cdc_ncm_bind(struct if_usb_devdata *pipe_data, struct usb_interface *intf, struct usb_link_device *usb_ld){ struct cdc_ncm_ctx *ctx; struct usb_driver *usbdrv = to_usb_driver(intf->dev.driver); struct usb_device *usbdev = interface_to_usbdev(intf); unsigned char *buf = intf->cur_altsetting->extra; int buflen = intf->cur_altsetting->extralen; const struct usb_cdc_union_desc *union_desc; int temp; u8 iface_no; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (ctx == NULL) return -ENODEV; hrtimer_init(&ctx->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); ctx->tx_timer.function = &cdc_ncm_tx_timer_cb; ctx->bh.data = (unsigned long)pipe_data; ctx->bh.func = cdc_ncm_txpath_bh; atomic_set(&ctx->stop, 0); spin_lock_init(&ctx->mtx); /* store ctx pointer in device data field */ pipe_data->sedata = (void *)ctx; ctx->intf = intf; /* parse through descriptors associated with control interface */ while ((buflen > 0) && (buf[0] > 2) && (buf[0] <= buflen)) { if (buf[1] == USB_DT_CS_INTERFACE) { switch (buf[2]) { case USB_CDC_UNION_TYPE: if (buf[0] < sizeof(*union_desc)) break; union_desc = (const struct usb_cdc_union_desc *)buf; ctx->control = usb_ifnum_to_if(usbdev, union_desc->bMasterInterface0); ctx->data = usb_ifnum_to_if(usbdev, union_desc->bSlaveInterface0); break; case USB_CDC_ETHERNET_TYPE: if (buf[0] < sizeof(*(ctx->ether_desc))) break; ctx->ether_desc = (const struct usb_cdc_ether_desc *)buf; break; case USB_CDC_NCM_TYPE: if (buf[0] < sizeof(*(ctx->func_desc))) break; ctx->func_desc = (const struct usb_cdc_ncm_desc *)buf; break; default: break; } } temp = buf[0]; buf += temp; buflen -= temp; } /* check if we got everything */ if ((ctx->control == NULL) || (ctx->data == NULL) || (ctx->ether_desc == NULL) || (ctx->control != intf)) goto error; pipe_data->usbdev = usb_get_dev(usbdev); pipe_data->usb_ld = usb_ld; pipe_data->disconnected = 0; pipe_data->state = STATE_RESUMED; /* claim interfaces, if any */ temp = usb_driver_claim_interface(usbdrv, ctx->data, pipe_data); if (temp) goto error; iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber; /* reset data interface */ temp = usb_set_interface(usbdev, iface_no, 0); if (temp) goto error2; /* initialize data interface */ if (cdc_ncm_setup(pipe_data)) goto error2; /* configure data interface */ temp = usb_set_interface(usbdev, iface_no, 1);//.........这里部分代码省略.........
开发者ID:BigBot96,项目名称:android_kernel_samsung_gts2wifi,代码行数:101,
示例14: usbnet_generic_cdc_bind//.........这里部分代码省略......... dev_dbg(&intf->dev, "extra MDLM descriptor/n"); goto bad_desc; } desc = (void *)buf; if (desc->bLength != sizeof(*desc)) goto bad_desc; if (memcmp(&desc->bGUID, mbm_guid, 16)) goto bad_desc; break; case USB_CDC_MDLM_DETAIL_TYPE: if (detail) { dev_dbg(&intf->dev, "extra MDLM detail descriptor/n"); goto bad_desc; } detail = (void *)buf; if (detail->bGuidDescriptorType == 0) { if (detail->bLength < (sizeof(*detail) + 1)) goto bad_desc; } else goto bad_desc; break; }next_desc: len -= buf [0]; /* bLength */ buf += buf [0]; } /* Microsoft ActiveSync based and some regular RNDIS devices lack the * CDC descriptors, so we'll hard-wire the interfaces and not check * for descriptors. * * Some Android RNDIS devices have a CDC Union descriptor pointing * to non-existing interfaces. Ignore that and attempt the same * hard-wired 0 and 1 interfaces. */ if (rndis && (!info->u || android_rndis_quirk)) { info->control = usb_ifnum_to_if(dev->udev, 0); info->data = usb_ifnum_to_if(dev->udev, 1); if (!info->control || !info->data || info->control != intf) { dev_dbg(&intf->dev, "rndis: master #0/%p slave #1/%p/n", info->control, info->data); goto bad_desc; } } else if (!info->header || !info->u || (!rndis && !info->ether)) { dev_dbg(&intf->dev, "missing cdc %s%s%sdescriptor/n", info->header ? "" : "header ", info->u ? "" : "union ", info->ether ? "" : "ether "); goto bad_desc; } /* claim data interface and set it up ... with side effects. * network traffic can't flow until an altsetting is enabled. */ status = usb_driver_claim_interface(driver, info->data, dev); if (status < 0) return status; status = usbnet_get_endpoints(dev, info->data); if (status < 0) { /* ensure immediate exit from usbnet_disconnect */ usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); return status; } /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */ dev->status = NULL; if (info->control->cur_altsetting->desc.bNumEndpoints == 1) { struct usb_endpoint_descriptor *desc; dev->status = &info->control->cur_altsetting->endpoint [0]; desc = &dev->status->desc; if (!usb_endpoint_is_int_in(desc) || (le16_to_cpu(desc->wMaxPacketSize) < sizeof(struct usb_cdc_notification)) || !desc->bInterval) { dev_dbg(&intf->dev, "bad notification endpoint/n"); dev->status = NULL; } } if (rndis && !dev->status) { dev_dbg(&intf->dev, "missing RNDIS status endpoint/n"); usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); return -ENODEV; } return 0;bad_desc: dev_info(&dev->udev->dev, "bad CDC descriptors/n"); return -ENODEV;}
开发者ID:nannaniel,项目名称:linux-2.6.35.3-imx28,代码行数:101,
示例15: btusb_probe//.........这里部分代码省略......... if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) return -ENODEV; data->cmdreq_type = USB_TYPE_CLASS; data->udev = interface_to_usbdev(intf); data->intf = intf; spin_lock_init(&data->lock); INIT_WORK(&data->work, btusb_work); INIT_WORK(&data->waker, btusb_waker); spin_lock_init(&data->txlock); init_usb_anchor(&data->tx_anchor); init_usb_anchor(&data->intr_anchor); init_usb_anchor(&data->bulk_anchor); init_usb_anchor(&data->isoc_anchor); init_usb_anchor(&data->deferred); hdev = hci_alloc_dev(); if (!hdev) return -ENOMEM; hdev->bus = HCI_USB; hci_set_drvdata(hdev, data); data->hdev = hdev; SET_HCIDEV_DEV(hdev, &intf->dev); hdev->open = btusb_open; hdev->close = btusb_close; hdev->flush = btusb_flush; hdev->send = btusb_send_frame; hdev->notify = btusb_notify; if (id->driver_info & BTUSB_BCM92035) hdev->setup = btusb_setup_bcm92035; if (id->driver_info & BTUSB_INTEL) hdev->setup = btusb_setup_intel; /* Interface numbers are hardcoded in the specification */ data->isoc = usb_ifnum_to_if(data->udev, 1); if (!reset) set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) { if (!disable_scofix) set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks); } if (id->driver_info & BTUSB_BROKEN_ISOC) data->isoc = NULL; if (id->driver_info & BTUSB_DIGIANSWER) { data->cmdreq_type = USB_TYPE_VENDOR; set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); } if (id->driver_info & BTUSB_CSR) { struct usb_device *udev = data->udev; /* Old firmware would otherwise execute USB reset */ if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117) set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); } if (id->driver_info & BTUSB_SNIFFER) { struct usb_device *udev = data->udev; /* New sniffer firmware has crippled HCI interface */ if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997) set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); data->isoc = NULL; } if (data->isoc) { err = usb_driver_claim_interface(&btusb_driver, data->isoc, data); if (err < 0) { hci_free_dev(hdev); return err; } } err = hci_register_dev(hdev); if (err < 0) { hci_free_dev(hdev); return err; } usb_set_intfdata(intf, data); usb_enable_autosuspend(data->udev); return 0;}
开发者ID:Skin1980,项目名称:bass-MM,代码行数:101,
示例16: if_usb_probestatic int __devinit if_usb_probe(struct usb_interface *intf, const struct usb_device_id *id){ struct usb_host_interface *data_desc; struct usb_link_device *usb_ld = (struct usb_link_device *)id->driver_info; struct link_device *ld = &usb_ld->ld; struct usb_interface *data_intf; struct usb_device *usbdev = interface_to_usbdev(intf); struct device *dev, *ehci_dev, *root_hub; struct if_usb_devdata *pipe; struct urb *urb; int i; int j; int dev_id; int err; /* To detect usb device order probed */ dev_id = intf->cur_altsetting->desc.bInterfaceNumber; if (dev_id >= IF_USB_DEVNUM_MAX) { dev_err(&intf->dev, "Device id %d cannot support/n", dev_id); return -EINVAL; } if (!usb_ld) { dev_err(&intf->dev, "if_usb device doesn't be allocated/n"); err = ENOMEM; goto out; } mif_info("probe dev_id=%d usb_device_id(0x%p), usb_ld (0x%p)/n", dev_id, id, usb_ld); usb_ld->usbdev = usbdev; usb_get_dev(usbdev); for (i = 0; i < IF_USB_DEVNUM_MAX; i++) { data_intf = usb_ifnum_to_if(usbdev, i); /* remap endpoint of RAW to no.1 for LTE modem */ if (i == 0) pipe = &usb_ld->devdata[1]; else if (i == 1) pipe = &usb_ld->devdata[0]; else pipe = &usb_ld->devdata[i]; pipe->disconnected = 0; pipe->data_intf = data_intf; data_desc = data_intf->cur_altsetting; /* Endpoints */ if (usb_pipein(data_desc->endpoint[0].desc.bEndpointAddress)) { pipe->rx_pipe = usb_rcvbulkpipe(usbdev, data_desc->endpoint[0].desc.bEndpointAddress); pipe->tx_pipe = usb_sndbulkpipe(usbdev, data_desc->endpoint[1].desc.bEndpointAddress); pipe->rx_buf_size = 1024*4; } else { pipe->rx_pipe = usb_rcvbulkpipe(usbdev, data_desc->endpoint[1].desc.bEndpointAddress); pipe->tx_pipe = usb_sndbulkpipe(usbdev, data_desc->endpoint[0].desc.bEndpointAddress); pipe->rx_buf_size = 1024*4; } if (i == 0) { dev_info(&usbdev->dev, "USB IF USB device found/n"); } else { err = usb_driver_claim_interface(&if_usb_driver, data_intf, usb_ld); if (err < 0) { mif_err("failed to cliam usb interface/n"); goto out; } } usb_set_intfdata(data_intf, usb_ld); usb_ld->dev_count++; pm_suspend_ignore_children(&data_intf->dev, true); for (j = 0; j < URB_COUNT; j++) { urb = usb_alloc_urb(0, GFP_KERNEL); if (!urb) { mif_err("alloc urb fail/n"); err = -ENOMEM; goto out2; } urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; urb->transfer_buffer = usb_alloc_coherent(usbdev, pipe->rx_buf_size, GFP_KERNEL, &urb->transfer_dma); if (!urb->transfer_buffer) { mif_err( "Failed to allocate transfer buffer/n"); usb_free_urb(urb);//.........这里部分代码省略.........
开发者ID:gadido30,项目名称:bigfatwifi,代码行数:101,
示例17: mdc800_usb_probe/* * Callback to search the Mustek MDC800 on the USB Bus */static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum, const struct usb_device_id *id){ int i,j; struct usb_interface_descriptor *intf_desc; int irq_interval=0; dbg ("(mdc800_usb_probe) called."); if (mdc800->dev != 0) { warn ("only one Mustek MDC800 is supported."); return 0; } if (dev->descriptor.bNumConfigurations != 1) { err ("probe fails -> wrong Number of Configuration"); return 0; } intf_desc=&dev->actconfig->interface[ifnum].altsetting[0]; if ( ( intf_desc->bInterfaceClass != 0xff ) || ( intf_desc->bInterfaceSubClass != 0 ) || ( intf_desc->bInterfaceProtocol != 0 ) || ( intf_desc->bNumEndpoints != 4) ) { err ("probe fails -> wrong Interface"); return 0; } /* Check the Endpoints */ for (i=0; i<4; i++) { mdc800->endpoint[i]=-1; for (j=0; j<4; j++) { if (mdc800_endpoint_equals (&intf_desc->endpoint [j],&mdc800_ed [i])) { mdc800->endpoint[i]=intf_desc->endpoint [j].bEndpointAddress ; if (i==1) { irq_interval=intf_desc->endpoint [j].bInterval; } continue; } } if (mdc800->endpoint[i] == -1) { err ("probe fails -> Wrong Endpoints."); return 0; } } usb_driver_claim_interface (&mdc800_usb_driver, &dev->actconfig->interface[ifnum], mdc800); if (usb_set_interface (dev, ifnum, 0) < 0) { err ("MDC800 Configuration fails."); return 0; } info ("Found Mustek MDC800 on USB."); down (&mdc800->io_lock); mdc800->dev=dev; mdc800->open=0; /* Setup URB Structs */ FILL_INT_URB ( mdc800->irq_urb, mdc800->dev, usb_rcvintpipe (mdc800->dev,mdc800->endpoint [1]), mdc800->irq_urb_buffer, 8, mdc800_usb_irq, mdc800, irq_interval ); FILL_BULK_URB ( mdc800->write_urb, mdc800->dev, usb_sndbulkpipe (mdc800->dev, mdc800->endpoint[0]), mdc800->write_urb_buffer, 8, mdc800_usb_write_notify, mdc800 ); FILL_BULK_URB ( mdc800->download_urb,//.........这里部分代码省略.........
开发者ID:NieHao,项目名称:Tomato-RAF,代码行数:101,
示例18: usbpn_probeint usbpn_probe(struct usb_interface *intf, const struct usb_device_id *id){ static const char ifname[] = "usbpn%d"; const struct usb_cdc_union_desc *union_header = NULL; const struct usb_host_interface *data_desc; struct usb_interface *data_intf; struct usb_device *usbdev = interface_to_usbdev(intf); struct net_device *dev; struct usbpn_dev *pnd; u8 *data; int phonet = 0; int len, err; data = intf->altsetting->extra; len = intf->altsetting->extralen; while (len >= 3) { u8 dlen = data[0]; if (dlen < 3) return -EINVAL; /* bDescriptorType */ if (data[1] == USB_DT_CS_INTERFACE) { /* bDescriptorSubType */ switch (data[2]) { case USB_CDC_UNION_TYPE: if (union_header || dlen < 5) break; union_header = (struct usb_cdc_union_desc *)data; break; case 0xAB: phonet = 1; break; } } data += dlen; len -= dlen; } if (!union_header || !phonet) return -EINVAL; data_intf = usb_ifnum_to_if(usbdev, union_header->bSlaveInterface0); if (data_intf == NULL) return -ENODEV; /* Data interface has one inactive and one active setting */ if (data_intf->num_altsetting != 2) return -EINVAL; if (data_intf->altsetting[0].desc.bNumEndpoints == 0 && data_intf->altsetting[1].desc.bNumEndpoints == 2) data_desc = data_intf->altsetting + 1; else if (data_intf->altsetting[0].desc.bNumEndpoints == 2 && data_intf->altsetting[1].desc.bNumEndpoints == 0) data_desc = data_intf->altsetting; else return -EINVAL; dev = alloc_netdev(sizeof(*pnd) + sizeof(pnd->urbs[0]) * rxq_size, ifname, usbpn_setup); if (!dev) return -ENOMEM; pnd = netdev_priv(dev); SET_NETDEV_DEV(dev, &intf->dev); netif_stop_queue(dev); pnd->dev = dev; pnd->usb = usb_get_dev(usbdev); pnd->intf = intf; pnd->data_intf = data_intf; spin_lock_init(&pnd->tx_lock); spin_lock_init(&pnd->rx_lock); /* Endpoints */ if (usb_pipein(data_desc->endpoint[0].desc.bEndpointAddress)) { pnd->rx_pipe = usb_rcvbulkpipe(usbdev, data_desc->endpoint[0].desc.bEndpointAddress); pnd->tx_pipe = usb_sndbulkpipe(usbdev, data_desc->endpoint[1].desc.bEndpointAddress); } else { pnd->rx_pipe = usb_rcvbulkpipe(usbdev, data_desc->endpoint[1].desc.bEndpointAddress); pnd->tx_pipe = usb_sndbulkpipe(usbdev, data_desc->endpoint[0].desc.bEndpointAddress); } pnd->active_setting = data_desc - data_intf->altsetting; err = usb_driver_claim_interface(&usbpn_driver, data_intf, pnd); if (err) goto out; /* Force inactive mode until the network device is brought UP */ usb_set_interface(usbdev, union_header->bSlaveInterface0, !pnd->active_setting); usb_set_intfdata(intf, pnd); err = register_netdev(dev); if (err) { usb_driver_release_interface(&usbpn_driver, data_intf); goto out;//.........这里部分代码省略.........
开发者ID:Atrix-Dev-Team,项目名称:kernel-MB860,代码行数:101,
示例19: qmi_wwan_bindstatic int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf){ int status = -1; u8 *buf = intf->cur_altsetting->extra; int len = intf->cur_altsetting->extralen; struct usb_interface_descriptor *desc = &intf->cur_altsetting->desc; struct usb_cdc_union_desc *cdc_union; struct usb_cdc_ether_desc *cdc_ether; struct usb_driver *driver = driver_of(intf); struct qmi_wwan_state *info = (void *)&dev->data; struct usb_cdc_parsed_header hdr; BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) < sizeof(struct qmi_wwan_state))); /* set up initial state */ info->control = intf; info->data = intf; /* and a number of CDC descriptors */ cdc_parse_cdc_header(&hdr, intf, buf, len); cdc_union = hdr.usb_cdc_union_desc; cdc_ether = hdr.usb_cdc_ether_desc; /* Use separate control and data interfaces if we found a CDC Union */ if (cdc_union) { info->data = usb_ifnum_to_if(dev->udev, cdc_union->bSlaveInterface0); if (desc->bInterfaceNumber != cdc_union->bMasterInterface0 || !info->data) { dev_err(&intf->dev, "bogus CDC Union: master=%u, slave=%u/n", cdc_union->bMasterInterface0, cdc_union->bSlaveInterface0); goto err; } } /* errors aren't fatal - we can live with the dynamic address */ if (cdc_ether) { dev->hard_mtu = le16_to_cpu(cdc_ether->wMaxSegmentSize); usbnet_get_ethernet_addr(dev, cdc_ether->iMACAddress); } /* claim data interface and set it up */ if (info->control != info->data) { status = usb_driver_claim_interface(driver, info->data, dev); if (status < 0) goto err; } status = qmi_wwan_register_subdriver(dev); if (status < 0 && info->control != info->data) { usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); } /* Never use the same address on both ends of the link, even if the * buggy firmware told us to. Or, if device is assigned the well-known * buggy firmware MAC address, replace it with a random address, */ if (ether_addr_equal(dev->net->dev_addr, default_modem_addr) || ether_addr_equal(dev->net->dev_addr, buggy_fw_addr)) eth_hw_addr_random(dev->net); /* make MAC addr easily distinguishable from an IP header */ if (possibly_iphdr(dev->net->dev_addr)) { dev->net->dev_addr[0] |= 0x02; /* set local assignment bit */ dev->net->dev_addr[0] &= 0xbf; /* clear "IP" bit */ } dev->net->netdev_ops = &qmi_wwan_netdev_ops;err: return status;}
开发者ID:hellocccat,项目名称:ath,代码行数:74,
示例20: qmi_wwan_bind//.........这里部分代码省略......... switch (buf[2]) { case USB_CDC_HEADER_TYPE: if (found & 1 << USB_CDC_HEADER_TYPE) { dev_dbg(&intf->dev, "extra CDC header/n"); goto err; } if (h->bLength != sizeof(struct usb_cdc_header_desc)) { dev_dbg(&intf->dev, "CDC header len %u/n", h->bLength); goto err; } break; case USB_CDC_UNION_TYPE: if (found & 1 << USB_CDC_UNION_TYPE) { dev_dbg(&intf->dev, "extra CDC union/n"); goto err; } if (h->bLength != sizeof(struct usb_cdc_union_desc)) { dev_dbg(&intf->dev, "CDC union len %u/n", h->bLength); goto err; } cdc_union = (struct usb_cdc_union_desc *)buf; break; case USB_CDC_ETHERNET_TYPE: if (found & 1 << USB_CDC_ETHERNET_TYPE) { dev_dbg(&intf->dev, "extra CDC ether/n"); goto err; } if (h->bLength != sizeof(struct usb_cdc_ether_desc)) { dev_dbg(&intf->dev, "CDC ether len %u/n", h->bLength); goto err; } cdc_ether = (struct usb_cdc_ether_desc *)buf; break; } /* Remember which CDC functional descriptors we've seen. Works * for all types we care about, of which USB_CDC_ETHERNET_TYPE * (0x0f) is the highest numbered */ if (buf[2] < 32) found |= 1 << buf[2];next_desc: len -= h->bLength; buf += h->bLength; } /* Use separate control and data interfaces if we found a CDC Union */ if (cdc_union) { info->data = usb_ifnum_to_if(dev->udev, cdc_union->bSlaveInterface0); if (desc->bInterfaceNumber != cdc_union->bMasterInterface0 || !info->data) { dev_err(&intf->dev, "bogus CDC Union: master=%u, slave=%u/n", cdc_union->bMasterInterface0, cdc_union->bSlaveInterface0); goto err; } } /* errors aren't fatal - we can live with the dynamic address */ if (cdc_ether) { dev->hard_mtu = le16_to_cpu(cdc_ether->wMaxSegmentSize); usbnet_get_ethernet_addr(dev, cdc_ether->iMACAddress); } /* claim data interface and set it up */ if (info->control != info->data) { status = usb_driver_claim_interface(driver, info->data, dev); if (status < 0) goto err; } status = qmi_wwan_register_subdriver(dev); if (status < 0 && info->control != info->data) { usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); } /* Never use the same address on both ends of the link, even if the * buggy firmware told us to. Or, if device is assigned the well-known * buggy firmware MAC address, replace it with a random address, */ if (ether_addr_equal(dev->net->dev_addr, default_modem_addr) || ether_addr_equal(dev->net->dev_addr, buggy_fw_addr)) eth_hw_addr_random(dev->net); /* make MAC addr easily distinguishable from an IP header */ if (possibly_iphdr(dev->net->dev_addr)) { dev->net->dev_addr[0] |= 0x02; /* set local assignment bit */ dev->net->dev_addr[0] &= 0xbf; /* clear "IP" bit */ } dev->net->netdev_ops = &qmi_wwan_netdev_ops;err: return status;}
开发者ID:Taran2ul,项目名称:rt-n56u,代码行数:101,
示例21: usbnet_generic_cdc_bind//.........这里部分代码省略......... "master #%u/%p slave #%u/%p/n", info->u->bMasterInterface0, info->control, info->u->bSlaveInterface0, info->data); goto bad_desc; } if (info->control != intf) { dev_dbg(&intf->dev, "bogus CDC Union/n"); /* Ambit USB Cable Modem (and maybe others) * interchanges master and slave interface. */ if (info->data == intf) { info->data = info->control; info->control = intf; } else goto bad_desc; } /* a data interface altsetting does the real i/o */ d = &info->data->cur_altsetting->desc; if (d->bInterfaceClass != USB_CLASS_CDC_DATA) { dev_dbg(&intf->dev, "slave class %u/n", d->bInterfaceClass); goto bad_desc; } break; case USB_CDC_ETHERNET_TYPE: if (info->ether) { dev_dbg(&intf->dev, "extra CDC ether/n"); goto bad_desc; } info->ether = (void *) buf; if (info->ether->bLength != sizeof *info->ether) { dev_dbg(&intf->dev, "CDC ether len %u/n", info->ether->bLength); goto bad_desc; } dev->hard_mtu = le16_to_cpu( info->ether->wMaxSegmentSize); /* because of Zaurus, we may be ignoring the host * side link address we were given. */ break; }next_desc: len -= buf [0]; /* bLength */ buf += buf [0]; } if (!info->header || !info->u || (!rndis && !info->ether)) { dev_dbg(&intf->dev, "missing cdc %s%s%sdescriptor/n", info->header ? "" : "header ", info->u ? "" : "union ", info->ether ? "" : "ether "); goto bad_desc; } /* claim data interface and set it up ... with side effects. * network traffic can't flow until an altsetting is enabled. */ status = usb_driver_claim_interface(driver, info->data, dev); if (status < 0) return status; status = usbnet_get_endpoints(dev, info->data); if (status < 0) { /* ensure immediate exit from usbnet_disconnect */ usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); return status; } /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */ dev->status = NULL; if (info->control->cur_altsetting->desc.bNumEndpoints == 1) { struct usb_endpoint_descriptor *desc; dev->status = &info->control->cur_altsetting->endpoint [0]; desc = &dev->status->desc; if (desc->bmAttributes != USB_ENDPOINT_XFER_INT || !(desc->bEndpointAddress & USB_DIR_IN) || (le16_to_cpu(desc->wMaxPacketSize) < sizeof(struct usb_cdc_notification)) || !desc->bInterval) { dev_dbg(&intf->dev, "bad notification endpoint/n"); dev->status = NULL; } } if (rndis && !dev->status) { dev_dbg(&intf->dev, "missing RNDIS status endpoint/n"); usb_set_intfdata(info->data, NULL); usb_driver_release_interface(driver, info->data); return -ENODEV; } return 0;bad_desc: dev_info(&dev->udev->dev, "bad CDC descriptors/n"); return -ENODEV;}
开发者ID:BackupTheBerlios,项目名称:tew632-brp-svn,代码行数:101,
注:本文中的usb_driver_claim_interface函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ usb_driver_release_interface函数代码示例 C++ usb_disabled函数代码示例 |