Advertisement
xerpi

Vita MTP

Jan 12th, 2017
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.22 KB | None | 0 0
  1.  
  2. #define VITA_PID 0x04E4
  3.  
  4. #define USB_DRIVERNAME "VITA_MTP"
  5.  
  6. /* Endpoint blocks */
  7. static
  8. struct SceUdcdEndpoint endpoints[4] = {
  9.     {
  10.         0, /* Control endpoint */
  11.         0,
  12.         0,
  13.         0
  14.     },
  15.     {
  16.         0x80, /* In */
  17.         1,
  18.         0,
  19.         0
  20.     },
  21.     {
  22.         0, /* Out */
  23.         2,
  24.         0,
  25.         0
  26.     },
  27.     {
  28.         0x80, /* In */
  29.         3,
  30.         0,
  31.         0
  32.     }
  33. };
  34.  
  35. /* Interfaces */
  36. static
  37. struct SceUdcdInterface interfaces[1] = {
  38.     { -1, 0, 1 }
  39. };
  40.  
  41. /* String descriptor */
  42. static
  43. struct SceUdcdStringDescriptor string_descriptors[2] = {
  44.     {
  45.         18,
  46.         USB_DT_STRING,
  47.         { 'V', 'i', 't', 'a', ' ',  'M', 'T', 'P' }
  48.     },
  49.     {
  50.         0,
  51.         USB_DT_STRING
  52.     }
  53. };
  54.  
  55. /* HI-Speed device descriptor */
  56. static
  57. struct SceUdcdDeviceDescriptor devdesc_hi =
  58. {
  59.     USB_DT_DEVICE_SIZE,
  60.     USB_DT_DEVICE,
  61.     0x200,         /* bcdUSB */
  62.     USB_CLASS_PER_INTERFACE,  /* bDeviceClass */
  63.     0,             /* bDeviceSubClass */
  64.     0,             /* bDeviceProtocol */
  65.     64,            /* bMaxPacketSize0 */
  66.     0,             /* idProduct */
  67.     0,             /* idVendor */
  68.     0x100,         /* bcdDevice */
  69.     0,             /* iManufacturer */
  70.     0,             /* iProduct */
  71.     0,             /* iSerialNumber */
  72.     1              /* bNumConfigurations */
  73. };
  74.  
  75. /* Hi-Speed endpoint descriptors */
  76. static
  77. struct SceUdcdEndpointDescriptor endpdesc_hi[4] =
  78. {
  79.     {
  80.         USB_DT_ENDPOINT_SIZE ,
  81.         USB_DT_ENDPOINT,
  82.         0x81,           /* bEndpointAddress */
  83.         USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
  84.         0x0200,         /* wMaxPacketSize */
  85.         0           /* bInterval */
  86.     },
  87.     {
  88.         USB_DT_ENDPOINT_SIZE ,
  89.         USB_DT_ENDPOINT,
  90.         0x01,           /* bEndpointAddress */
  91.         USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
  92.         0x0200,         /* wMaxPacketSize */
  93.         0           /* bInterval */
  94.     },
  95.     {
  96.         USB_DT_ENDPOINT_SIZE ,
  97.         USB_DT_ENDPOINT,
  98.         0x82,               /* bEndpointAddress */
  99.         USB_ENDPOINT_TYPE_INTERRUPT,    /* bmAttributes */
  100.         0x001c,             /* wMaxPacketSize */
  101.         0x06                /* bInterval */
  102.     },
  103.     {
  104.         0
  105.     }
  106. };
  107.  
  108. /* Hi-Speed interface descriptor */
  109. static
  110. struct SceUdcdInterfaceDescriptor interdesc_hi[2] =
  111. {
  112.     {
  113.         USB_DT_INTERFACE_SIZE,
  114.         USB_DT_INTERFACE,
  115.         0,      /* bInterfaceNumber */
  116.         0,      /* bAlternateSetting */
  117.         3,      /* bNumEndpoints */
  118.         USB_CLASS_VENDOR_SPEC ,   /* bInterfaceClass */
  119.         0xFF,   /* bInterfaceSubClass */
  120.         0x00,   /* bInterfaceProtocol */
  121.         1,      /* iInterface */
  122.         &endpdesc_hi[0], /* endpoints */
  123.         NULL,
  124.         0
  125.     },
  126.     {
  127.         0
  128.     }
  129. };
  130.  
  131. /* Hi-Speed settings */
  132. static
  133. struct SceUdcdInterfaceSettings settings_hi[1] =
  134. {
  135.     {
  136.         &interdesc_hi[0],
  137.         0,
  138.         1
  139.     }
  140. };
  141.  
  142. /* Hi-Speed configuration descriptor */
  143. static
  144. struct SceUdcdConfigDescriptor confdesc_hi =
  145. {
  146.     USB_DT_CONFIG_SIZE,
  147.     USB_DT_CONFIG,
  148.     (USB_DT_INTERFACE_SIZE + USB_DT_CONFIG_SIZE + 3 * USB_DT_ENDPOINT_SIZE), /* wTotalLength */
  149.     1,      /* bNumInterfaces */
  150.     1,      /* bConfigurationValue */
  151.     0,      /* iConfiguration */
  152.     0xC0,   /* bmAttributes */
  153.     0,      /* bMaxPower */
  154.     &settings_hi[0]
  155. };
  156.  
  157.  
  158. /* Hi-Speed configuration */
  159. static
  160. struct SceUdcdConfiguration config_hi =
  161. {
  162.     &confdesc_hi,
  163.     &settings_hi[0],
  164.     &interdesc_hi[0],
  165.     &endpdesc_hi[0]
  166. };
  167.  
  168. /* Full-Speed device descriptor */
  169. static
  170. struct SceUdcdDeviceDescriptor devdesc_full =
  171. {
  172.     USB_DT_DEVICE_SIZE,
  173.     USB_DT_DEVICE,
  174.     0x200,         /* bcdUSB (should be 0x110 but Vita freezes otherwise) */
  175.     USB_CLASS_PER_INTERFACE,  /* bDeviceClass */
  176.     0,             /* bDeviceSubClass */
  177.     0,             /* bDeviceProtocol */
  178.     8,             /* bMaxPacketSize0 */
  179.     0,             /* idProduct */
  180.     0,             /* idVendor */
  181.     0x200,         /* bcdDevice */
  182.     0,             /* iManufacturer */
  183.     0,             /* iProduct */
  184.     0,             /* iSerialNumber */
  185.     1              /* bNumConfigurations */
  186. };
  187.  
  188. /* Full-Speed endpoint descriptors */
  189. static
  190. struct SceUdcdEndpointDescriptor endpdesc_full[4] =
  191. {
  192.     {
  193.         USB_DT_ENDPOINT_SIZE ,
  194.         USB_DT_ENDPOINT,
  195.         0x81,           /* bEndpointAddress */
  196.         USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
  197.         0x40,           /* wMaxPacketSize */
  198.         0           /* bInterval */
  199.     },
  200.     {
  201.         USB_DT_ENDPOINT_SIZE ,
  202.         USB_DT_ENDPOINT,
  203.         0x01,           /* bEndpointAddress */
  204.         USB_ENDPOINT_TYPE_BULK, /* bmAttributes */
  205.         0x40,           /* wMaxPacketSize */
  206.         0           /* bInterval */
  207.     },
  208.     {
  209.         USB_DT_ENDPOINT_SIZE ,
  210.         USB_DT_ENDPOINT,
  211.         0x82,               /* bEndpointAddress */
  212.         USB_ENDPOINT_TYPE_INTERRUPT,    /* bmAttributes */
  213.         0x001c,             /* wMaxPacketSize */
  214.         0x06                /* bInterval */
  215.     },
  216.     {
  217.         0
  218.     }
  219. };
  220.  
  221. /* Full-Speed interface descriptor */
  222. static
  223. struct SceUdcdInterfaceDescriptor interdesc_full[2] =
  224. {
  225.     {
  226.         USB_DT_INTERFACE_SIZE,
  227.         USB_DT_INTERFACE,
  228.         0,      /* bInterfaceNumber */
  229.         0,      /* bAlternateSetting */
  230.         3,      /* bNumEndpoints */
  231.         USB_CLASS_VENDOR_SPEC ,   /* bInterfaceClass */
  232.         0xFF,   /* bInterfaceSubClass */
  233.         0x00,   /* bInterfaceProtocol */
  234.         1,      /* iInterface */
  235.         &endpdesc_full[0], /* endpoints */
  236.         NULL,
  237.         0
  238.     },
  239.     {
  240.         0
  241.     }
  242. };
  243.  
  244.  
  245. /* Full-Speed settings */
  246. static
  247. struct SceUdcdInterfaceSettings settings_full[1] =
  248. {
  249.     {
  250.         &interdesc_full[0],
  251.         0,
  252.         1
  253.     }
  254. };
  255.  
  256. /* Full-Speed configuration descriptor */
  257. static
  258. struct SceUdcdConfigDescriptor confdesc_full =
  259. {
  260.     USB_DT_CONFIG_SIZE,
  261.     USB_DT_CONFIG,
  262.     (USB_DT_INTERFACE_SIZE + USB_DT_CONFIG_SIZE + 3 * USB_DT_ENDPOINT_SIZE), /* wTotalLength */
  263.     1,      /* bNumInterfaces */
  264.     1,      /* bConfigurationValue */
  265.     0,      /* iConfiguration */
  266.     0xC0,   /* bmAttributes */
  267.     0,      /* bMaxPower */
  268.     &settings_full[0]
  269. };
  270.  
  271. /* Full-Speed configuration */
  272. static
  273. struct SceUdcdConfiguration config_full =
  274. {
  275.     &confdesc_full,
  276.     &settings_full[0],
  277.     &interdesc_full[0],
  278.     &endpdesc_full[0]
  279. };
  280.  
  281. static struct SceUdcdDriver usb_driver = {
  282.     .driverName     = USB_DRIVERNAME,
  283.     .numEndpoints       = 4,
  284.     .endpoints      = endpoints,
  285.     .interface      = interfaces,
  286.     .descriptor_hi      = &devdesc_hi,
  287.     .configuration_hi   = &config_hi,
  288.     .descriptor     = &devdesc_full,
  289.     .configuration      = &config_full,
  290.     .stringDescriptorsUnk0  = string_descriptors,
  291.     .stringDescriptorsUnk1  = string_descriptors,
  292.     .stringDescriptorsUnk2  = string_descriptors,
  293.     .processRequest     = usb_driver_process_request,
  294.     .changeSetting      = usb_driver_change_setting,
  295.     .attach         = usb_driver_attach,
  296.     .detach         = usb_driver_detach,
  297.     .configure      = usb_driver_configure,
  298.     .start          = usb_driver_start,
  299.     .stop           = usb_driver_stop,
  300.     .unk1           = 0,
  301.     .unk2           = 0,
  302.     .link           = NULL
  303. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement