title: Call to ioctl() on a usb device using usbfs does not work
body: <p>I am trying to create my own driver for my Gamepad right now, I found out the original reason why I wanted to create it does not exist but I still want to do it for the experience. <strong>So please don't tell me there is a better way to do this than writing my own driver.</strong></p>
  
  <p>The part in kernelspace with the <em>ioctl</em> function that should be called is:</p>
  
  <pre><code>static int xpad_ioctl (struct usb_interface *intf, unsigned int code,void *buf) {
      //struct usb_xpad *xpad = usb_get_intfdata(intf);
      printk(KERN_INFO"(Ongy)IOCTL called\n");
  
      //if (_IOC_TYPE(code) != XPAD_IOMAGIC) return -ENOTTY;
      //if (_IOC_NR(code) &gt; XPAD_IOMAX) return -ENOTTY;
      switch(code){
          case XPAD_IORMAP:
              printk(KERN_INFO"(Ongy)IORMAP called\n");
              break;
          default:
             return -EINVAL;
      }
      return 0;
  }
  
  static struct usb_driver xpad_driver =
  {
      .name = "Cyborg-V5-driver",
      .probe = xpad_probe,
      .disconnect = xpad_disconnect,
      .unlocked_ioctl = xpad_ioctl,
      .id_table = xpad_table,
  };
  </code></pre>
  
  <p>The part in userspace to call it is (this is part of a Qt-application):</p>
  
  <pre><code>int openfile() {
      char *device = "/dev/bus/usb/005/009";
      printf("Opening device %s\n", device);
      return open(device, /*O_RDONLY*/O_WRONLY | O_NONBLOCK );
  }
  </code></pre>
  
  <p>[...] the closefile(int file_desc) is missing here, this and the openfile functions exist because of me not knowing one can call "::open()" when Qt overrides function calls.</p>
  
  <pre><code>void MainContainer::callioctl() {
      int file_desc, ret_val;
      errno = 0;
      file_desc = openfile();
      if (file_desc==-1){
          printf("Ioctl notcalled because of: error %s\n", strerror(errno));
      }
      else
      {
          errno = 0;
          //struct usbdevfs_getdriver* driver = (usbdevfs_getdriver*)malloc(sizeof(struct usbdevfs_getdriver));
          struct mappingpair* pair = (mappingpair*)malloc(sizeof(struct mappingpair));
          ret_val = ioctl(file_desc, XPAD_IORMAP, pair);
          //printf("Drivername %s\n", driver-&gt;driver);
          closefile(file_desc);
          if (ret_val==-1) printf("Ioctl failed with error %s\n", strerror(errno));
          else printf("Ioctl call successfull\n");
      }
  }
  </code></pre>
  
  <p>ok, the string to the file I open I get with a call to lsusb and change it by hand in the code, this is only for debugging and until I get the ioctl calls working</p>
  
  <p>When I call the callioctl() it prints:</p>
  
  <pre><code>Ioctl failed with error Unpassender IOCTL (I/O-Control) für das Gerät
  </code></pre>
  
  <p>The German part means "wrong ioctl (I/O-Control) for the device" and nothing appears in <code>dmesg</code>, that is why I think my ioctl function in the driver is not called.</p>