summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.mk9
-rw-r--r--minadbd/Android.mk7
-rw-r--r--minadbd/adb.c30
-rw-r--r--minadbd/adb.h11
-rw-r--r--minadbd/adb_main.c (renamed from minadbd/transport.h)35
-rw-r--r--minadbd/fdevent.h83
-rw-r--r--minadbd/fuse_adb_provider.h8
-rw-r--r--minadbd/mutex_list.h26
-rw-r--r--minadbd/services.c42
-rw-r--r--minadbd/sysdeps.h494
-rw-r--r--minadbd/transport.c803
-rw-r--r--minadbd/transport_usb.c121
-rw-r--r--minadbd/usb_linux_client.c541
-rw-r--r--minadbd/utils.c106
-rw-r--r--minadbd/utils.h68
15 files changed, 52 insertions, 2332 deletions
diff --git a/Android.mk b/Android.mk
index e360c6b22..b8ef63e99 100644
--- a/Android.mk
+++ b/Android.mk
@@ -54,7 +54,10 @@ RECOVERY_FSTAB_VERSION := 2
LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
LOCAL_CFLAGS += -Wno-unused-parameter
-LOCAL_C_INCLUDES += system/vold
+LOCAL_C_INCLUDES += \
+ system/vold \
+ system/extras/ext4_utils \
+ system/core/adb \
LOCAL_STATIC_LIBRARIES := \
libext4_utils_static \
@@ -64,7 +67,7 @@ LOCAL_STATIC_LIBRARIES := \
libmtdutils \
libmincrypt \
libminadbd \
- libadb \
+ libadbd \
libfusesideload \
libminui \
libpng \
@@ -94,8 +97,6 @@ else
LOCAL_STATIC_LIBRARIES += $(TARGET_RECOVERY_UI_LIB)
endif
-LOCAL_C_INCLUDES += system/extras/ext4_utils
-
include $(BUILD_EXECUTABLE)
# All the APIs for testing
diff --git a/minadbd/Android.mk b/minadbd/Android.mk
index c07715706..0cba0c5f1 100644
--- a/minadbd/Android.mk
+++ b/minadbd/Android.mk
@@ -12,17 +12,14 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
adb.c \
+ adb_main.c \
fuse_adb_provider.c \
- transport.c \
- transport_usb.c \
sockets.c \
services.c \
- usb_linux_client.c \
- utils.c
LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter
LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
-LOCAL_C_INCLUDES += bootable/recovery
+LOCAL_C_INCLUDES := bootable/recovery system/core/adb
LOCAL_MODULE := libminadbd
diff --git a/minadbd/adb.c b/minadbd/adb.c
index 0ac16e4d9..5f9cfdfa1 100644
--- a/minadbd/adb.c
+++ b/minadbd/adb.c
@@ -370,33 +370,3 @@ void handle_packet(apacket *p, atransport *t)
put_apacket(p);
}
-
-static void adb_cleanup(void)
-{
- usb_cleanup();
-}
-
-int adb_main()
-{
- atexit(adb_cleanup);
-#if !defined(_WIN32)
- // No SIGCHLD. Let the service subproc handle its children.
- signal(SIGPIPE, SIG_IGN);
-#endif
-
- init_transport_registration();
-
- // The minimal version of adbd only uses USB.
- if (access(USB_ADB_PATH, F_OK) == 0 || access(USB_FFS_ADB_EP0, F_OK) == 0) {
- // listen on USB
- usb_init();
- }
-
- D("Event loop starting\n");
-
- fdevent_loop();
-
- usb_cleanup();
-
- return 0;
-}
diff --git a/minadbd/adb.h b/minadbd/adb.h
index 714868f5c..58818a996 100644
--- a/minadbd/adb.h
+++ b/minadbd/adb.h
@@ -22,6 +22,10 @@
#include "transport.h" /* readx(), writex() */
#include "fdevent.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define MAX_PAYLOAD 4096
#define A_SYNC 0x434e5953
@@ -253,7 +257,8 @@ void close_usb_devices();
void unregister_transport(atransport *t);
void unregister_all_tcp_transports();
-void register_usb_transport(usb_handle *h, const char *serial, unsigned writeable);
+void register_usb_transport(usb_handle *h, const char *serial,
+ const char* dev_path, unsigned writeable);
/* this should only be used for transports with connection_state == CS_NOPERM */
void unregister_usb_transport(usb_handle *usb);
@@ -421,4 +426,8 @@ extern int SHELL_EXIT_NOTIFY_FD;
int sendfailmsg(int fd, const char *reason);
int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/minadbd/transport.h b/minadbd/adb_main.c
index 992e05285..66d270261 100644
--- a/minadbd/transport.h
+++ b/minadbd/adb_main.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,13 +14,28 @@
* limitations under the License.
*/
-#ifndef __TRANSPORT_H
-#define __TRANSPORT_H
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
-/* convenience wrappers around read/write that will retry on
-** EINTR and/or short read/write. Returns 0 on success, -1
-** on error or EOF.
-*/
-int readx(int fd, void *ptr, size_t len);
-int writex(int fd, const void *ptr, size_t len);
-#endif /* __TRANSPORT_H */
+#define TRACE_TAG TRACE_ADB
+
+#include "adb.h"
+#include "sysdeps.h"
+
+int adb_main()
+{
+ atexit(usb_cleanup);
+
+ // No SIGCHLD. Let the service subproc handle its children.
+ signal(SIGPIPE, SIG_IGN);
+
+ init_transport_registration();
+ usb_init();
+
+ D("Event loop starting\n");
+ fdevent_loop();
+
+ return 0;
+}
diff --git a/minadbd/fdevent.h b/minadbd/fdevent.h
deleted file mode 100644
index a0ebe2a7e..000000000
--- a/minadbd/fdevent.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __FDEVENT_H
-#define __FDEVENT_H
-
-#include <stdint.h> /* for int64_t */
-
-/* events that may be observed */
-#define FDE_READ 0x0001
-#define FDE_WRITE 0x0002
-#define FDE_ERROR 0x0004
-#define FDE_TIMEOUT 0x0008
-
-/* features that may be set (via the events set/add/del interface) */
-#define FDE_DONT_CLOSE 0x0080
-
-typedef struct fdevent fdevent;
-
-typedef void (*fd_func)(int fd, unsigned events, void *userdata);
-
-/* Allocate and initialize a new fdevent object
- * Note: use FD_TIMER as 'fd' to create a fd-less object
- * (used to implement timers).
-*/
-fdevent *fdevent_create(int fd, fd_func func, void *arg);
-
-/* Uninitialize and deallocate an fdevent object that was
-** created by fdevent_create()
-*/
-void fdevent_destroy(fdevent *fde);
-
-/* Initialize an fdevent object that was externally allocated
-*/
-void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg);
-
-/* Uninitialize an fdevent object that was initialized by
-** fdevent_install()
-*/
-void fdevent_remove(fdevent *item);
-
-/* Change which events should cause notifications
-*/
-void fdevent_set(fdevent *fde, unsigned events);
-void fdevent_add(fdevent *fde, unsigned events);
-void fdevent_del(fdevent *fde, unsigned events);
-
-void fdevent_set_timeout(fdevent *fde, int64_t timeout_ms);
-
-/* loop forever, handling events.
-*/
-void fdevent_loop();
-
-struct fdevent
-{
- fdevent *next;
- fdevent *prev;
-
- int fd;
- int force_eof;
-
- unsigned short state;
- unsigned short events;
-
- fd_func func;
- void *arg;
-};
-
-
-#endif
diff --git a/minadbd/fuse_adb_provider.h b/minadbd/fuse_adb_provider.h
index 0eb1f79d1..23de44ab2 100644
--- a/minadbd/fuse_adb_provider.h
+++ b/minadbd/fuse_adb_provider.h
@@ -17,6 +17,14 @@
#ifndef __FUSE_ADB_PROVIDER_H
#define __FUSE_ADB_PROVIDER_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
int run_adb_fuse(int sfd, uint64_t file_size, uint32_t block_size);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/minadbd/mutex_list.h b/minadbd/mutex_list.h
deleted file mode 100644
index 652dd7341..000000000
--- a/minadbd/mutex_list.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* the list of mutexes used by adb */
-/* #ifndef __MUTEX_LIST_H
- * Do not use an include-guard. This file is included once to declare the locks
- * and once in win32 to actually do the runtime initialization.
- */
-#ifndef ADB_MUTEX
-#error ADB_MUTEX not defined when including this file
-#endif
-ADB_MUTEX(dns_lock)
-ADB_MUTEX(socket_list_lock)
-ADB_MUTEX(transport_lock)
-#if ADB_HOST
-ADB_MUTEX(local_transports_lock)
-#endif
-ADB_MUTEX(usb_lock)
-
-// Sadly logging to /data/adb/adb-... is not thread safe.
-// After modifying adb.h::D() to count invocations:
-// DEBUG(jpa):0:Handling main()
-// DEBUG(jpa):1:[ usb_init - starting thread ]
-// (Oopsies, no :2:, and matching message is also gone.)
-// DEBUG(jpa):3:[ usb_thread - opening device ]
-// DEBUG(jpa):4:jdwp control socket started (10)
-ADB_MUTEX(D_lock)
-
-#undef ADB_MUTEX
diff --git a/minadbd/services.c b/minadbd/services.c
index 218b84a38..357c222b4 100644
--- a/minadbd/services.c
+++ b/minadbd/services.c
@@ -47,9 +47,9 @@ void *service_bootstrap_func(void *x)
static void sideload_host_service(int sfd, void* cookie)
{
char* saveptr;
- const char* s = strtok_r(cookie, ":", &saveptr);
+ const char* s = adb_strtok_r(cookie, ":", &saveptr);
uint64_t file_size = strtoull(s, NULL, 10);
- s = strtok_r(NULL, ":", &saveptr);
+ s = adb_strtok_r(NULL, ":", &saveptr);
uint32_t block_size = strtoul(s, NULL, 10);
printf("sideload-host file size %llu block size %lu\n", file_size, block_size);
@@ -61,40 +61,6 @@ static void sideload_host_service(int sfd, void* cookie)
exit(result == 0 ? 0 : 1);
}
-#if 0
-static void echo_service(int fd, void *cookie)
-{
- char buf[4096];
- int r;
- char *p;
- int c;
-
- for(;;) {
- r = read(fd, buf, 4096);
- if(r == 0) goto done;
- if(r < 0) {
- if(errno == EINTR) continue;
- else goto done;
- }
-
- c = r;
- p = buf;
- while(c > 0) {
- r = write(fd, p, c);
- if(r > 0) {
- c -= r;
- p += r;
- continue;
- }
- if((r < 0) && (errno == EINTR)) continue;
- goto done;
- }
- }
-done:
- close(fd);
-}
-#endif
-
static int create_service_thread(void (*func)(int, void *), void *cookie)
{
stinfo *sti;
@@ -135,10 +101,6 @@ int service_to_fd(const char *name)
exit(3);
} else if (!strncmp(name, "sideload-host:", 14)) {
ret = create_service_thread(sideload_host_service, (void*)(name + 14));
-#if 0
- } else if(!strncmp(name, "echo:", 5)){
- ret = create_service_thread(echo_service, 0);
-#endif
}
if (ret >= 0) {
close_on_exec(ret);
diff --git a/minadbd/sysdeps.h b/minadbd/sysdeps.h
deleted file mode 100644
index 800ddb753..000000000
--- a/minadbd/sysdeps.h
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* this file contains system-dependent definitions used by ADB
- * they're related to threads, sockets and file descriptors
- */
-#ifndef _ADB_SYSDEPS_H
-#define _ADB_SYSDEPS_H
-
-#ifdef __CYGWIN__
-# undef _WIN32
-#endif
-
-#ifdef _WIN32
-
-#include <windows.h>
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <process.h>
-#include <fcntl.h>
-#include <io.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <ctype.h>
-
-#define OS_PATH_SEPARATOR '\\'
-#define OS_PATH_SEPARATOR_STR "\\"
-
-typedef CRITICAL_SECTION adb_mutex_t;
-
-#define ADB_MUTEX_DEFINE(x) adb_mutex_t x
-
-/* declare all mutexes */
-/* For win32, adb_sysdeps_init() will do the mutex runtime initialization. */
-#define ADB_MUTEX(x) extern adb_mutex_t x;
-#include "mutex_list.h"
-
-extern void adb_sysdeps_init(void);
-
-static __inline__ void adb_mutex_lock( adb_mutex_t* lock )
-{
- EnterCriticalSection( lock );
-}
-
-static __inline__ void adb_mutex_unlock( adb_mutex_t* lock )
-{
- LeaveCriticalSection( lock );
-}
-
-typedef struct { unsigned tid; } adb_thread_t;
-
-typedef void* (*adb_thread_func_t)(void* arg);
-
-typedef void (*win_thread_func_t)(void* arg);
-
-static __inline__ int adb_thread_create( adb_thread_t *thread, adb_thread_func_t func, void* arg)
-{
- thread->tid = _beginthread( (win_thread_func_t)func, 0, arg );
- if (thread->tid == (unsigned)-1L) {
- return -1;
- }
- return 0;
-}
-
-static __inline__ void close_on_exec(int fd)
-{
- /* nothing really */
-}
-
-extern void disable_tcp_nagle(int fd);
-
-#define lstat stat /* no symlinks on Win32 */
-
-#define S_ISLNK(m) 0 /* no symlinks on Win32 */
-
-static __inline__ int adb_unlink(const char* path)
-{
- int rc = unlink(path);
-
- if (rc == -1 && errno == EACCES) {
- /* unlink returns EACCES when the file is read-only, so we first */
- /* try to make it writable, then unlink again... */
- rc = chmod(path, _S_IREAD|_S_IWRITE );
- if (rc == 0)
- rc = unlink(path);
- }
- return rc;
-}
-#undef unlink
-#define unlink ___xxx_unlink
-
-static __inline__ int adb_mkdir(const char* path, int mode)
-{
- return _mkdir(path);
-}
-#undef mkdir
-#define mkdir ___xxx_mkdir
-
-extern int adb_open(const char* path, int options);
-extern int adb_creat(const char* path, int mode);
-extern int adb_read(int fd, void* buf, int len);
-extern int adb_write(int fd, const void* buf, int len);
-extern int adb_lseek(int fd, int pos, int where);
-extern int adb_shutdown(int fd);
-extern int adb_close(int fd);
-
-static __inline__ int unix_close(int fd)
-{
- return close(fd);
-}
-#undef close
-#define close ____xxx_close
-
-static __inline__ int unix_read(int fd, void* buf, size_t len)
-{
- return read(fd, buf, len);
-}
-#undef read
-#define read ___xxx_read
-
-static __inline__ int unix_write(int fd, const void* buf, size_t len)
-{
- return write(fd, buf, len);
-}
-#undef write
-#define write ___xxx_write
-
-static __inline__ int adb_open_mode(const char* path, int options, int mode)
-{
- return adb_open(path, options);
-}
-
-static __inline__ int unix_open(const char* path, int options,...)
-{
- if ((options & O_CREAT) == 0)
- {
- return open(path, options);
- }
- else
- {
- int mode;
- va_list args;
- va_start( args, options );
- mode = va_arg( args, int );
- va_end( args );
- return open(path, options, mode);
- }
-}
-#define open ___xxx_unix_open
-
-
-/* normally provided by <cutils/misc.h> */
-extern void* load_file(const char* pathname, unsigned* psize);
-
-/* normally provided by <cutils/sockets.h> */
-extern int socket_loopback_client(int port, int type);
-extern int socket_network_client(const char *host, int port, int type);
-extern int socket_loopback_server(int port, int type);
-extern int socket_inaddr_any_server(int port, int type);
-
-/* normally provided by "fdevent.h" */
-
-#define FDE_READ 0x0001
-#define FDE_WRITE 0x0002
-#define FDE_ERROR 0x0004
-#define FDE_DONT_CLOSE 0x0080
-
-typedef struct fdevent fdevent;
-
-typedef void (*fd_func)(int fd, unsigned events, void *userdata);
-
-fdevent *fdevent_create(int fd, fd_func func, void *arg);
-void fdevent_destroy(fdevent *fde);
-void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg);
-void fdevent_remove(fdevent *item);
-void fdevent_set(fdevent *fde, unsigned events);
-void fdevent_add(fdevent *fde, unsigned events);
-void fdevent_del(fdevent *fde, unsigned events);
-void fdevent_loop();
-
-struct fdevent {
- fdevent *next;
- fdevent *prev;
-
- int fd;
- int force_eof;
-
- unsigned short state;
- unsigned short events;
-
- fd_func func;
- void *arg;
-};
-
-static __inline__ void adb_sleep_ms( int mseconds )
-{
- Sleep( mseconds );
-}
-
-extern int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t *addrlen);
-
-#undef accept
-#define accept ___xxx_accept
-
-static __inline__ int adb_socket_setbufsize( int fd, int bufsize )
-{
- int opt = bufsize;
- return setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (const char*)&opt, sizeof(opt));
-}
-
-extern int adb_socketpair( int sv[2] );
-
-static __inline__ char* adb_dirstart( const char* path )
-{
- char* p = strchr(path, '/');
- char* p2 = strchr(path, '\\');
-
- if ( !p )
- p = p2;
- else if ( p2 && p2 > p )
- p = p2;
-
- return p;
-}
-
-static __inline__ char* adb_dirstop( const char* path )
-{
- char* p = strrchr(path, '/');
- char* p2 = strrchr(path, '\\');
-
- if ( !p )
- p = p2;
- else if ( p2 && p2 > p )
- p = p2;
-
- return p;
-}
-
-static __inline__ int adb_is_absolute_host_path( const char* path )
-{
- return isalpha(path[0]) && path[1] == ':' && path[2] == '\\';
-}
-
-#else /* !_WIN32 a.k.a. Unix */
-
-#include "fdevent.h"
-#include <cutils/sockets.h>
-#include <cutils/properties.h>
-#include <cutils/misc.h>
-#include <signal.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include <pthread.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <string.h>
-
-#define OS_PATH_SEPARATOR '/'
-#define OS_PATH_SEPARATOR_STR "/"
-
-typedef pthread_mutex_t adb_mutex_t;
-
-#define ADB_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
-#define adb_mutex_init pthread_mutex_init
-#define adb_mutex_lock pthread_mutex_lock
-#define adb_mutex_unlock pthread_mutex_unlock
-#define adb_mutex_destroy pthread_mutex_destroy
-
-#define ADB_MUTEX_DEFINE(m) adb_mutex_t m = PTHREAD_MUTEX_INITIALIZER
-
-#define adb_cond_t pthread_cond_t
-#define adb_cond_init pthread_cond_init
-#define adb_cond_wait pthread_cond_wait
-#define adb_cond_broadcast pthread_cond_broadcast
-#define adb_cond_signal pthread_cond_signal
-#define adb_cond_destroy pthread_cond_destroy
-
-/* declare all mutexes */
-#define ADB_MUTEX(x) extern adb_mutex_t x;
-#include "mutex_list.h"
-
-static __inline__ void close_on_exec(int fd)
-{
- fcntl( fd, F_SETFD, FD_CLOEXEC );
-}
-
-static __inline__ int unix_open(const char* path, int options,...)
-{
- if ((options & O_CREAT) == 0)
- {
- return open(path, options);
- }
- else
- {
- int mode;
- va_list args;
- va_start( args, options );
- mode = va_arg( args, int );
- va_end( args );
- return open(path, options, mode);
- }
-}
-
-static __inline__ int adb_open_mode( const char* pathname, int options, int mode )
-{
- return open( pathname, options, mode );
-}
-
-static __inline__ int adb_creat(const char* path, int mode)
-{
- int fd = open(path, O_CREAT|O_WRONLY|O_TRUNC|O_NOFOLLOW, mode);
-
- if ( fd < 0 )
- return -1;
-
- close_on_exec(fd);
- return fd;
-}
-#undef creat
-#define creat ___xxx_creat
-
-static __inline__ int adb_open( const char* pathname, int options )
-{
- int fd = open( pathname, options );
- if (fd < 0)
- return -1;
- close_on_exec( fd );
- return fd;
-}
-#undef open
-#define open ___xxx_open
-
-static __inline__ int adb_shutdown(int fd)
-{
- return shutdown(fd, SHUT_RDWR);
-}
-#undef shutdown
-#define shutdown ____xxx_shutdown
-
-static __inline__ int adb_close(int fd)
-{
- return close(fd);
-}
-#undef close
-#define close ____xxx_close
-
-
-static __inline__ int adb_read(int fd, void* buf, size_t len)
-{
- return read(fd, buf, len);
-}
-
-#undef read
-#define read ___xxx_read
-
-static __inline__ int adb_write(int fd, const void* buf, size_t len)
-{
- return write(fd, buf, len);
-}
-#undef write
-#define write ___xxx_write
-
-static __inline__ int adb_lseek(int fd, int pos, int where)
-{
- return lseek(fd, pos, where);
-}
-#undef lseek
-#define lseek ___xxx_lseek
-
-static __inline__ int adb_unlink(const char* path)
-{
- return unlink(path);
-}
-#undef unlink
-#define unlink ___xxx_unlink
-
-static __inline__ int adb_socket_accept(int serverfd, struct sockaddr* addr, socklen_t *addrlen)
-{
- int fd;
-
- fd = accept(serverfd, addr, addrlen);
- if (fd >= 0)
- close_on_exec(fd);
-
- return fd;
-}
-
-#undef accept
-#define accept ___xxx_accept
-
-#define unix_read adb_read
-#define unix_write adb_write
-#define unix_close adb_close
-
-typedef pthread_t adb_thread_t;
-
-typedef void* (*adb_thread_func_t)( void* arg );
-
-static __inline__ int adb_thread_create( adb_thread_t *pthread, adb_thread_func_t start, void* arg )
-{
- pthread_attr_t attr;
-
- pthread_attr_init (&attr);
- pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
-
- return pthread_create( pthread, &attr, start, arg );
-}
-
-static __inline__ int adb_socket_setbufsize( int fd, int bufsize )
-{
- int opt = bufsize;
- return setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt));
-}
-
-static __inline__ void disable_tcp_nagle(int fd)
-{
- int on = 1;
- setsockopt( fd, IPPROTO_TCP, TCP_NODELAY, (void*)&on, sizeof(on) );
-}
-
-
-static __inline__ int unix_socketpair( int d, int type, int protocol, int sv[2] )
-{
- return socketpair( d, type, protocol, sv );
-}
-
-static __inline__ int adb_socketpair( int sv[2] )
-{
- int rc;
-
- rc = unix_socketpair( AF_UNIX, SOCK_STREAM, 0, sv );
- if (rc < 0)
- return -1;
-
- close_on_exec( sv[0] );
- close_on_exec( sv[1] );
- return 0;
-}
-
-#undef socketpair
-#define socketpair ___xxx_socketpair
-
-static __inline__ void adb_sleep_ms( int mseconds )
-{
- usleep( mseconds*1000 );
-}
-
-static __inline__ int adb_mkdir(const char* path, int mode)
-{
- return mkdir(path, mode);
-}
-#undef mkdir
-#define mkdir ___xxx_mkdir
-
-static __inline__ void adb_sysdeps_init(void)
-{
-}
-
-static __inline__ char* adb_dirstart(const char* path)
-{
- return strchr(path, '/');
-}
-
-static __inline__ char* adb_dirstop(const char* path)
-{
- return strrchr(path, '/');
-}
-
-static __inline__ int adb_is_absolute_host_path( const char* path )
-{
- return path[0] == '/';
-}
-
-#endif /* !_WIN32 */
-
-#endif /* _ADB_SYSDEPS_H */
diff --git a/minadbd/transport.c b/minadbd/transport.c
deleted file mode 100644
index 92679f518..000000000
--- a/minadbd/transport.c
+++ /dev/null
@@ -1,803 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include "sysdeps.h"
-
-#define TRACE_TAG TRACE_TRANSPORT
-#include "adb.h"
-
-static void transport_unref(atransport *t);
-
-static atransport transport_list = {
- .next = &transport_list,
- .prev = &transport_list,
-};
-
-ADB_MUTEX_DEFINE( transport_lock );
-
-#if ADB_TRACE
-#define MAX_DUMP_HEX_LEN 16
-static void dump_hex( const unsigned char* ptr, size_t len )
-{
- int nn, len2 = len;
- // Build a string instead of logging each character.
- // MAX chars in 2 digit hex, one space, MAX chars, one '\0'.
- char buffer[MAX_DUMP_HEX_LEN *2 + 1 + MAX_DUMP_HEX_LEN + 1 ], *pb = buffer;
-
- if (len2 > MAX_DUMP_HEX_LEN) len2 = MAX_DUMP_HEX_LEN;
-
- for (nn = 0; nn < len2; nn++) {
- sprintf(pb, "%02x", ptr[nn]);
- pb += 2;
- }
- sprintf(pb++, " ");
-
- for (nn = 0; nn < len2; nn++) {
- int c = ptr[nn];
- if (c < 32 || c > 127)
- c = '.';
- *pb++ = c;
- }
- *pb++ = '\0';
- DR("%s\n", buffer);
-}
-#endif
-
-void
-kick_transport(atransport* t)
-{
- if (t && !t->kicked)
- {
- int kicked;
-
- adb_mutex_lock(&transport_lock);
- kicked = t->kicked;
- if (!kicked)
- t->kicked = 1;
- adb_mutex_unlock(&transport_lock);
-
- if (!kicked)
- t->kick(t);
- }
-}
-
-void
-run_transport_disconnects(atransport* t)
-{
- adisconnect* dis = t->disconnects.next;
-
- D("%s: run_transport_disconnects\n", t->serial);
- while (dis != &t->disconnects) {
- adisconnect* next = dis->next;
- dis->func( dis->opaque, t );
- dis = next;
- }
-}
-
-#if ADB_TRACE
-static void
-dump_packet(const char* name, const char* func, apacket* p)
-{
- unsigned command = p->msg.command;
- int len = p->msg.data_length;
- char cmd[9];
- char arg0[12], arg1[12];
- int n;
-
- for (n = 0; n < 4; n++) {
- int b = (command >> (n*8)) & 255;
- if (b < 32 || b >= 127)
- break;
- cmd[n] = (char)b;
- }
- if (n == 4) {
- cmd[4] = 0;
- } else {
- /* There is some non-ASCII name in the command, so dump
- * the hexadecimal value instead */
- snprintf(cmd, sizeof cmd, "%08x", command);
- }
-
- if (p->msg.arg0 < 256U)
- snprintf(arg0, sizeof arg0, "%d", p->msg.arg0);
- else
- snprintf(arg0, sizeof arg0, "0x%x", p->msg.arg0);
-
- if (p->msg.arg1 < 256U)
- snprintf(arg1, sizeof arg1, "%d", p->msg.arg1);
- else
- snprintf(arg1, sizeof arg1, "0x%x", p->msg.arg1);
-
- D("%s: %s: [%s] arg0=%s arg1=%s (len=%d) ",
- name, func, cmd, arg0, arg1, len);
- dump_hex(p->data, len);
-}
-#endif /* ADB_TRACE */
-
-static int
-read_packet(int fd, const char* name, apacket** ppacket)
-{
- char *p = (char*)ppacket; /* really read a packet address */
- int r;
- int len = sizeof(*ppacket);
- char buff[8];
- if (!name) {
- snprintf(buff, sizeof buff, "fd=%d", fd);
- name = buff;
- }
- while(len > 0) {
- r = adb_read(fd, p, len);
- if(r > 0) {
- len -= r;
- p += r;
- } else {
- D("%s: read_packet (fd=%d), error ret=%d errno=%d: %s\n", name, fd, r, errno, strerror(errno));
- if((r < 0) && (errno == EINTR)) continue;
- return -1;
- }
- }
-
-#if ADB_TRACE
- if (ADB_TRACING) {
- dump_packet(name, "from remote", *ppacket);
- }
-#endif
- return 0;
-}
-
-static int
-write_packet(int fd, const char* name, apacket** ppacket)
-{
- char *p = (char*) ppacket; /* we really write the packet address */
- int r, len = sizeof(ppacket);
- char buff[8];
- if (!name) {
- snprintf(buff, sizeof buff, "fd=%d", fd);
- name = buff;
- }
-
-#if ADB_TRACE
- if (ADB_TRACING) {
- dump_packet(name, "to remote", *ppacket);
- }
-#endif
- len = sizeof(ppacket);
- while(len > 0) {
- r = adb_write(fd, p, len);
- if(r > 0) {
- len -= r;
- p += r;
- } else {
- D("%s: write_packet (fd=%d) error ret=%d errno=%d: %s\n", name, fd, r, errno, strerror(errno));
- if((r < 0) && (errno == EINTR)) continue;
- return -1;
- }
- }
- return 0;
-}
-
-static void transport_socket_events(int fd, unsigned events, void *_t)
-{
- atransport *t = _t;
- D("transport_socket_events(fd=%d, events=%04x,...)\n", fd, events);
- if(events & FDE_READ){
- apacket *p = 0;
- if(read_packet(fd, t->serial, &p)){
- D("%s: failed to read packet from transport socket on fd %d\n", t->serial, fd);
- } else {
- handle_packet(p, (atransport *) _t);
- }
- }
-}
-
-void send_packet(apacket *p, atransport *t)
-{
- unsigned char *x;
- unsigned sum;
- unsigned count;
-
- p->msg.magic = p->msg.command ^ 0xffffffff;
-
- count = p->msg.data_length;
- x = (unsigned char *) p->data;
- sum = 0;
- while(count-- > 0){
- sum += *x++;
- }
- p->msg.data_check = sum;
-
- print_packet("send", p);
-
- if (t == NULL) {
- D("Transport is null \n");
- // Zap errno because print_packet() and other stuff have errno effect.
- errno = 0;
- fatal_errno("Transport is null");
- }
-
- if(write_packet(t->transport_socket, t->serial, &p)){
- fatal_errno("cannot enqueue packet on transport socket");
- }
-}
-
-/* The transport is opened by transport_register_func before
-** the input and output threads are started.
-**
-** The output thread issues a SYNC(1, token) message to let
-** the input thread know to start things up. In the event
-** of transport IO failure, the output thread will post a
-** SYNC(0,0) message to ensure shutdown.
-**
-** The transport will not actually be closed until both
-** threads exit, but the input thread will kick the transport
-** on its way out to disconnect the underlying device.
-*/
-
-static void *output_thread(void *_t)
-{
- atransport *t = _t;
- apacket *p;
-
- D("%s: starting transport output thread on fd %d, SYNC online (%d)\n",
- t->serial, t->fd, t->sync_token + 1);
- p = get_apacket();
- p->msg.command = A_SYNC;
- p->msg.arg0 = 1;
- p->msg.arg1 = ++(t->sync_token);
- p->msg.magic = A_SYNC ^ 0xffffffff;
- if(write_packet(t->fd, t->serial, &p)) {
- put_apacket(p);
- D("%s: failed to write SYNC packet\n", t->serial);
- goto oops;
- }
-
- D("%s: data pump started\n", t->serial);
- for(;;) {
- p = get_apacket();
-
- if(t->read_from_remote(p, t) == 0){
- D("%s: received remote packet, sending to transport\n",
- t->serial);
- if(write_packet(t->fd, t->serial, &p)){
- put_apacket(p);
- D("%s: failed to write apacket to transport\n", t->serial);
- goto oops;
- }
- } else {
- D("%s: remote read failed for transport\n", t->serial);
- put_apacket(p);
- break;
- }
- }
-
- D("%s: SYNC offline for transport\n", t->serial);
- p = get_apacket();
- p->msg.command = A_SYNC;
- p->msg.arg0 = 0;
- p->msg.arg1 = 0;
- p->msg.magic = A_SYNC ^ 0xffffffff;
- if(write_packet(t->fd, t->serial, &p)) {
- put_apacket(p);
- D("%s: failed to write SYNC apacket to transport", t->serial);
- }
-
-oops:
- D("%s: transport output thread is exiting\n", t->serial);
- kick_transport(t);
- transport_unref(t);
- return 0;
-}
-
-static void *input_thread(void *_t)
-{
- atransport *t = _t;
- apacket *p;
- int active = 0;
-
- D("%s: starting transport input thread, reading from fd %d\n",
- t->serial, t->fd);
-
- for(;;){
- if(read_packet(t->fd, t->serial, &p)) {
- D("%s: failed to read apacket from transport on fd %d\n",
- t->serial, t->fd );
- break;
- }
- if(p->msg.command == A_SYNC){
- if(p->msg.arg0 == 0) {
- D("%s: transport SYNC offline\n", t->serial);
- put_apacket(p);
- break;
- } else {
- if(p->msg.arg1 == t->sync_token) {
- D("%s: transport SYNC online\n", t->serial);
- active = 1;
- } else {
- D("%s: transport ignoring SYNC %d != %d\n",
- t->serial, p->msg.arg1, t->sync_token);
- }
- }
- } else {
- if(active) {
- D("%s: transport got packet, sending to remote\n", t->serial);
- t->write_to_remote(p, t);
- } else {
- D("%s: transport ignoring packet while offline\n", t->serial);
- }
- }
-
- put_apacket(p);
- }
-
- // this is necessary to avoid a race condition that occured when a transport closes
- // while a client socket is still active.
- close_all_sockets(t);
-
- D("%s: transport input thread is exiting, fd %d\n", t->serial, t->fd);
- kick_transport(t);
- transport_unref(t);
- return 0;
-}
-
-
-static int transport_registration_send = -1;
-static int transport_registration_recv = -1;
-static fdevent transport_registration_fde;
-
-void update_transports(void)
-{
- // nothing to do on the device side
-}
-
-typedef struct tmsg tmsg;
-struct tmsg
-{
- atransport *transport;
- int action;
-};
-
-static int
-transport_read_action(int fd, struct tmsg* m)
-{
- char *p = (char*)m;
- int len = sizeof(*m);
- int r;
-
- while(len > 0) {
- r = adb_read(fd, p, len);
- if(r > 0) {
- len -= r;
- p += r;
- } else {
- if((r < 0) && (errno == EINTR)) continue;
- D("transport_read_action: on fd %d, error %d: %s\n",
- fd, errno, strerror(errno));
- return -1;
- }
- }
- return 0;
-}
-
-static int
-transport_write_action(int fd, struct tmsg* m)
-{
- char *p = (char*)m;
- int len = sizeof(*m);
- int r;
-
- while(len > 0) {
- r = adb_write(fd, p, len);
- if(r > 0) {
- len -= r;
- p += r;
- } else {
- if((r < 0) && (errno == EINTR)) continue;
- D("transport_write_action: on fd %d, error %d: %s\n",
- fd, errno, strerror(errno));
- return -1;
- }
- }
- return 0;
-}
-
-static void transport_registration_func(int _fd, unsigned ev, void *data)
-{
- tmsg m;
- adb_thread_t output_thread_ptr;
- adb_thread_t input_thread_ptr;
- int s[2];
- atransport *t;
-
- if(!(ev & FDE_READ)) {
- return;
- }
-
- if(transport_read_action(_fd, &m)) {
- fatal_errno("cannot read transport registration socket");
- }
-
- t = m.transport;
-
- if(m.action == 0){
- D("transport: %s removing and free'ing %d\n", t->serial, t->transport_socket);
-
- /* IMPORTANT: the remove closes one half of the
- ** socket pair. The close closes the other half.
- */
- fdevent_remove(&(t->transport_fde));
- adb_close(t->fd);
-
- adb_mutex_lock(&transport_lock);
- t->next->prev = t->prev;
- t->prev->next = t->next;
- adb_mutex_unlock(&transport_lock);
-
- run_transport_disconnects(t);
-
- if (t->product)
- free(t->product);
- if (t->serial)
- free(t->serial);
-
- memset(t,0xee,sizeof(atransport));
- free(t);
-
- update_transports();
- return;
- }
-
- /* don't create transport threads for inaccessible devices */
- if (t->connection_state != CS_NOPERM) {
- /* initial references are the two threads */
- t->ref_count = 2;
-
- if(adb_socketpair(s)) {
- fatal_errno("cannot open transport socketpair");
- }
-
- D("transport: %s (%d,%d) starting\n", t->serial, s[0], s[1]);
-
- t->transport_socket = s[0];
- t->fd = s[1];
-
- fdevent_install(&(t->transport_fde),
- t->transport_socket,
- transport_socket_events,
- t);
-
- fdevent_set(&(t->transport_fde), FDE_READ);
-
- if(adb_thread_create(&input_thread_ptr, input_thread, t)){
- fatal_errno("cannot create input thread");
- }
-
- if(adb_thread_create(&output_thread_ptr, output_thread, t)){
- fatal_errno("cannot create output thread");
- }
- }
-
- /* put us on the master device list */
- adb_mutex_lock(&transport_lock);
- t->next = &transport_list;
- t->prev = transport_list.prev;
- t->next->prev = t;
- t->prev->next = t;
- adb_mutex_unlock(&transport_lock);
-
- t->disconnects.next = t->disconnects.prev = &t->disconnects;
-
- update_transports();
-}
-
-void init_transport_registration(void)
-{
- int s[2];
-
- if(adb_socketpair(s)){
- fatal_errno("cannot open transport registration socketpair");
- }
-
- transport_registration_send = s[0];
- transport_registration_recv = s[1];
-
- fdevent_install(&transport_registration_fde,
- transport_registration_recv,
- transport_registration_func,
- 0);
-
- fdevent_set(&transport_registration_fde, FDE_READ);
-}
-
-/* the fdevent select pump is single threaded */
-static void register_transport(atransport *transport)
-{
- tmsg m;
- m.transport = transport;
- m.action = 1;
- D("transport: %s registered\n", transport->serial);
- if(transport_write_action(transport_registration_send, &m)) {
- fatal_errno("cannot write transport registration socket\n");
- }
-}
-
-static void remove_transport(atransport *transport)
-{
- tmsg m;
- m.transport = transport;
- m.action = 0;
- D("transport: %s removed\n", transport->serial);
- if(transport_write_action(transport_registration_send, &m)) {
- fatal_errno("cannot write transport registration socket\n");
- }
-}
-
-
-static void transport_unref_locked(atransport *t)
-{
- t->ref_count--;
- if (t->ref_count == 0) {
- D("transport: %s unref (kicking and closing)\n", t->serial);
- if (!t->kicked) {
- t->kicked = 1;
- t->kick(t);
- }
- t->close(t);
- remove_transport(t);
- } else {
- D("transport: %s unref (count=%d)\n", t->serial, t->ref_count);
- }
-}
-
-static void transport_unref(atransport *t)
-{
- if (t) {
- adb_mutex_lock(&transport_lock);
- transport_unref_locked(t);
- adb_mutex_unlock(&transport_lock);
- }
-}
-
-void add_transport_disconnect(atransport* t, adisconnect* dis)
-{
- adb_mutex_lock(&transport_lock);
- dis->next = &t->disconnects;
- dis->prev = dis->next->prev;
- dis->prev->next = dis;
- dis->next->prev = dis;
- adb_mutex_unlock(&transport_lock);
-}
-
-void remove_transport_disconnect(atransport* t, adisconnect* dis)
-{
- dis->prev->next = dis->next;
- dis->next->prev = dis->prev;
- dis->next = dis->prev = dis;
-}
-
-
-atransport *acquire_one_transport(int state, transport_type ttype, const char* serial, char** error_out)
-{
- atransport *t;
- atransport *result = NULL;
- int ambiguous = 0;
-
-retry:
- if (error_out)
- *error_out = "device not found";
-
- adb_mutex_lock(&transport_lock);
- for (t = transport_list.next; t != &transport_list; t = t->next) {
- if (t->connection_state == CS_NOPERM) {
- if (error_out)
- *error_out = "insufficient permissions for device";
- continue;
- }
-
- /* check for matching serial number */
- if (serial) {
- if (t->serial && !strcmp(serial, t->serial)) {
- result = t;
- break;
- }
- } else {
- if (ttype == kTransportUsb && t->type == kTransportUsb) {
- if (result) {
- if (error_out)
- *error_out = "more than one device";
- ambiguous = 1;
- result = NULL;
- break;
- }
- result = t;
- } else if (ttype == kTransportLocal && t->type == kTransportLocal) {
- if (result) {
- if (error_out)
- *error_out = "more than one emulator";
- ambiguous = 1;
- result = NULL;
- break;
- }
- result = t;
- } else if (ttype == kTransportAny) {
- if (result) {
- if (error_out)
- *error_out = "more than one device and emulator";
- ambiguous = 1;
- result = NULL;
- break;
- }
- result = t;
- }
- }
- }
- adb_mutex_unlock(&transport_lock);
-
- if (result) {
- /* offline devices are ignored -- they are either being born or dying */
- if (result && result->connection_state == CS_OFFLINE) {
- if (error_out)
- *error_out = "device offline";
- result = NULL;
- }
- /* check for required connection state */
- if (result && state != CS_ANY && result->connection_state != state) {
- if (error_out)
- *error_out = "invalid device state";
- result = NULL;
- }
- }
-
- if (result) {
- /* found one that we can take */
- if (error_out)
- *error_out = NULL;
- } else if (state != CS_ANY && (serial || !ambiguous)) {
- adb_sleep_ms(1000);
- goto retry;
- }
-
- return result;
-}
-
-void register_usb_transport(usb_handle *usb, const char *serial, unsigned writeable)
-{
- atransport *t = calloc(1, sizeof(atransport));
- D("transport: %p init'ing for usb_handle %p (sn='%s')\n", t, usb,
- serial ? serial : "");
- init_usb_transport(t, usb, (writeable ? CS_OFFLINE : CS_NOPERM));
- if(serial) {
- t->serial = strdup(serial);
- }
- register_transport(t);
-}
-
-/* this should only be used for transports with connection_state == CS_NOPERM */
-void unregister_usb_transport(usb_handle *usb)
-{
- atransport *t;
- adb_mutex_lock(&transport_lock);
- for(t = transport_list.next; t != &transport_list; t = t->next) {
- if (t->usb == usb && t->connection_state == CS_NOPERM) {
- t->next->prev = t->prev;
- t->prev->next = t->next;
- break;
- }
- }
- adb_mutex_unlock(&transport_lock);
-}
-
-#undef TRACE_TAG
-#define TRACE_TAG TRACE_RWX
-
-int readx(int fd, void *ptr, size_t len)
-{
- char *p = ptr;
- int r;
-#if ADB_TRACE
- size_t len0 = len;
-#endif
- D("readx: fd=%d wanted=%d\n", fd, (int)len);
- while(len > 0) {
- r = adb_read(fd, p, len);
- if(r > 0) {
- len -= r;
- p += r;
- } else {
- if (r < 0) {
- D("readx: fd=%d error %d: %s\n", fd, errno, strerror(errno));
- if (errno == EINTR)
- continue;
- } else {
- D("readx: fd=%d disconnected\n", fd);
- }
- return -1;
- }
- }
-
-#if ADB_TRACE
- D("readx: fd=%d wanted=%zu got=%zu\n", fd, len0, len0 - len);
- dump_hex( ptr, len0 );
-#endif
- return 0;
-}
-
-int writex(int fd, const void *ptr, size_t len)
-{
- char *p = (char*) ptr;
- int r;
-
-#if ADB_TRACE
- D("writex: fd=%d len=%d: ", fd, (int)len);
- dump_hex( ptr, len );
-#endif
- while(len > 0) {
- r = adb_write(fd, p, len);
- if(r > 0) {
- len -= r;
- p += r;
- } else {
- if (r < 0) {
- D("writex: fd=%d error %d: %s\n", fd, errno, strerror(errno));
- if (errno == EINTR)
- continue;
- } else {
- D("writex: fd=%d disconnected\n", fd);
- }
- return -1;
- }
- }
- return 0;
-}
-
-int check_header(apacket *p)
-{
- if(p->msg.magic != (p->msg.command ^ 0xffffffff)) {
- D("check_header(): invalid magic\n");
- return -1;
- }
-
- if(p->msg.data_length > MAX_PAYLOAD) {
- D("check_header(): %d > MAX_PAYLOAD\n", p->msg.data_length);
- return -1;
- }
-
- return 0;
-}
-
-int check_data(apacket *p)
-{
- unsigned count, sum;
- unsigned char *x;
-
- count = p->msg.data_length;
- x = p->data;
- sum = 0;
- while(count-- > 0) {
- sum += *x++;
- }
-
- if(sum != p->msg.data_check) {
- return -1;
- } else {
- return 0;
- }
-}
diff --git a/minadbd/transport_usb.c b/minadbd/transport_usb.c
deleted file mode 100644
index 91cbf6151..000000000
--- a/minadbd/transport_usb.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sysdeps.h>
-
-#define TRACE_TAG TRACE_TRANSPORT
-#include "adb.h"
-
-#ifdef HAVE_BIG_ENDIAN
-#define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
-static inline void fix_endians(apacket *p)
-{
- p->msg.command = H4(p->msg.command);
- p->msg.arg0 = H4(p->msg.arg0);
- p->msg.arg1 = H4(p->msg.arg1);
- p->msg.data_length = H4(p->msg.data_length);
- p->msg.data_check = H4(p->msg.data_check);
- p->msg.magic = H4(p->msg.magic);
-}
-unsigned host_to_le32(unsigned n)
-{
- return H4(n);
-}
-#else
-#define fix_endians(p) do {} while (0)
-unsigned host_to_le32(unsigned n)
-{
- return n;
-}
-#endif
-
-static int remote_read(apacket *p, atransport *t)
-{
- if(usb_read(t->usb, &p->msg, sizeof(amessage))){
- D("remote usb: read terminated (message)\n");
- return -1;
- }
-
- fix_endians(p);
-
- if(check_header(p)) {
- D("remote usb: check_header failed\n");
- return -1;
- }
-
- if(p->msg.data_length) {
- if(usb_read(t->usb, p->data, p->msg.data_length)){
- D("remote usb: terminated (data)\n");
- return -1;
- }
- }
-
- if(check_data(p)) {
- D("remote usb: check_data failed\n");
- return -1;
- }
-
- return 0;
-}
-
-static int remote_write(apacket *p, atransport *t)
-{
- unsigned size = p->msg.data_length;
-
- fix_endians(p);
-
- if(usb_write(t->usb, &p->msg, sizeof(amessage))) {
- D("remote usb: 1 - write terminated\n");
- return -1;
- }
- if(p->msg.data_length == 0) return 0;
- if(usb_write(t->usb, &p->data, size)) {
- D("remote usb: 2 - write terminated\n");
- return -1;
- }
-
- return 0;
-}
-
-static void remote_close(atransport *t)
-{
- usb_close(t->usb);
- t->usb = 0;
-}
-
-static void remote_kick(atransport *t)
-{
- usb_kick(t->usb);
-}
-
-void init_usb_transport(atransport *t, usb_handle *h, int state)
-{
- D("transport: usb\n");
- t->close = remote_close;
- t->kick = remote_kick;
- t->read_from_remote = remote_read;
- t->write_to_remote = remote_write;
- t->sync_token = 1;
- t->connection_state = state;
- t->type = kTransportUsb;
- t->usb = h;
-
- HOST = 0;
-}
diff --git a/minadbd/usb_linux_client.c b/minadbd/usb_linux_client.c
deleted file mode 100644
index b3a38dce5..000000000
--- a/minadbd/usb_linux_client.c
+++ /dev/null
@@ -1,541 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <linux/usb/ch9.h>
-#include <linux/usb/functionfs.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-
-#include "sysdeps.h"
-
-#define TRACE_TAG TRACE_USB
-#include "adb.h"
-
-#define MAX_PACKET_SIZE_FS 64
-#define MAX_PACKET_SIZE_HS 512
-
-#define cpu_to_le16(x) htole16(x)
-#define cpu_to_le32(x) htole32(x)
-
-struct usb_handle
-{
- int fd;
- adb_cond_t notify;
- adb_mutex_t lock;
-
- int (*write)(usb_handle *h, const void *data, int len);
- int (*read)(usb_handle *h, void *data, int len);
- void (*kick)(usb_handle *h);
-
- int control;
- int bulk_out; /* "out" from the host's perspective => source for adbd */
- int bulk_in; /* "in" from the host's perspective => sink for adbd */
-};
-
-struct func_desc {
- struct usb_interface_descriptor intf;
- struct usb_endpoint_descriptor_no_audio source;
- struct usb_endpoint_descriptor_no_audio sink;
-} __attribute__((packed));
-
-struct desc_v1 {
- struct usb_functionfs_descs_head_v1 {
- __le32 magic;
- __le32 length;
- __le32 fs_count;
- __le32 hs_count;
- } __attribute__((packed)) header;
- struct func_desc fs_descs, hs_descs;
-} __attribute__((packed));
-
-struct desc_v2 {
- struct usb_functionfs_descs_head_v2 header;
- // The rest of the structure depends on the flags in the header.
- __le32 fs_count;
- __le32 hs_count;
- struct func_desc fs_descs, hs_descs;
-} __attribute__((packed));
-
-/*static const struct {
- struct usb_functionfs_descs_head header;
- struct {
- struct usb_interface_descriptor intf;
- struct usb_endpoint_descriptor_no_audio source;
- struct usb_endpoint_descriptor_no_audio sink;
- } __attribute__((packed)) fs_descs, hs_descs;
-} __attribute__((packed)) descriptors = {
- .header = {
- .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC),
- .length = cpu_to_le32(sizeof(descriptors)),
- .fs_count = 3,
- .hs_count = 3,
- },
-
-*/
-
-struct func_desc fs_descriptors = {
- .intf = {
- .bLength = sizeof(fs_descriptors.intf),
- .bDescriptorType = USB_DT_INTERFACE,
- .bInterfaceNumber = 0,
- .bNumEndpoints = 2,
- .bInterfaceClass = ADB_CLASS,
- .bInterfaceSubClass = ADB_SUBCLASS,
- .bInterfaceProtocol = ADB_PROTOCOL,
- .iInterface = 1, /* first string from the provided table */
- },
- .source = {
- .bLength = sizeof(fs_descriptors.source),
- .bDescriptorType = USB_DT_ENDPOINT,
- .bEndpointAddress = 1 | USB_DIR_OUT,
- .bmAttributes = USB_ENDPOINT_XFER_BULK,
- .wMaxPacketSize = MAX_PACKET_SIZE_FS,
- },
- .sink = {
- .bLength = sizeof(fs_descriptors.sink),
- .bDescriptorType = USB_DT_ENDPOINT,
- .bEndpointAddress = 2 | USB_DIR_IN,
- .bmAttributes = USB_ENDPOINT_XFER_BULK,
- .wMaxPacketSize = MAX_PACKET_SIZE_FS,
- },
-};
-
-struct func_desc hs_descriptors = {
- .intf = {
- .bLength = sizeof(hs_descriptors.intf),
- .bDescriptorType = USB_DT_INTERFACE,
- .bInterfaceNumber = 0,
- .bNumEndpoints = 2,
- .bInterfaceClass = ADB_CLASS,
- .bInterfaceSubClass = ADB_SUBCLASS,
- .bInterfaceProtocol = ADB_PROTOCOL,
- .iInterface = 1, /* first string from the provided table */
- },
- .source = {
- .bLength = sizeof(hs_descriptors.source),
- .bDescriptorType = USB_DT_ENDPOINT,
- .bEndpointAddress = 1 | USB_DIR_OUT,
- .bmAttributes = USB_ENDPOINT_XFER_BULK,
- .wMaxPacketSize = MAX_PACKET_SIZE_HS,
- },
- .sink = {
- .bLength = sizeof(hs_descriptors.sink),
- .bDescriptorType = USB_DT_ENDPOINT,
- .bEndpointAddress = 2 | USB_DIR_IN,
- .bmAttributes = USB_ENDPOINT_XFER_BULK,
- .wMaxPacketSize = MAX_PACKET_SIZE_HS,
- },
-};
-
-#define STR_INTERFACE_ "ADB Interface"
-
-static const struct {
- struct usb_functionfs_strings_head header;
- struct {
- __le16 code;
- const char str1[sizeof(STR_INTERFACE_)];
- } __attribute__((packed)) lang0;
-} __attribute__((packed)) strings = {
- .header = {
- .magic = cpu_to_le32(FUNCTIONFS_STRINGS_MAGIC),
- .length = cpu_to_le32(sizeof(strings)),
- .str_count = cpu_to_le32(1),
- .lang_count = cpu_to_le32(1),
- },
- .lang0 = {
- cpu_to_le16(0x0409), /* en-us */
- STR_INTERFACE_,
- },
-};
-
-void usb_cleanup()
-{
- // nothing to do here
-}
-
-static void *usb_adb_open_thread(void *x)
-{
- struct usb_handle *usb = (struct usb_handle *)x;
- int fd;
-
- while (1) {
- // wait until the USB device needs opening
- adb_mutex_lock(&usb->lock);
- while (usb->fd != -1)
- adb_cond_wait(&usb->notify, &usb->lock);
- adb_mutex_unlock(&usb->lock);
-
- D("[ usb_thread - opening device ]\n");
- do {
- /* XXX use inotify? */
- fd = unix_open("/dev/android_adb", O_RDWR);
- if (fd < 0) {
- // to support older kernels
- fd = unix_open("/dev/android", O_RDWR);
- fprintf(stderr, "usb_adb_open_thread: %d\n", fd );
- }
- if (fd < 0) {
- adb_sleep_ms(1000);
- }
- } while (fd < 0);
- D("[ opening device succeeded ]\n");
-
- close_on_exec(fd);
- usb->fd = fd;
-
- D("[ usb_thread - registering device ]\n");
- register_usb_transport(usb, 0, 1);
- }
-
- // never gets here
- return 0;
-}
-
-static int usb_adb_write(usb_handle *h, const void *data, int len)
-{
- int n;
-
- D("about to write (fd=%d, len=%d)\n", h->fd, len);
- n = adb_write(h->fd, data, len);
- if(n != len) {
- D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
- h->fd, n, errno, strerror(errno));
- return -1;
- }
- D("[ done fd=%d ]\n", h->fd);
- return 0;
-}
-
-static int usb_adb_read(usb_handle *h, void *data, int len)
-{
- int n;
-
- D("about to read (fd=%d, len=%d)\n", h->fd, len);
- n = adb_read(h->fd, data, len);
- if(n != len) {
- D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
- h->fd, n, errno, strerror(errno));
- return -1;
- }
- D("[ done fd=%d ]\n", h->fd);
- return 0;
-}
-
-static void usb_adb_kick(usb_handle *h)
-{
- D("usb_kick\n");
- adb_mutex_lock(&h->lock);
- adb_close(h->fd);
- h->fd = -1;
-
- // notify usb_adb_open_thread that we are disconnected
- adb_cond_signal(&h->notify);
- adb_mutex_unlock(&h->lock);
-}
-
-static void usb_adb_init()
-{
- usb_handle *h;
- adb_thread_t tid;
- int fd;
-
- h = calloc(1, sizeof(usb_handle));
-
- h->write = usb_adb_write;
- h->read = usb_adb_read;
- h->kick = usb_adb_kick;
- h->fd = -1;
-
- adb_cond_init(&h->notify, 0);
- adb_mutex_init(&h->lock, 0);
-
- fprintf(stderr, "Starting to open usb_init()\n");
- // Open the file /dev/android_adb_enable to trigger
- // the enabling of the adb USB function in the kernel.
- // We never touch this file again - just leave it open
- // indefinitely so the kernel will know when we are running
- // and when we are not.
- fd = unix_open("/dev/android_adb_enable", O_RDWR);
- fprintf(stderr, "unix_open to open usb_init(): %d\n", fd);
- if (fd < 0) {
- D("failed to open /dev/android_adb_enable\n");
- } else {
- close_on_exec(fd);
- }
-
- D("[ usb_init - starting thread ]\n");
- if(adb_thread_create(&tid, usb_adb_open_thread, h)){
- fatal_errno("cannot create usb thread");
- fprintf(stderr, "cannot create the usb thread()\n");
- }
-}
-
-
-static void init_functionfs(struct usb_handle *h)
-{
- ssize_t ret;
- struct desc_v1 v1_descriptor;
- struct desc_v2 v2_descriptor;
-
- v2_descriptor.header.magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2);
- v2_descriptor.header.length = cpu_to_le32(sizeof(v2_descriptor));
- v2_descriptor.header.flags = FUNCTIONFS_HAS_FS_DESC | FUNCTIONFS_HAS_HS_DESC;
- v2_descriptor.fs_count = 3;
- v2_descriptor.hs_count = 3;
- v2_descriptor.fs_descs = fs_descriptors;
- v2_descriptor.hs_descs = hs_descriptors;
-
-
- D("OPENING %s\n", USB_FFS_ADB_EP0);
- h->control = adb_open(USB_FFS_ADB_EP0, O_RDWR);
- if (h->control < 0) {
- D("[ %s: cannot open control endpoint: errno=%d]\n", USB_FFS_ADB_EP0, errno);
- goto err;
- }
-
- ret = adb_write(h->control, &v2_descriptor, sizeof(v2_descriptor));
- if (ret < 0) {
- v1_descriptor.header.magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC);
- v1_descriptor.header.length = cpu_to_le32(sizeof(v1_descriptor));
- v1_descriptor.header.fs_count = 3;
- v1_descriptor.header.hs_count = 3;
- v1_descriptor.fs_descs = fs_descriptors;
- v1_descriptor.hs_descs = hs_descriptors;
- D("[ %s: Switching to V1_descriptor format errno=%d ]\n", USB_FFS_ADB_EP0, errno);
- ret = adb_write(h->control, &v1_descriptor, sizeof(v1_descriptor));
- if (ret < 0) {
- D("[ %s: write descriptors failed: errno=%d ]\n", USB_FFS_ADB_EP0, errno);
- goto err;
- }
- }
-
- ret = adb_write(h->control, &strings, sizeof(strings));
- if (ret < 0) {
- D("[ %s: writing strings failed: errno=%d]\n", USB_FFS_ADB_EP0, errno);
- goto err;
- }
-
- h->bulk_out = adb_open(USB_FFS_ADB_OUT, O_RDWR);
- if (h->bulk_out < 0) {
- D("[ %s: cannot open bulk-out ep: errno=%d ]\n", USB_FFS_ADB_OUT, errno);
- goto err;
- }
-
- h->bulk_in = adb_open(USB_FFS_ADB_IN, O_RDWR);
- if (h->bulk_in < 0) {
- D("[ %s: cannot open bulk-in ep: errno=%d ]\n", USB_FFS_ADB_IN, errno);
- goto err;
- }
-
- return;
-
-err:
- if (h->bulk_in > 0) {
- adb_close(h->bulk_in);
- h->bulk_in = -1;
- }
- if (h->bulk_out > 0) {
- adb_close(h->bulk_out);
- h->bulk_out = -1;
- }
- if (h->control > 0) {
- adb_close(h->control);
- h->control = -1;
- }
- return;
-}
-
-static void *usb_ffs_open_thread(void *x)
-{
- struct usb_handle *usb = (struct usb_handle *)x;
-
- while (1) {
- // wait until the USB device needs opening
- adb_mutex_lock(&usb->lock);
- while (usb->control != -1)
- adb_cond_wait(&usb->notify, &usb->lock);
- adb_mutex_unlock(&usb->lock);
-
- while (1) {
- init_functionfs(usb);
-
- if (usb->control >= 0)
- break;
-
- adb_sleep_ms(1000);
- }
-
- D("[ usb_thread - registering device ]\n");
- register_usb_transport(usb, 0, 1);
- }
-
- // never gets here
- return 0;
-}
-
-static int bulk_write(int bulk_in, const char *buf, size_t length)
-{
- size_t count = 0;
- int ret;
-
- do {
- ret = adb_write(bulk_in, buf + count, length - count);
- if (ret < 0) {
- if (errno != EINTR)
- return ret;
- } else {
- count += ret;
- }
- } while (count < length);
-
- D("[ bulk_write done fd=%d ]\n", bulk_in);
- return count;
-}
-
-static int usb_ffs_write(usb_handle *h, const void *data, int len)
-{
- int n;
-
- D("about to write (fd=%d, len=%d)\n", h->bulk_in, len);
- n = bulk_write(h->bulk_in, data, len);
- if (n != len) {
- D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
- h->bulk_in, n, errno, strerror(errno));
- return -1;
- }
- D("[ done fd=%d ]\n", h->bulk_in);
- return 0;
-}
-
-static int bulk_read(int bulk_out, char *buf, size_t length)
-{
- size_t count = 0;
- int ret;
-
- do {
- ret = adb_read(bulk_out, buf + count, length - count);
- if (ret < 0) {
- if (errno != EINTR) {
- D("[ bulk_read failed fd=%d length=%zu count=%zu ]\n",
- bulk_out, length, count);
- return ret;
- }
- } else {
- count += ret;
- }
- } while (count < length);
-
- return count;
-}
-
-static int usb_ffs_read(usb_handle *h, void *data, int len)
-{
- int n;
-
- D("about to read (fd=%d, len=%d)\n", h->bulk_out, len);
- n = bulk_read(h->bulk_out, data, len);
- if (n != len) {
- D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
- h->bulk_out, n, errno, strerror(errno));
- return -1;
- }
- D("[ done fd=%d ]\n", h->bulk_out);
- return 0;
-}
-
-static void usb_ffs_kick(usb_handle *h)
-{
- int err;
-
- err = ioctl(h->bulk_in, FUNCTIONFS_CLEAR_HALT);
- if (err < 0)
- D("[ kick: source (fd=%d) clear halt failed (%d) ]", h->bulk_in, errno);
-
- err = ioctl(h->bulk_out, FUNCTIONFS_CLEAR_HALT);
- if (err < 0)
- D("[ kick: sink (fd=%d) clear halt failed (%d) ]", h->bulk_out, errno);
-
- adb_mutex_lock(&h->lock);
- adb_close(h->control);
- adb_close(h->bulk_out);
- adb_close(h->bulk_in);
- h->control = h->bulk_out = h->bulk_in = -1;
-
- // notify usb_ffs_open_thread that we are disconnected
- adb_cond_signal(&h->notify);
- adb_mutex_unlock(&h->lock);
-}
-
-static void usb_ffs_init()
-{
- usb_handle *h;
- adb_thread_t tid;
-
- D("[ usb_init - using FunctionFS ]\n");
-
- h = calloc(1, sizeof(usb_handle));
-
- h->write = usb_ffs_write;
- h->read = usb_ffs_read;
- h->kick = usb_ffs_kick;
-
- h->control = -1;
- h->bulk_out = -1;
- h->bulk_out = -1;
-
- adb_cond_init(&h->notify, 0);
- adb_mutex_init(&h->lock, 0);
-
- D("[ usb_init - starting thread ]\n");
- if (adb_thread_create(&tid, usb_ffs_open_thread, h)){
- fatal_errno("[ cannot create usb thread ]\n");
- }
-}
-
-void usb_init()
-{
- if (access(USB_FFS_ADB_EP0, F_OK) == 0)
- usb_ffs_init();
- else
- usb_adb_init();
-}
-
-int usb_write(usb_handle *h, const void *data, int len)
-{
- return h->write(h, data, len);
-}
-
-int usb_read(usb_handle *h, void *data, int len)
-{
- return h->read(h, data, len);
-}
-int usb_close(usb_handle *h)
-{
- // nothing to do here
- return 0;
-}
-
-void usb_kick(usb_handle *h)
-{
- h->kick(h);
-}
diff --git a/minadbd/utils.c b/minadbd/utils.c
deleted file mode 100644
index 91518bab6..000000000
--- a/minadbd/utils.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "utils.h"
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-
-char*
-buff_addc (char* buff, char* buffEnd, int c)
-{
- int avail = buffEnd - buff;
-
- if (avail <= 0) /* already in overflow mode */
- return buff;
-
- if (avail == 1) { /* overflowing, the last byte is reserved for zero */
- buff[0] = 0;
- return buff + 1;
- }
-
- buff[0] = (char) c; /* add char and terminating zero */
- buff[1] = 0;
- return buff + 1;
-}
-
-char*
-buff_adds (char* buff, char* buffEnd, const char* s)
-{
- int slen = strlen(s);
-
- return buff_addb(buff, buffEnd, s, slen);
-}
-
-char*
-buff_addb (char* buff, char* buffEnd, const void* data, int len)
-{
- int avail = (buffEnd - buff);
-
- if (avail <= 0 || len <= 0) /* already overflowing */
- return buff;
-
- if (len > avail)
- len = avail;
-
- memcpy(buff, data, len);
-
- buff += len;
-
- /* ensure there is a terminating zero */
- if (buff >= buffEnd) { /* overflow */
- buff[-1] = 0;
- } else
- buff[0] = 0;
-
- return buff;
-}
-
-char*
-buff_add (char* buff, char* buffEnd, const char* format, ... )
-{
- int avail;
-
- avail = (buffEnd - buff);
-
- if (avail > 0) {
- va_list args;
- int nn;
-
- va_start(args, format);
- nn = vsnprintf( buff, avail, format, args);
- va_end(args);
-
- if (nn < 0) {
- /* some C libraries return -1 in case of overflow,
- * but they will also do that if the format spec is
- * invalid. We assume ADB is not buggy enough to
- * trigger that last case. */
- nn = avail;
- }
- else if (nn > avail) {
- nn = avail;
- }
-
- buff += nn;
-
- /* ensure that there is a terminating zero */
- if (buff >= buffEnd)
- buff[-1] = 0;
- else
- buff[0] = 0;
- }
- return buff;
-}
diff --git a/minadbd/utils.h b/minadbd/utils.h
deleted file mode 100644
index f70ecd24d..000000000
--- a/minadbd/utils.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef _ADB_UTILS_H
-#define _ADB_UTILS_H
-
-/* bounded buffer functions */
-
-/* all these functions are used to append data to a bounded buffer.
- *
- * after each operation, the buffer is guaranteed to be zero-terminated,
- * even in the case of an overflow. they all return the new buffer position
- * which allows one to use them in succession, only checking for overflows
- * at the end. For example:
- *
- * BUFF_DECL(temp,p,end,1024);
- * char* p;
- *
- * p = buff_addc(temp, end, '"');
- * p = buff_adds(temp, end, string);
- * p = buff_addc(temp, end, '"');
- *
- * if (p >= end) {
- * overflow detected. note that 'temp' is
- * zero-terminated for safety.
- * }
- * return strdup(temp);
- */
-
-/* tries to add a character to the buffer, in case of overflow
- * this will only write a terminating zero and return buffEnd.
- */
-char* buff_addc (char* buff, char* buffEnd, int c);
-
-/* tries to add a string to the buffer */
-char* buff_adds (char* buff, char* buffEnd, const char* s);
-
-/* tries to add a bytes to the buffer. the input can contain zero bytes,
- * but a terminating zero will always be appended at the end anyway
- */
-char* buff_addb (char* buff, char* buffEnd, const void* data, int len);
-
-/* tries to add a formatted string to a bounded buffer */
-char* buff_add (char* buff, char* buffEnd, const char* format, ... );
-
-/* convenience macro used to define a bounded buffer, as well as
- * a 'cursor' and 'end' variables all in one go.
- *
- * note: this doesn't place an initial terminating zero in the buffer,
- * you need to use one of the buff_ functions for this. or simply
- * do _cursor[0] = 0 manually.
- */
-#define BUFF_DECL(_buff,_cursor,_end,_size) \
- char _buff[_size], *_cursor=_buff, *_end = _cursor + (_size)
-
-#endif /* _ADB_UTILS_H */