Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae72b5aa authored by Josh Gao's avatar Josh Gao
Browse files

adb: extract USB FFS read/write limit constants.

Change-Id: I5e9fb7959a1c4744cb8d53ece4634138239d4e49
parent b6dfab03
Loading
Loading
Loading
Loading
+11 −3
Original line number Original line Diff line number Diff line
@@ -30,6 +30,8 @@
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h>


#include <algorithm>

#include "adb.h"
#include "adb.h"
#include "transport.h"
#include "transport.h"


@@ -37,6 +39,13 @@
#define MAX_PACKET_SIZE_HS	512
#define MAX_PACKET_SIZE_HS	512
#define MAX_PACKET_SIZE_SS	1024
#define MAX_PACKET_SIZE_SS	1024


// Writes larger than 16k fail on some devices (seed with 3.10.49-g209ea2f in particular).
#define USB_FFS_MAX_WRITE 16384

// The kernel allocates a contiguous buffer for reads, which can fail for large ones due to
// fragmentation. 16k chosen arbitrarily to match the write limit.
#define USB_FFS_MAX_READ 16384

#define cpu_to_le16(x)  htole16(x)
#define cpu_to_le16(x)  htole16(x)
#define cpu_to_le32(x)  htole32(x)
#define cpu_to_le32(x)  htole32(x)


@@ -459,10 +468,9 @@ static void *usb_ffs_open_thread(void *x)
static int usb_ffs_write(usb_handle* h, const void* data, int len) {
static int usb_ffs_write(usb_handle* h, const void* data, int len) {
    D("about to write (fd=%d, len=%d)", h->bulk_in, len);
    D("about to write (fd=%d, len=%d)", h->bulk_in, len);


    // Writes larger than 16k fail on some devices (seed with 3.10.49-g209ea2f in particular).
    const char* buf = static_cast<const char*>(data);
    const char* buf = static_cast<const char*>(data);
    while (len > 0) {
    while (len > 0) {
        int write_len = (len > 16384) ? 16384 : len;
        int write_len = std::min(USB_FFS_MAX_WRITE, len);
        int n = adb_write(h->bulk_in, buf, write_len);
        int n = adb_write(h->bulk_in, buf, write_len);
        if (n < 0) {
        if (n < 0) {
            D("ERROR: fd = %d, n = %d: %s", h->bulk_in, n, strerror(errno));
            D("ERROR: fd = %d, n = %d: %s", h->bulk_in, n, strerror(errno));
@@ -481,7 +489,7 @@ static int usb_ffs_read(usb_handle* h, void* data, int len) {


    char* buf = static_cast<char*>(data);
    char* buf = static_cast<char*>(data);
    while (len > 0) {
    while (len > 0) {
        int read_len = (len > 16384) ? 16384 : len;
        int read_len = std::min(USB_FFS_MAX_READ, len);
        int n = adb_read(h->bulk_out, buf, read_len);
        int n = adb_read(h->bulk_out, buf, read_len);
        if (n < 0) {
        if (n < 0) {
            D("ERROR: fd = %d, n = %d: %s", h->bulk_out, n, strerror(errno));
            D("ERROR: fd = %d, n = %d: %s", h->bulk_out, n, strerror(errno));