summaryrefslogtreecommitdiffstats
path: root/fastboot
diff options
context:
space:
mode:
Diffstat (limited to 'fastboot')
-rw-r--r--fastboot/fastboot.c5
-rw-r--r--fastboot/usb.h2
-rw-r--r--fastboot/usb_linux.c20
-rw-r--r--fastboot/usb_osx.c3
-rw-r--r--fastboot/usb_windows.c1
5 files changed, 23 insertions, 8 deletions
diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c
index c81222a82..911c3f60c 100644
--- a/fastboot/fastboot.c
+++ b/fastboot/fastboot.c
@@ -165,6 +165,9 @@ int list_devices_callback(usb_ifc_info *info)
{
if (match_fastboot(info) == 0) {
char* serial = info->serial_number;
+ if (!info->writable) {
+ serial = "no permissions"; // like "adb devices"
+ }
if (!serial[0]) {
serial = "????????????";
}
@@ -554,6 +557,8 @@ int main(int argc, char **argv)
return 0;
}
+ serial = getenv("ANDROID_SERIAL");
+
while (argc > 0) {
if(!strcmp(*argv, "-w")) {
wants_wipe = 1;
diff --git a/fastboot/usb.h b/fastboot/usb.h
index f3ec5bfda..cc157d56e 100644
--- a/fastboot/usb.h
+++ b/fastboot/usb.h
@@ -50,6 +50,8 @@ struct usb_ifc_info
unsigned char has_bulk_in;
unsigned char has_bulk_out;
+ unsigned char writable;
+
char serial_number[256];
};
diff --git a/fastboot/usb_linux.c b/fastboot/usb_linux.c
index 3b40ba7f9..2ce53eb83 100644
--- a/fastboot/usb_linux.c
+++ b/fastboot/usb_linux.c
@@ -89,7 +89,8 @@ static int check(void *_desc, int len, unsigned type, int size)
return 0;
}
-static int filter_usb_device(int fd, char *ptr, int len, ifc_match_func callback,
+static int filter_usb_device(int fd, char *ptr, int len, int writable,
+ ifc_match_func callback,
int *ept_in_id, int *ept_out_id, int *ifc_id)
{
struct usb_device_descriptor *dev;
@@ -119,7 +120,8 @@ static int filter_usb_device(int fd, char *ptr, int len, ifc_match_func callback
info.dev_class = dev->bDeviceClass;
info.dev_subclass = dev->bDeviceSubClass;
info.dev_protocol = dev->bDeviceProtocol;
-
+ info.writable = writable;
+
// read device serial number (if there is one)
info.serial_number[0] = 0;
if (dev->iSerialNumber) {
@@ -201,6 +203,7 @@ static usb_handle *find_usb_device(const char *base, ifc_match_func callback)
DIR *busdir, *devdir;
struct dirent *de;
int fd;
+ int writable;
busdir = opendir(base);
if(busdir == 0) return 0;
@@ -219,13 +222,20 @@ static usb_handle *find_usb_device(const char *base, ifc_match_func callback)
sprintf(devname, "%s/%s", busname, de->d_name);
// DBG("[ scanning %s ]\n", devname);
+ writable = 1;
if((fd = open(devname, O_RDWR)) < 0) {
- continue;
+ // Check if we have read-only access, so we can give a helpful
+ // diagnostic like "adb devices" does.
+ writable = 0;
+ if((fd = open(devname, O_RDONLY)) < 0) {
+ continue;
+ }
}
n = read(fd, desc, sizeof(desc));
- if(filter_usb_device(fd, desc, n, callback, &in, &out, &ifc) == 0){
+ if(filter_usb_device(fd, desc, n, writable, callback,
+ &in, &out, &ifc) == 0) {
usb = calloc(1, sizeof(usb_handle));
strcpy(usb->fname, devname);
usb->ep_in = in;
@@ -375,5 +385,3 @@ usb_handle *usb_open(ifc_match_func callback)
{
return find_usb_device("/dev/bus/usb", callback);
}
-
-
diff --git a/fastboot/usb_osx.c b/fastboot/usb_osx.c
index d6a826094..0b0512d1c 100644
--- a/fastboot/usb_osx.c
+++ b/fastboot/usb_osx.c
@@ -351,6 +351,7 @@ static int try_device(io_service_t device, usb_handle *handle) {
// device has no serial number
handle->info.serial_number[0] = 0;
}
+ handle->info.writable = 1;
if (try_interfaces(dev, handle)) {
goto error;
@@ -416,8 +417,6 @@ static int init_usb(ifc_match_func callback, usb_handle **handle) {
break;
}
- usb_ifc_info info;
-
if (try_device(device, &h) != 0) {
IOObjectRelease(device);
ret = -1;
diff --git a/fastboot/usb_windows.c b/fastboot/usb_windows.c
index 9c0a9cbf1..54008a423 100644
--- a/fastboot/usb_windows.c
+++ b/fastboot/usb_windows.c
@@ -301,6 +301,7 @@ int recognized_device(usb_handle* handle, ifc_match_func callback) {
info.ifc_class = interf_desc.bInterfaceClass;
info.ifc_subclass = interf_desc.bInterfaceSubClass;
info.ifc_protocol = interf_desc.bInterfaceProtocol;
+ info.writable = 1;
// read serial number (if there is one)
unsigned long serial_number_len = sizeof(info.serial_number);