Re: [PATCH 125/144] usb: gadget: g_ncm added

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





> Date: Thursday, January 6, 2011, 3:50 PM
> From: Yauheni Kaliuta <yauheni.kaliuta@xxxxxxxxx>
> 

> +/* DO NOT REUSE THESE IDs with a protocol-incompatible
> driver!!  Ever!!

Grr.  It seems that's exactly what this does.

You're using the CDC ECM Id for everything, which
is (as it says) *VERY* incorrect.

Methinks each of g_ncm, g_eem, and g_cdc (ecm?)
lso g
should have their own source file, own Kconfig
engry,and own product Ids...  Use the Linux-USB
vendor ID. except where IDs are already assigned.
and valid...

> + * Instead:  allocate your own, using normal USB-IF  procedures.

which in this case involve going through Greg...
> + */
> +
> +/* Thanks to NetChip Technologies for donating this
> product ID.
> + * It's for devices with only CDC Ethernet
> configurations.

  HIGHLIGHT!!!!!  NOT NCM!!

> + */
> +#define CDC_VENDOR_NUM   
>     0x0525    /* NetChip */
> +#define CDC_PRODUCT_NUM   
>     0xa4a1    /* Linux-USB
> Ethernet Gadget */
> +
> +/*-------------------------------------------------------------------------*/
> +
> +static struct usb_device_descriptor device_desc = {
> +    .bLength =   
>     sizeof device_desc,
> +    .bDescriptorType =   
> USB_DT_DEVICE,
> +
> +    .bcdUSB =   
>     cpu_to_le16 (0x0200)


... which has only ever indicated ECM,
never NCM.  Systems in the field will be
confused if they talk ECM to this device
and get errors.

> +
> +    .bDeviceClass =   
>     USB_CLASS_COMM,
> +    .bDeviceSubClass =   

> +

> +};
> +
> +static const struct usb_descriptor_header *otg_desc[] = {
> +    (struct usb_descriptor_header *)
> &otg_descriptor,
> +    NULL,
> +};
> +
> +
> +/* string IDs are assigned dynamically */
> +
> +#define STRING_MANUFACTURER_IDX   
>     0
> +#define STRING_PRODUCT_IDX   
>     1
> +
> +static char manufacturer[50];
> +
> +static struct usb_string strings_dev[] = {
> +    [STRING_MANUFACTURER_IDX].s =
> manufacturer,
> +    [STRING_PRODUCT_IDX].s = DRIVER_DESC,
> +    {  } /* end of list */
> +};
> +
> +static struct usb_gadget_strings stringtab_dev = {
> +    .language    =
> 0x0409,    /* en-us */
> +    .strings    =
> strings_dev,
> +};
> +
> +static struct usb_gadget_strings *dev_strings[] = {
> +    &stringtab_dev,
> +    NULL,
> +};
> +
> +static u8 hostaddr[ETH_ALEN];
> +
> +/*-------------------------------------------------------------------------*/
> +
> +static int __init ncm_do_config(struct usb_configuration
> *c)
> +{
> +    /* FIXME alloc iConfiguration string,
> set it in c->strings */
> +
> +    if
> (gadget_is_otg(c->cdev->gadget)) {
> +        c->descriptors =
> otg_desc;
> +        c->bmAttributes
> |= USB_CONFIG_ATT_WAKEUP;
> +    }
> +
> +    return ncm_bind_config(c, hostaddr);
> +}
> +
> +static struct usb_configuration ncm_config_driver = {
> +    /* .label = f(hardware) */
> +    .label   
>         = "CDC Ethernet
> (NCM)",

No, theses IDs and strings areor ECM not NCM.
> +    .bConfigurationValue   
> = 1,
> +    /* .iConfiguration = DYNAMIC */
> +    .bmAttributes   
>     = USB_CONFIG_ATT_SELFPOWER,
> +};
> +
> +/*-------------------------------------------------------------------------*/
> +
> +static int __init gncm_bind(struct usb_composite_dev
> *cdev)
> +{
> +    int   
>         gcnum;
> +    struct usb_gadget   
> *gadget = cdev->gadget;
> +    int   
>         status;
> +
> +    /* set up network link layer */
> +    status = gether_setup(cdev->gadget,
> hostaddr);
> +    if (status < 0)
> +        return status;
> +
> +    gcnum =
> usb_gadget_controller_number(gadget);
> +    if (gcnum >= 0)
> +       
> device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
> +    else {
> +        /* We assume that
> can_support_ecm() tells the truth;
> +         * but if
> the controller isn't recognized at all then
> +         * that
> assumption is a bit more likely to be wrong.
> +         */
> +       
> dev_warn(&gadget->dev,
> +       
>      "controller '%s' not
> recognized; trying %s\n",
> +       
>      gadget->name,
> +       
>      ncm_config_driver.label);
> +       
> device_desc.bcdDevice =
> +           
> cpu_to_le16(0x0300 | 0x0099);
> +    }
> +
> +
> +    /* Allocate string descriptor numbers
> ... note that string
> +     * contents can be overridden
> by the composite_dev glue.
> +     */
> +
> +    /* device descriptor strings:
> manufacturer, product */
> +    snprintf(manufacturer, sizeof
> manufacturer, "%s %s with %s",
> +       
> init_utsname()->sysname, init_utsname()->release,
> +        gadget->name);
> +    status = usb_string_id(cdev);
> +    if (status < 0)
> +        goto fail;
> +    strings_dev[STRING_MANUFACTURER_IDX].id
> = status;
> +    device_desc.iManufacturer = status;
> +
> +    status = usb_string_id(cdev);
> +    if (status < 0)
> +        goto fail;
> +    strings_dev[STRING_PRODUCT_IDX].id =
> status;
> +    device_desc.iProduct = status;
> +
> +    status = usb_add_config(cdev,
> &ncm_config_driver,
> +           
>     ncm_do_config);
> +    if (status < 0)
> +        goto fail;
> +
> +    dev_info(&gadget->dev, "%s\n",
> DRIVER_DESC);
> +
> +    return 0;
> +
> +fail:
> +    gether_cleanup();
> +    return status;
> +}
> +
> +static int __exit gncm_unbind(struct usb_composite_dev
> *cdev)
> +{
> +    gether_cleanup();
> +    return 0;
> +}
> +
> +static struct usb_composite_driver ncm_driver = {
> +    .name   
>     = "g_ncm",
> +    .dev   
>     = &device_desc,
> +    .strings    =
> dev_strings,
> +    .unbind   
>     = __exit_p(gncm_unbind),
> +};
> +
> +MODULE_DESCRIPTION(DRIVER_DESC);
> +MODULE_AUTHOR("Yauheni Kaliuta");
> +MODULE_LICENSE("GPL");
> +
> +static int __init init(void)
> +{
> +    return
> usb_composite_probe(&ncm_driver, gncm_bind);
> +}
> +module_init(init);
> +
> +static void __exit cleanup(void)
> +{
> +   
> usb_composite_unregister(&ncm_driver);
> +}
> +module_exit(cleanup);
> -- 
> 1.7.3.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-usb" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux