Advertisement
Guest User

USB Host Mouse keyboar working

a guest
Jul 3rd, 2018
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define MAX_SENSE_LENGTH 24
  2. #define MAX_CDB_LENGTH 16
  3. #define MAX_TRANSFER_BUFFER_LENGTH 1 << 16
  4.  
  5. #define HID_MOUSE_NO_BUTTON         0x00
  6. #define HID_MOUSE_RIGHT_BUTTON      0x01
  7. #define HID_MOUSE_LEFT_BUTTON       0x02
  8.  
  9. #define HID_KEY_MOD_LEFT_CTRL       0x01
  10. #define HID_KEY_MOD_LEFT_SHIFT      0x02
  11. #define HID_KEY_MOD_LEFT_ALT        0x04
  12. #define HID_KEY_MOD_LEFT_META       0x08
  13. #define HID_KEY_MOD_RIGHT_CTRL      0x10
  14. #define HID_KEY_MOD_RIGHT_SHIFT     0x20
  15. #define HID_KEY_MOD_RIGHT_ALT       0x40
  16. #define HID_KEY_MOD_RIGHT_META      0x80
  17.  
  18. #define HID_KEY_NONE                0x00
  19. #define HID_KEY_ERROR_ROLLOVER      0x01
  20. #define HID_KEY_ERROR_POSTFAIL      0x02
  21. #define HID_KEY_ERROR_UNDEFINED     0x03
  22.  
  23. #define HID_KEY_A                   0x04
  24. #define HID_KEY_B                   0x05
  25. #define HID_KEY_C                   0x06
  26. #define HID_KEY_D                   0x07
  27. #define HID_KEY_E                   0x08
  28. #define HID_KEY_F                   0x09
  29. #define HID_KEY_G                   0x0a
  30. #define HID_KEY_H                   0x0b
  31. #define HID_KEY_I                   0x0c
  32. #define HID_KEY_J                   0x0d
  33. #define HID_KEY_K                   0x0e
  34. #define HID_KEY_L                   0x0f
  35. #define HID_KEY_M                   0x10
  36. #define HID_KEY_N                   0x11
  37. #define HID_KEY_O                   0x12
  38. #define HID_KEY_P                   0x13
  39. #define HID_KEY_Q                   0x14
  40. #define HID_KEY_R                   0x15
  41. #define HID_KEY_S                   0x16
  42. #define HID_KEY_T                   0x17
  43. #define HID_KEY_U                   0x18
  44. #define HID_KEY_V                   0x19
  45. #define HID_KEY_W                   0x1a
  46. #define HID_KEY_X                   0x1b
  47. #define HID_KEY_Y                   0x1c
  48. #define HID_KEY_Z                   0x1d
  49.  
  50. #define HID_KEY_1                   0x1e // 1 and !
  51. #define HID_KEY_2                   0x1f // 2 and @
  52. #define HID_KEY_3                   0x20 // 3 and #
  53. #define HID_KEY_4                   0x21 // 4 and $
  54. #define HID_KEY_5                   0x22 // 5 and %
  55. #define HID_KEY_6                   0x23 // 6 and ^
  56. #define HID_KEY_7                   0x24 // 7 and &
  57. #define HID_KEY_8                   0x25 // 8 and *
  58. #define HID_KEY_9                   0x26 // 9 and (
  59. #define HID_KEY_0                   0x27 // 0 and )
  60.  
  61. #define HID_KEY_EXCLAMATION         0x1e // 1 and !
  62. #define HID_KEY_AT                  0x1f // 2 and @
  63. #define HID_KEY_HASH                0x20 // 3 and #
  64. #define HID_KEY_DOLLAR              0x21 // 4 and $
  65. #define HID_KEY_PERCENT             0x22 // 5 and %
  66. #define HID_KEY_CIRCUMFLEX          0x23 // 6 and ^
  67. #define HID_KEY_AMPERSAND           0x24 // 7 and &
  68. #define HID_KEY_ASTERISK            0x25 // 8 and *
  69. #define HID_KEY_LEFTPARENTTHESIS    0x26 // 9 and (
  70. #define HID_KEY_RIGHTPARENTTHESIS   0x27 // 0 and )
  71.  
  72. #define HID_KEY_RETURN              0x28 // RETURN
  73. #define HID_KEY_ESC                 0x29 // ESCAPE
  74. #define HID_KEY_BACKSPACE           0x2a // Backspace
  75. #define HID_KEY_TAB                 0x2b // Tab
  76. #define HID_KEY_SPACE               0x2c // Spacebar
  77. #define HID_KEY_MINUS               0x2d // - and _
  78. #define HID_KEY_UNDERSCORE          0x2d // - and _
  79. #define HID_KEY_EQUAL               0x2e // = and +
  80. #define HID_KEY_PLUS                0x2e // = and +
  81. #define HID_KEY_LEFTBRACE           0x2f // [ and {
  82. #define HID_KEY_RIGHTBRACE          0x30 // ] and }
  83.  
  84. #define HID_KEY_BACKSLASH           0x31 // \ and |
  85. #define HID_KEY_PIPE                0x31 // \ and |
  86. #define HID_KEY_HASHTILDE           0x32 // Non-US # and ~
  87. #define HID_KEY_SEMICOLON           0x33 // ; and :
  88. #define HID_KEY_COLON               0x33 // ; and :
  89. #define HID_KEY_QUOTE               0x34 // ' and "
  90. #define HID_KEY_DOUBLE_QUOTE        0x34 // ' and "
  91. #define HID_KEY_GRAVE               0x35 // ` and ~
  92. #define HID_KEY_TILDE               0x35 // ` and ~
  93.  
  94. #define HID_KEY_COMMA               0x36 // , and <
  95. #define HID_KEY_LESSTHAN            0x36 // , and <
  96. #define HID_KEY_DOT                 0x37 // . and >
  97. #define HID_KEY_GREATETHAN          0x37 // . and >
  98. #define HID_KEY_SLASH               0x38 // / and ?
  99. #define HID_KEY_QUESTIONMARK        0x38 // / and ?
  100. #define HID_KEY_CAPSLOCK            0x39 // Caps Lock
  101.  
  102. #define HID_KEY_F1                  0x3a // F1
  103. #define HID_KEY_F2                  0x3b // F2
  104. #define HID_KEY_F3                  0x3c // F3
  105. #define HID_KEY_F4                  0x3d // F4
  106. #define HID_KEY_F5                  0x3e // F5
  107. #define HID_KEY_F6                  0x3f // F6
  108. #define HID_KEY_F7                  0x40 // F7
  109. #define HID_KEY_F8                  0x41 // F8
  110. #define HID_KEY_F9                  0x42 // F9
  111. #define HID_KEY_F10                 0x43 // F10
  112. #define HID_KEY_F11                 0x44 // F11
  113. #define HID_KEY_F12                 0x45 // F12
  114.  
  115. #define HID_KEY_PRINT               0x46 // Print Screen
  116. #define HID_KEY_SCROLLLOCK          0x47 // Scroll Lock
  117. #define HID_KEY_PAUSE               0x48 // Pause
  118. #define HID_KEY_INSERT              0x49 // Insert
  119. #define HID_KEY_HOME                0x4a // Home
  120. #define HID_KEY_PAGEUP              0x4b // Page Up
  121. #define HID_KEY_DELETE              0x4c // Delete Forward
  122. #define HID_KEY_END                 0x4d // End
  123. #define HID_KEY_PAGEDOWN            0x4e // Page Down
  124. #define HID_KEY_RIGHT               0x4f // Right Arrow
  125. #define HID_KEY_LEFT                0x50 // Left Arrow
  126. #define HID_KEY_DOWN                0x51 // Down Arrow
  127. #define HID_KEY_UP                  0x52 // Up Arrow
  128.  
  129. #define HID_KEY_NUMLOCK             0x53 // Num Lock and Clear
  130. #define HID_KEY_KEYPAD_SLASH        0x54 // Keypad /
  131. #define HID_KEY_KEYPAD_ASTERISK     0x55 // Keypad *
  132. #define HID_KEY_KEYPAD_MINUS        0x56 // Keypad -
  133. #define HID_KEY_KEYPAD_PLUS         0x57 // Keypad +
  134. #define HID_KEY_KEYPAD_ENTER        0x58 // Keypad ENTER
  135. #define HID_KEY_KEYPAD_1            0x59 // Keypad 1 and End
  136. #define HID_KEY_KEYPAD_2            0x5a // Keypad 2 and Down Arrow
  137. #define HID_KEY_KEYPAD_3            0x5b // Keypad 3 and PageDn
  138. #define HID_KEY_KEYPAD_4            0x5c // Keypad 4 and Left Arrow
  139. #define HID_KEY_KEYPAD_5            0x5d // Keypad 5
  140. #define HID_KEY_KEYPAD_6            0x5e // Keypad 6 and Right Arrow
  141. #define HID_KEY_KEYPAD_7            0x5f // Keypad 7 and Home
  142. #define HID_KEY_KEYPAD_8            0x60 // Keypad 8 and Up Arrow
  143. #define HID_KEY_KEYPAD_9            0x61 // Keypad 9 and Page Up
  144. #define HID_KEY_KEYPAD_0            0x62 // Keypad 0 and Insert
  145. #define HID_KEY_KEYPAD_DOT          0x63 // Keypad ./, and Delete
  146.  
  147. #define USB_HOST_TO_HOST_TIMEOUT 5
  148.  
  149. #ifdef MS_WINDOWS
  150. #include <windows.h>
  151. #include <ntddscsi.h>
  152.  
  153. #else
  154.  
  155. #include <stdio.h>
  156. #include <errno.h>
  157. #include <string.h>
  158. #include <stdarg.h>
  159. #include <fcntl.h>
  160. #include <sys/stat.h>
  161. #include <sys/types.h>
  162.  
  163. #include <scsi/sg.h>
  164. #include <sys/ioctl.h>
  165.  
  166. #define INTERFACE_ID (int)'S'    
  167. typedef int HANDLE;
  168. #define INVALID_HANDLE_VALUE -1
  169.  
  170. #define TRUE 1
  171. #define FALSE 0
  172.  
  173. typedef struct
  174. {
  175.     sg_io_hdr_t io_hdr;
  176.     unsigned char cdb[MAX_CDB_LENGTH];
  177.     unsigned char sense_buffer[MAX_SENSE_LENGTH];
  178. } SCSI_PASS_THROUGH_DIRECT;
  179. #endif
  180.  
  181. unsigned char usb_h2h_cdb_read[MAX_CDB_LENGTH]     = {217,40,100,0,0,0,0,0,0,0,0,0,0,0,79,84};
  182. unsigned char usb_h2h_cdb_write[MAX_CDB_LENGTH]    = {217,42,255,0,0,0,0,0,0,0,0,0,0,0,79,84};
  183. unsigned char usb_h2h_cdb_keyboard[MAX_CDB_LENGTH] = {217,52,  0,0,0,0,0,0,0,0,0,0,0,0,79,84};
  184. unsigned char usb_h2h_cdb_mouse[MAX_CDB_LENGTH]    = {217,51,  0,0,0,0,0,0,0,0,0,0,0,0,79,84};
  185.  
  186. typedef struct
  187. {
  188.     SCSI_PASS_THROUGH_DIRECT scsi_op;
  189.     HANDLE handle_dev
  190.     unsigned char* buffer;
  191.     unsigned int buffer_size;
  192.     unsigned char read_count;
  193. } USB_HOST_TO_HOST_TRANSFER;
  194.  
  195. int is_invalid_device_handle(HANDLE handle)
  196. {
  197.     #ifdef MS_WINDOWS
  198.     return (INVALID_HANDLE_VALUE == handle);
  199.     #else
  200.     return (handle < 0);
  201.     #endif
  202. }
  203.  
  204. void close_device_handle(HANDLE handle)
  205. {
  206.     if (is_invalid_device_handle(handle))
  207.     {
  208.         // handle is invalid
  209.     }
  210.     else
  211.     {
  212.         #ifdef MS_WINDOWS
  213.         CloseHandle(handle);
  214.         #else
  215.         close(handle);
  216.         #endif
  217.     }
  218. }
  219.  
  220. int is_valid_device_name(const char *dev_path)
  221. {
  222.     #ifdef MS_WINDOWS  
  223.     char tmp[] = {'\\', '\\', '.', '\\', 'X' , ':' , 0};
  224.    
  225.     if (strlen(dev_path) = strlen(tmp))
  226.     {
  227.         char drive = dev_path[4];
  228.         tmp[4] = drive;
  229.        
  230.         if ( (drive >= 'a' && drive <= 'z') || (drive >= 'A' && drive <= 'Z') )
  231.         {  
  232.             if (strncmp(dev_path, tmp, strlen(tmp)) == 0)
  233.             {
  234.                 return TRUE;
  235.             }
  236.         }
  237.     }
  238.     #else
  239.     char tmp[] = {'/', 'd', 'e', 'v', '/' , 's', 'g', 0};
  240.    
  241.     if (strlen(dev_path) > strlen(tmp))
  242.     {
  243.         if (strncmp(dev_path, tmp, strlen(tmp)) == 0)
  244.         {
  245.             return TRUE;
  246.         }
  247.     }  
  248.     #endif
  249.     return FALSE;
  250. }
  251.  
  252. void freeDevice(USB_HOST_TO_HOST_TRANSFER *transfer)
  253. {
  254.     if (transfer == NULL)
  255.     {
  256.         if (transfer->buffer)
  257.             free(transfer->buffer);
  258.         close_device_handle(transfer->handle_dev);     
  259.     }
  260. }
  261.  
  262. void* getDeviceMemory(USB_HOST_TO_HOST_TRANSFER *transfer)
  263. {
  264.     if (transfer)
  265.     {  
  266.         return transfer->buffer;
  267.     }
  268.     return NULL;
  269. }
  270.  
  271. int __fill_SCSI_PASS_THROUGH_DIRECT(SCSI_PASS_THROUGH_DIRECT *op, int direction_read, unsigned int timeout, unsigned char *cdb, unsigned int cdb_size, void *buffer, unsigned int buffer_size)
  272. {
  273.     /*
  274.     if (op)
  275.     {
  276.         if ( ( (buffer == NULL) && (buffer_size == 0) )  || ( (buffer && (buffer_size > 0) && (buffer_size <= MAX_TRANSFER_BUFFER_LENGTH) ) ) )
  277.         {
  278.             if ((cdb_size > 0) && (cdb_size <= MAX_CDB_LENGTH))
  279.             {
  280.                 //ok
  281.             }
  282.             else
  283.             {
  284.                 return FALSE;
  285.             }
  286.         }      
  287.         else
  288.         {
  289.             return FALSE;  
  290.         }  
  291.     }
  292.     else
  293.     {
  294.         return FALSE;
  295.     }  
  296.     */
  297.     #ifdef MS_WINDOWS
  298.     memset(op, 0, sizeof(SCSI_PASS_THROUGH_DIRECT));
  299.    
  300.     op->ScsiStatus = -1;
  301.     op->PathId = -1;
  302.     op->TargetId = -1;
  303.     op->Lun = -1;
  304.        
  305.     op->Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
  306.  
  307.     op->DataIn = direction;
  308.     op->TimeOutValue = timeout;
  309.    
  310.     op->DataBuffer = buffer;
  311.     op->DataTransferLength = buffer_size;
  312.    
  313.     memcpy(sptd->Cdb, cdb, cdb_size);
  314.     op->CdbLength = cdb_size;
  315.  
  316.     op->SenseInfoLength = MAX_SENSE_LENGTH;
  317.     op->SenseInfoOffset = 48;
  318.    
  319.     #else
  320.    
  321.     memset(&op->io_hdr, 0, sizeof(sg_io_hdr_t));
  322.     memset(&op->sense_buffer, 0, MAX_SENSE_LENGTH);
  323.     op->io_hdr.interface_id = INTERFACE_ID;
  324.     op->io_hdr.mx_sb_len = MAX_SENSE_LENGTH;
  325.     op->io_hdr.sbp = op->sense_buffer;
  326.     op->io_hdr.timeout = timeout;
  327.    
  328.     op->io_hdr.cmdp = op->cdb;
  329.     op->io_hdr.cmd_len = cdb_size;
  330.     memcpy(op->cdb, cdb, cdb_size);
  331.    
  332.     if (direction_read)
  333.     {
  334.         op->io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
  335.     }
  336.     else
  337.     {
  338.         op->io_hdr.dxfer_direction = SG_DXFER_TO_DEV;  
  339.     }
  340.    
  341.    
  342.     op->io_hdr.dxferp = buffer;
  343.     op->io_hdr.dxfer_len = buffer_size;
  344.    
  345.     #endif
  346.     return TRUE;
  347. }
  348.  
  349. int sendKeyboard(USB_HOST_TO_HOST_TRANSFER *transfer, int usb_key_mod, int usb_key)
  350. {
  351.     int status;
  352.     unsigned char cdb[MAX_CDB_LENGTH];
  353.     memcpy(&cdb[0], &usb_h2h_cdb_keyboard[0], sizeof(usb_h2h_cdb_keyboard));
  354.     cdb[2] = (usb_key_mod & 255);
  355.     cdb[4] = (usb_key & 255);
  356.    
  357.     __fill_SCSI_PASS_THROUGH_DIRECT(&transfer->scsi_op, TRUE, USB_HOST_TO_HOST_TIMEOUT, cdb, MAX_CDB_LENGTH, transfer->buffer, 80);
  358.     #ifdef MS_WINDOWS
  359.     DeviceIoControl(transfer->handle_dev, IOCTL_SCSI_PASS_THROUGH_DIRECT, transfer->scsi_op, sizeof(SCSI_PASS_THROUGH_DIRECT), transfer->scsi_op, 80, &status, NULL);
  360.     #else
  361.     status = ioctl(transfer->handle_dev, SG_IO, &transfer->scsi_op);   
  362.     #endif
  363.     //printf("driver: %i\n",io_hdr_write.driver_status);
  364.     //printf("driver w: %i\n",io_hdr_write.host_status);       
  365. }
  366.  
  367. int sendMouse(USB_HOST_TO_HOST_TRANSFER *transfer, int usb_mouse_keys, int usb_mouse_dx, int usb_mouse_dy)
  368. {
  369.     int status;
  370.     unsigned char cdb[MAX_CDB_LENGTH];
  371.     memcpy(&cdb[0], &usb_h2h_cdb_mouse[0], sizeof(usb_h2h_cdb_mouse));
  372.    
  373.     if (usb_mouse_dx < - 127)
  374.         usb_mouse_dx = -127;
  375.     if (usb_mouse_dy < - 127)
  376.         usb_mouse_dy = -127;   
  377.    
  378.     if (usb_mouse_dx > 127)
  379.         usb_mouse_dx = 127;
  380.     if (usb_mouse_dy > 127)
  381.         usb_mouse_dy = 127;
  382.    
  383.     cdb[2] = (usb_mouse_keys & 255);
  384.     cdb[3] = (usb_mouse_dx & 255);
  385.     cdb[4] = (usb_mouse_dy & 255);
  386.     __fill_SCSI_PASS_THROUGH_DIRECT(&transfer->scsi_op, TRUE, USB_HOST_TO_HOST_TIMEOUT, cdb, MAX_CDB_LENGTH, NULL, 0)
  387.    
  388.     #ifdef MS_WINDOWS
  389.     DeviceIoControl(transfer->handle_dev, IOCTL_SCSI_PASS_THROUGH_DIRECT, transfer->scsi_op, sizeof(SCSI_PASS_THROUGH_DIRECT), transfer->scsi_op, 80, &status, NULL);
  390.     #else
  391.    
  392.     //printf("xxxxxxxxxx %i\n", cdb[3]);
  393.     status = ioctl(transfer->handle_dev, SG_IO, &transfer->scsi_op);   
  394.     #endif
  395.    
  396.     printf("driver: %i\n",transfer->scsi_op.io_hdr.driver_status);
  397.     printf("driver w: %i\n",transfer->scsi_op.io_hdr.host_status)
  398.    
  399.     printf("%i\n", status);
  400. }
  401.  
  402.  
  403. int sendDevice(USB_HOST_TO_HOST_TRANSFER *transfer)
  404. {
  405.     int status;
  406.     __fill_SCSI_PASS_THROUGH_DIRECT(&transfer->scsi_op, FALSE, USB_HOST_TO_HOST_TIMEOUT, usb_h2h_cdb_write, MAX_CDB_LENGTH, transfer->buffer, transfer->buffer_size);  
  407.     status = ioctl(transfer->handle_dev, SG_IO, &transfer->scsi_op);   
  408.     //printf("driver: %i\n",io_hdr_write.driver_status);
  409.     //printf("driver w: %i\n",io_hdr_write.host_status);
  410.            
  411. }
  412.  
  413. int readDevice(USB_HOST_TO_HOST_TRANSFER *transfer)
  414. {
  415.     int status;
  416.    
  417.     __fill_SCSI_PASS_THROUGH_DIRECT(&transfer->scsi_op, TRUE, USB_HOST_TO_HOST_TIMEOUT, usb_h2h_cdb_read, MAX_CDB_LENGTH, transfer->buffer, transfer->buffer_size);
  418.     #ifdef MS_WINDOWS
  419.         transfer->scsi_op.Cdb[8] = transfer->read_count;
  420.     #else
  421.         transfer->scsi_op.cdb[8] = transfer->read_count;
  422.     #endif 
  423.     status = ioctl(transfer->handle_dev, SG_IO, &transfer->scsi_op);
  424.     transfer->read_count++;
  425.     //printf("driver: %i\n",io_hdr_write.driver_status);
  426.     //printf("driver w: %i\n",io_hdr_write.host_status);       
  427. }
  428.  
  429.  
  430. int openDevice(USB_HOST_TO_HOST_TRANSFER *transfer, char *dev_path)
  431. {
  432.     HANDLE handle = INVALID_HANDLE_VALUE;
  433.     char *buffer = NULL;
  434.     int ok = TRUE;
  435.     int vers;  
  436.    
  437.     if (transfer == NULL)
  438.     {
  439.         ok = FALSE;
  440.     }
  441.    
  442.     if (dev_path == NULL)
  443.     {
  444.         ok = FALSE;
  445.     }
  446.    
  447.     if (ok)
  448.     {      
  449.         if (!is_valid_device_name(dev_path))
  450.         {
  451.             fprintf(stderr,"invalid device path '%s'!\n", dev_path);
  452.             ok = FALSE;
  453.         }
  454.     }
  455.    
  456.     if (ok)
  457.     {          
  458.         #ifdef MS_WINDOWS
  459.         handle = CreateFile(dev_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, 0);
  460.         #else
  461.         handle = open(dev_path, O_RDWR);
  462.         #endif
  463.        
  464.         if (is_invalid_device_handle(handle))
  465.         {
  466.             fprintf(stderr,"open device '%s' failed!\n", dev_path);
  467.             ok = FALSE;
  468.         }
  469.     }
  470.    
  471.     if (ok)
  472.     {      
  473.         #ifdef MS_WINDOWS
  474.         if (GetDriveType(dev_path + strlen("\\\\.\\")) != DRIVE_CDROM)
  475.         {
  476.             fprintf(stderr, "Device '%s' is not detected as CDROM drive", dev_path);
  477.             CloseHandle(handle);
  478.         }
  479.         #else
  480.         if ((ioctl(handle, SG_GET_VERSION_NUM, &vers) < 0) || (vers < 30000)) {
  481.             fprintf(stderr, "Device '%s' is not an sg device, or old sg driver\n", dev_path);
  482.            
  483.         }    
  484.         #endif
  485.     }
  486.  
  487.     if (ok)
  488.     {  
  489.         buffer = malloc(MAX_TRANSFER_BUFFER_LENGTH);
  490.         if (buffer == NULL)
  491.         {
  492.             fprintf(stderr, "Cannot allocate memory\n", dev_path);
  493.             ok = FALSE;
  494.         }
  495.     }
  496.    
  497.     if (ok)
  498.     {
  499.         transfer->handle_dev = handle;
  500.         transfer->read_count = 0;
  501.         transfer->buffer = buffer;
  502.         transfer->buffer_size = MAX_TRANSFER_BUFFER_LENGTH;    
  503.     }
  504.     else
  505.     {
  506.         if (buffer)
  507.             free(buffer);
  508.         close_device_handle(handle);
  509.     }
  510.     return ok;
  511. }
  512.  
  513.  
  514.  
  515. void main()
  516. {
  517.     USB_HOST_TO_HOST_TRANSFER t;
  518.  
  519.     openDevice(&t, "/dev/sg5");
  520.    
  521.     char *data_write = getDeviceMemory(&t);
  522.     memset(data_write,0, 65536);
  523.    
  524.     data_write[0] = 'H';
  525.     data_write[1] = 'a';    
  526.     data_write[2] = 'l';
  527.     data_write[3] = 'l';
  528.     data_write[4] = 'o';
  529.     data_write[5] = ' ';
  530.     data_write[6] = 'W';
  531.     data_write[7] = 'o';
  532.     data_write[8] = 'r';
  533.     data_write[9] = 'l';
  534.     data_write[10] = 'd';
  535.     data_write[11] = '1';
  536.     data_write[12] = '2';
  537.                                                
  538.     while(1)
  539.     {
  540.         printf("send\n");
  541.         sendMouse(&t, 0, 1, 1);
  542.         sendKeyboard(&t,0,HID_KEY_A);
  543.         sleep(1);
  544.         sendKeyboard(&t,0,0);
  545.         sleep(1);
  546.         //sendDevice(&t);
  547.        
  548.     }
  549.         /*
  550.     getSGHDR(&io_hdr_write, SG_DXFER_TO_DEV, 500, cdb_send, 16, data_write, data_size_write);
  551.     status = ioctl(fd_write, SG_IO, &io_hdr_write);
  552.    
  553.         printf("driver: %i\n",io_hdr_write.driver_status);
  554.             printf("driver w: %i\n",io_hdr_write.host_status);
  555.         //  printf("driver w: %s\n",io_hdr_write->sbp+2);
  556.    
  557.             if (status < 0) {
  558.             // failure
  559.             printf("write fail\n");
  560.  
  561.         }
  562.         else {
  563.             // success
  564.             printf("write success\n");
  565.         }
  566.     //free(io_hdr_write);
  567.    
  568.     SG_DXFER_TO_DEV SG_DXFER_FROM_DEV
  569.     getSGHDR(&io_hdr_read, SG_DXFER_FROM_DEV, 500, cdb_read, 16, data_read, data_size_read);
  570.     status = ioctl(fd_read, SG_IO, &io_hdr_read);  
  571.    
  572.     cdb_read[8]++;
  573.     //  printf("driver read: %i\n",io_hdr_read->driver_status);
  574.     //      printf("driver: %s\n",io_hdr_read->sbp);
  575.     //  printf("driver read: %s\n",io_hdr_read->sbp+2);
  576.        
  577.        
  578.         if (status < 0) {
  579.             // failure
  580.             printf("read fail\n");
  581.  
  582.         }
  583.         else {
  584.             // success
  585.             printf("read %s\n",data_read);
  586.             //printf("read %i\n",*((int*)data_read));
  587.             //printf("read %i\n",*((int*)data_read+4));
  588.         }  
  589.    
  590.     */ 
  591.     return;
  592. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement