Move transport declarations into transport.h.

There are a few cloexec issues in here as an added bonus.

Change-Id: I1699d719d733f47878bdba0454230cf5ab6a60b6
This commit is contained in:
Dan Albert 2015-02-24 15:51:19 -08:00
parent 5329d3fd54
commit 7664901a35
21 changed files with 202 additions and 164 deletions

View file

@ -31,6 +31,7 @@
#include "adb.h"
#include "adb_auth.h"
#include "adb_listeners.h"
#include "transport.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

View file

@ -18,10 +18,10 @@
#define __ADB_H
#include <limits.h>
#include <sys/types.h>
#include "adb_trace.h"
#include "fdevent.h"
#include "transport.h" /* readx(), writex() */
#ifdef __cplusplus
extern "C" {
@ -37,12 +37,15 @@ extern "C" {
#define A_WRTE 0x45545257
#define A_AUTH 0x48545541
#define A_VERSION 0x01000000 // ADB protocol version
// ADB protocol version.
#define A_VERSION 0x01000000
#define ADB_VERSION_MAJOR 1 // Used for help/version information
#define ADB_VERSION_MINOR 0 // Used for help/version information
// Used for help/version information.
#define ADB_VERSION_MAJOR 1
#define ADB_VERSION_MINOR 0
#define ADB_SERVER_VERSION 32 // Increment this when we want to force users to start a new adb server
// Increment this when we want to force users to start a new adb server.
#define ADB_SERVER_VERSION 32
typedef struct amessage amessage;
typedef struct apacket apacket;
@ -263,33 +266,11 @@ void fatal(const char *fmt, ...);
void fatal_errno(const char *fmt, ...);
void handle_packet(apacket *p, atransport *t);
void send_packet(apacket *p, atransport *t);
void get_my_path(char *s, size_t maxLen);
int launch_server(int server_port);
int adb_main(int is_daemon, int server_port);
/* transports are ref-counted
** get_device_transport does an acquire on your behalf before returning
*/
void init_transport_registration(void);
int list_transports(char *buf, size_t bufsize, int long_listing);
void update_transports(void);
asocket* create_device_tracker(void);
/* Obtain a transport from the available transports.
** If state is != CS_ANY, only transports in that state are considered.
** If serial is non-NULL then only the device with that serial will be chosen.
** If no suitable transport is found, error is set.
*/
atransport *acquire_one_transport(int state, transport_type ttype, const char* serial, char **error_out);
void add_transport_disconnect( atransport* t, adisconnect* dis );
void remove_transport_disconnect( atransport* t, adisconnect* dis );
void run_transport_disconnects( atransport* t );
void kick_transport( atransport* t );
/* initialize a transport object's func pointers and state */
#if ADB_HOST
int get_available_local_transport_index();
@ -297,22 +278,6 @@ int get_available_local_transport_index();
int init_socket_transport(atransport *t, int s, int port, int local);
void init_usb_transport(atransport *t, usb_handle *usb, int state);
/* for MacOS X cleanup */
void close_usb_devices();
/* cause new transports to be init'd and added to the list */
int register_socket_transport(int s, const char *serial, int port, int local);
/* these should only be used for the "adb disconnect" command */
void unregister_transport(atransport *t);
void unregister_all_tcp_transports();
void register_usb_transport(usb_handle *h, const char *serial, const char *devpath, unsigned writeable);
/* this should only be used for transports with connection_state == CS_NOPERM */
void unregister_usb_transport(usb_handle *usb);
atransport *find_transport(const char *serial);
#if ADB_HOST
atransport* find_emulator_transport_by_adb_port(int adb_port);
#endif
@ -343,9 +308,6 @@ void set_verity_enabled_state_service(int fd, void* cookie);
apacket *get_apacket(void);
void put_apacket(apacket *p);
int check_header(apacket *p);
int check_data(apacket *p);
// Define it if you want to dump packets.
#define DEBUG_PACKETS 0

View file

@ -24,6 +24,7 @@
#include "adb.h"
#include "adb_auth.h"
#include "transport.h"
#include "sysdeps.h"
int auth_enabled = 0;

View file

@ -14,18 +14,20 @@
* limitations under the License.
*/
#include <resolv.h>
#include <stdio.h>
#include <string.h>
#include <resolv.h>
#include <cutils/list.h>
#include <cutils/sockets.h>
#include "sysdeps.h"
#include "adb.h"
#include "adb_auth.h"
#include "cutils/list.h"
#include "cutils/sockets.h"
#include "fdevent.h"
#include "mincrypt/rsa.h"
#include "mincrypt/sha.h"
#include "transport.h"
#define TRACE_TAG TRACE_AUTH

View file

@ -1,17 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* 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.
* 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 <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <zipfile/zipfile.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "sysdeps.h"
#define TRACE_TAG TRACE_ADB
#include "adb_client.h"
#include "transport.h"
#include "zipfile/zipfile.h"
static transport_type __adb_transport = kTransportAny;
static const char* __adb_serial = NULL;

View file

@ -20,6 +20,7 @@
#include <stdlib.h>
#include "sysdeps.h"
#include "transport.h"
int gListenAll = 0; /* Not static because it is used in commandline.c. */

View file

@ -21,10 +21,12 @@
#include <stdio.h>
#include <stdlib.h>
#include "sysdeps.h"
#include "adb.h"
#include "adb_auth.h"
#include "adb_listeners.h"
#include "sysdeps.h"
#include "transport.h"
#if !ADB_HOST
#include <getopt.h>

View file

@ -14,30 +14,31 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <stdarg.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <ctype.h>
#include <assert.h>
#include "sysdeps.h"
#include <sys/types.h>
#if !defined(_WIN32)
#include <termios.h>
#include <unistd.h>
#endif
#include "sysdeps.h"
#define TRACE_TAG TRACE_ADB
#include "adb.h"
#include "adb_client.h"
#include "adb_auth.h"
#include "file_sync_service.h"
#include "transport.h"
static int do_cmd(transport_type ttype, char* serial, char *cmd, ...);

View file

@ -14,24 +14,25 @@
* limitations under the License.
*/
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <dirent.h>
#include <limits.h>
#include <sys/types.h>
#include <zipfile/zipfile.h>
#include <time.h>
#include <utime.h>
#include "sysdeps.h"
#include "adb.h"
#include "adb_client.h"
#include "file_sync_service.h"
#include "transport.h"
#include "zipfile/zipfile.h"
static unsigned long long total_bytes;
static long long start_time;

View file

@ -14,24 +14,24 @@
* limitations under the License.
*/
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <selinux/android.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <utime.h>
#include <unistd.h>
#include <utime.h>
#include <errno.h>
#include <private/android_filesystem_config.h>
#include <selinux/android.h>
#include "sysdeps.h"
#define TRACE_TAG TRACE_SYNC
#include "adb.h"
#include "file_sync_service.h"
#include "private/android_filesystem_config.h"
#include "transport.h"
/* TODO: use fs_config to configure permissions on /data */
static bool is_on_system(const char *name) {

View file

@ -14,21 +14,23 @@
* limitations under the License.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "fdevent.h"
#include "adb.h"
#include <fcntl.h>
#include <linux/fb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "sysdeps.h"
#include "adb.h"
#include "fdevent.h"
#include "transport.h"
/* TODO:
** - sync with vsync to avoid tearing
@ -68,15 +70,15 @@ void framebuffer_service(int fd, void *cookie)
if (pid == 0) {
dup2(fds[1], STDOUT_FILENO);
close(fds[0]);
close(fds[1]);
adb_close(fds[0]);
adb_close(fds[1]);
const char* command = "screencap";
const char *args[2] = {command, NULL};
execvp(command, (char**)args);
exit(1);
}
close(fds[1]);
adb_close(fds[1]);
fd_screencap = fds[0];
/* read w, h & format */
@ -174,9 +176,9 @@ void framebuffer_service(int fd, void *cookie)
}
done:
close(fds[0]);
adb_close(fds[0]);
TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0));
pipefail:
close(fd);
adb_close(fd);
}

View file

@ -14,8 +14,6 @@
* limitations under the License.
*/
#include "sysdeps.h"
#include <errno.h>
#include <fcntl.h>
#include <mntent.h>
@ -25,11 +23,12 @@
#include <sys/mount.h>
#include <unistd.h>
#include "cutils/properties.h"
#include "sysdeps.h"
#define TRACE_TAG TRACE_ADB
#include "adb.h"
#include "cutils/properties.h"
#include "transport.h"
static int system_ro = 1;
static int vendor_ro = 1;

View file

@ -14,29 +14,30 @@
* limitations under the License.
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef _WIN32
#include <netdb.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <unistd.h>
#endif
#if !ADB_HOST
#include "cutils/android_reboot.h"
#include "cutils/properties.h"
#endif
#include "sysdeps.h"
#define TRACE_TAG TRACE_SERVICES
#include "adb.h"
#include "file_sync_service.h"
#if ADB_HOST
# ifndef HAVE_WINSOCK
# include <netinet/in.h>
# include <netdb.h>
# include <sys/ioctl.h>
# endif
#else
# include <cutils/android_reboot.h>
# include <cutils/properties.h>
#endif
#include "transport.h"
typedef struct stinfo stinfo;

View file

@ -14,21 +14,21 @@
* limitations under the License.
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include "sysdeps.h"
#if !ADB_HOST
#include <cutils/properties.h>
#endif
#define TRACE_TAG TRACE_SOCKETS
#include "adb.h"
#if !ADB_HOST
#include "cutils/properties.h"
#endif
#include "transport.h"
ADB_MUTEX_DEFINE( socket_list_lock );

View file

@ -14,13 +14,15 @@
* limitations under the License.
*/
#include "sysdeps.h"
#include "transport.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "sysdeps.h"
#include <unistd.h>
#define TRACE_TAG TRACE_TRANSPORT
#include "adb.h"
@ -494,8 +496,7 @@ create_device_tracker(void)
/* call this function each time the transport list has changed */
void update_transports(void)
{
void update_transports(void) {
char buffer[1024];
int len;
device_tracker* tracker;

View file

@ -19,17 +19,64 @@
#include <sys/types.h>
#include "adb.h"
#ifdef __cplusplus
extern "C" {
#endif
/* convenience wrappers around read/write that will retry on
** EINTR and/or short read/write. Returns 0 on success, -1
** on error or EOF.
*/
/*
* 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);
/*
* Obtain a transport from the available transports.
* If state is != CS_ANY, only transports in that state are considered.
* If serial is non-NULL then only the device with that serial will be chosen.
* If no suitable transport is found, error is set.
*/
atransport* acquire_one_transport(int state, transport_type ttype,
const char* serial, char** error_out);
void add_transport_disconnect(atransport* t, adisconnect* dis);
void remove_transport_disconnect(atransport* t, adisconnect* dis);
void kick_transport(atransport* t);
void run_transport_disconnects(atransport* t);
void update_transports(void);
/* transports are ref-counted
** get_device_transport does an acquire on your behalf before returning
*/
void init_transport_registration(void);
int list_transports(char* buf, size_t bufsize, int long_listing);
atransport* find_transport(const char* serial);
void register_usb_transport(usb_handle* h, const char* serial,
const char* devpath, unsigned writeable);
/* cause new transports to be init'd and added to the list */
int register_socket_transport(int s, const char* serial, int port, int local);
/* this should only be used for transports with connection_state == CS_NOPERM */
void unregister_usb_transport(usb_handle* usb);
/* these should only be used for the "adb disconnect" command */
void unregister_transport(atransport* t);
void unregister_all_tcp_transports();
int check_header(apacket* p);
int check_data(apacket* p);
/* for MacOS X cleanup */
void close_usb_devices();
void send_packet(apacket* p, atransport* t);
asocket* create_device_tracker(void);
#ifdef __cplusplus
}
#endif

View file

@ -14,19 +14,20 @@
* limitations under the License.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include "sysdeps.h"
#include <sys/types.h>
#if !ADB_HOST
#include <cutils/properties.h>
#endif
#define TRACE_TAG TRACE_TRANSPORT
#include "adb.h"
#if !ADB_HOST
#include "cutils/properties.h"
#endif
#include "transport.h"
#if ADB_HOST
/* we keep a list of opened transports. The atransport struct knows to which

View file

@ -22,6 +22,7 @@
#define TRACE_TAG TRACE_TRANSPORT
#include "adb.h"
#include "transport.h"
static int remote_read(apacket *p, atransport *t)
{

View file

@ -14,33 +14,30 @@
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <dirent.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/usbdevice_fs.h>
#include <linux/version.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20)
#include <linux/usb/ch9.h>
#else
#include <linux/usb_ch9.h>
#endif
#include <asm/byteorder.h>
#include "sysdeps.h"
#define TRACE_TAG TRACE_USB
#include "adb.h"
#include "transport.h"
/* usb scan debugging is waaaay too verbose */
#define DBGX(x...)

View file

@ -14,22 +14,22 @@
* 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 <linux/usb/ch9.h>
#include <linux/usb/functionfs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include "sysdeps.h"
#define TRACE_TAG TRACE_USB
#include "adb.h"
#include "transport.h"
#define MAX_PACKET_SIZE_FS 64
#define MAX_PACKET_SIZE_HS 512

View file

@ -14,19 +14,20 @@
* limitations under the License.
*/
#include <winsock2.h>
#include <windows.h>
#include <winerror.h>
#include <errno.h>
#include <usb100.h>
#include <winsock2.h> // winsock.h *must* be included before windows.h.
#include <adb_api.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <usb100.h>
#include <windows.h>
#include <winerror.h>
#include "sysdeps.h"
#define TRACE_TAG TRACE_USB
#include "adb.h"
#include "transport.h"
/** Structure usb_handle describes our connection to the usb device via
AdbWinApi.dll. This structure is returned from usb_open() routine and