diff options
author | Dave Airlie <airlied@redhat.com> | 2014-11-03 17:18:12 +1000 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2014-11-03 17:18:12 +1000 |
commit | 91cf5e2f91b2d4f2978be0f9996836f8b171af93 (patch) | |
tree | b34ecb666badc562264de45e3e4bd4996fdf0241 | |
parent | 5128b44bfc3a52e8b25706b61abdb2e97be175f2 (diff) |
split usb rw fns out
-rw-r--r-- | dl3.c | 109 |
1 files changed, 65 insertions, 44 deletions
@@ -261,54 +261,62 @@ static void decode_cert(const unsigned char *buf, int len) #endif printf("ret is %d\n", ret); } -static int send_buffer(libusb_device_handle *handle, int endpoint_out, int endpoint_in) -{ - unsigned char buf[1024]; - int r, i = 0; - int size; - - memset(buf, 0, 255); -#if 0 - buf[2] = 0x1c; - buf[4] = 0x02; - buf[8] = 0x25; - buf[16] = 0x05; -#endif - - buf[2] = 0x0c; - buf[4] = 0x01; - do { - r = libusb_bulk_transfer(handle, endpoint_out, buf, 16, &size, 1000); - if (r == LIBUSB_ERROR_PIPE) - libusb_clear_halt(handle, endpoint_out); - i++; - } while ((r == LIBUSB_ERROR_PIPE) && (i < 5)); - - buf[2] = 0x1c; - buf[4] = 0x02; - buf[8] = 0x25; - buf[16] = 0x05; - - do { - r = libusb_bulk_transfer(handle, endpoint_out, buf, 32, &size, 1000); +static int write_to_usb(libusb_device_handle *handle, int endpoint_out, + const uint8_t *buf, int len, int *size) +{ + int i = 0, r; + do { + r = libusb_bulk_transfer(handle, endpoint_out, buf, len, size, 1000); if (r == LIBUSB_ERROR_PIPE) libusb_clear_halt(handle, endpoint_out); i++; } while ((r == LIBUSB_ERROR_PIPE) && (i < 5)); + return r; +} - do { - r = libusb_bulk_transfer(handle, endpoint_out, buf0, 84, &size, 1000); - if (r == LIBUSB_ERROR_PIPE) - libusb_clear_halt(handle, endpoint_out); - i++; - } while ((r == LIBUSB_ERROR_PIPE) && (i < 5)); +static int block_read_usb(libusb_device_handle *handle, int endpoint_in, + uint8_t *buf, int *size) +{ + int r; - r = libusb_bulk_transfer(handle, endpoint_in, buf, 38, &size, 1000); + r = libusb_bulk_transfer(handle, endpoint_in, buf, 1024, size, 1000); if (r < 0) { printf("libusb_bulk_transfer failed: %s\n", libusb_error_name(r)); - return; } + return r; +} + +static int send_buffer(libusb_device_handle *handle, int endpoint_out, int endpoint_in) +{ + unsigned char buf[1024]; + int r, i = 0; + int size; + int len2, len; + + dl3_empty_packet(buf, &len); + r = write_to_usb(handle, endpoint_out, buf, len, &size); + if (r != 0) + return r; + + dl3_msg2_hdr25(buf, &len); + r = write_to_usb(handle, endpoint_out, buf, len, &size); + if (r != 0) + return r; + + memset(buf, 0, 1024); + dl3_msg2_hdr04(buf, &len); + len2 = len; + dl3_packet_hdcp_ake_init(&buf[len], &len); + len2 += len; + len2 = ROUND_TO_4(len2); + r = write_to_usb(handle, endpoint_out, buf, len2, &size); + if (r != 0) + return r; + + r = block_read_usb(handle, endpoint_in, buf, &size); + if (r < 0) + return r; printf(" rx %d\n", size); for (i = 0; i < size; i++) { @@ -316,11 +324,9 @@ static int send_buffer(libusb_device_handle *handle, int endpoint_out, int endpo } printf("\n"); - r = libusb_bulk_transfer(handle, endpoint_in, buf, 546, &size, 1000); - if (r < 0) { - printf("libusb_bulk_transfer failed: %s\n", libusb_error_name(r)); - return; - } + r = block_read_usb(handle, endpoint_in, buf, &size); + if (r < 0) + return r; printf(" rx %d\n", size); printf("{"); @@ -333,8 +339,23 @@ static int send_buffer(libusb_device_handle *handle, int endpoint_out, int endpo decode_cert(buf, size); - return 0; + dl3_packet_hdcp_ake_no_stored_km(buf, &len); + len = ROUND_TO_4(len); + r = write_to_usb(handle, endpoint_out, buf, len, &size); + if (r != 0) + return r; + do { + r = block_read_usb(handle, endpoint_in, buf, &size); + if (r < 0) + return r; + printf(" rx %d\n", size); + + for (i = 0; i < size; i++) { + printf("%02x ", buf[i]); + } + printf("\n"); + } while (1); return 0; } |