示例#1
0
static int __init psfreedom_bind(struct usb_gadget *gadget)
{
    struct psfreedom_device *dev;
    int err = 0;

    dev = kzalloc(sizeof(*dev), GFP_KERNEL);
    if (!dev) {
        return -ENOMEM;
    }

    spin_lock_init(&dev->lock);
    usb_gadget_set_selfpowered (gadget);
    dev->gadget = gadget;
    set_gadget_data(gadget, dev);

    /* preallocate control response and buffer */
    dev->req = alloc_ep_req(gadget->ep0, USB_BUFSIZ);
    if (!dev->req) {
        err = -ENOMEM;
        goto fail;
    }

    dev->req->complete = psfreedom_setup_complete;
    gadget->ep0->driver_data = dev;

    INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);

    /* Bind the hub and devices */
    err = hub_bind (gadget, dev);
    if (err < 0)
        goto fail;

    err = devices_bind (gadget, dev);
    if (err < 0)
        goto fail;

    DBG(dev, "psfreedom_bind finished ok\n");

    setup_timer(&psfreedom_state_machine_timer, psfreedom_state_machine_timeout,
                (unsigned long) gadget);

    psfreedom_disconnect (gadget);

    return 0;

fail:
    psfreedom_unbind(gadget);
    return err;
}
示例#2
0
static int psfreedom_bind(struct usb_gadget *gadget)
{
  struct psfreedom_device *dev;
  int err = 0;

  dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  if (!dev) {
    return -ENOMEM;
  }
  spin_lock_init(&dev->lock);
  usb_gadget_set_selfpowered (gadget);
  dev->gadget = gadget;
  set_gadget_data(gadget, dev);


  INFO(dev, "%s, version: " PSFREEDOM_VERSION " - " DRIVER_VERSION "\n",
      longname);

  load_firmware (dev, supported_firmwares[0].version);

  /* preallocate control response and buffer */
  dev->req = alloc_ep_req(gadget->ep0,
      max (sizeof (port3_config_desc),
          dev->port1_config_desc_size) + USB_BUFSIZ);
  if (!dev->req) {
    err = -ENOMEM;
    goto fail;
  }

  dev->req->complete = psfreedom_setup_complete;
  gadget->ep0->driver_data = dev;

  /* Bind the hub and devices */
  err = hub_bind (gadget, dev);
  if (err < 0)
    goto fail;

  err = devices_bind (gadget, dev);
  if (err < 0)
    goto fail;

  DBG(dev, "psfreedom_bind finished ok\n");

  setup_timer(&psfreedom_state_machine_timer, psfreedom_state_machine_timeout,
      (unsigned long) gadget);

  psfreedom_disconnect (gadget);

  /* Create the /proc filesystem */
  dev->proc_dir = proc_mkdir (PROC_DIR_NAME, NULL);
  if (dev->proc_dir) {
    printk(KERN_INFO "/proc/%s/ created\n", PROC_DIR_NAME);
    create_proc_fs (dev, &dev->proc_status_entry,
        PROC_STATUS_NAME, proc_status_read, NULL);
    create_proc_fs (dev, &dev->proc_version_entry,
        PROC_VERSION_NAME, proc_version_read, NULL);
    create_proc_fs (dev, &dev->proc_payload_entry,
        PROC_PAYLOAD_NAME, proc_payload_read, proc_payload_write);
    create_proc_fs (dev, &dev->proc_shellcode_entry,
        PROC_SHELLCODE_NAME, proc_shellcode_read, proc_shellcode_write);
    create_proc_fs (dev, &dev->proc_supported_firmwares_entry,
        PROC_SUPPORTED_FIRMWARES_NAME, proc_supported_firmwares_read, NULL);
    create_proc_fs (dev, &dev->proc_fw_version_entry,
        PROC_FW_VERSION_NAME, proc_fw_version_read, proc_fw_version_write);
    create_proc_fs (dev, &dev->proc_stage2_entry,
        PROC_STAGE2_NAME, NULL, proc_stage2_write);
    /* that's it for now..*/
  }

  /* By default don't use asbestos */
  dev->stage2_payload = NULL;
  dev->stage2_payload_size = 0;

  return 0;

 fail:
  psfreedom_unbind(gadget);
  return err;
}