blob: 1138dddc518ebbc18d0835430ee0008566a12d2f [file] [log] [blame]
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20
21#include <sysdeps.h>
22
23#define TRACE_TAG TRACE_TRANSPORT
24#include "adb.h"
25
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080026static int remote_read(apacket *p, atransport *t)
27{
28 if(usb_read(t->usb, &p->msg, sizeof(amessage))){
29 D("remote usb: read terminated (message)\n");
30 return -1;
31 }
32
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080033 if(check_header(p)) {
34 D("remote usb: check_header failed\n");
35 return -1;
36 }
37
38 if(p->msg.data_length) {
39 if(usb_read(t->usb, p->data, p->msg.data_length)){
40 D("remote usb: terminated (data)\n");
41 return -1;
42 }
43 }
44
45 if(check_data(p)) {
46 D("remote usb: check_data failed\n");
47 return -1;
48 }
49
50 return 0;
51}
52
53static int remote_write(apacket *p, atransport *t)
54{
55 unsigned size = p->msg.data_length;
56
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080057 if(usb_write(t->usb, &p->msg, sizeof(amessage))) {
58 D("remote usb: 1 - write terminated\n");
59 return -1;
60 }
61 if(p->msg.data_length == 0) return 0;
62 if(usb_write(t->usb, &p->data, size)) {
63 D("remote usb: 2 - write terminated\n");
64 return -1;
65 }
66
67 return 0;
68}
69
70static void remote_close(atransport *t)
71{
72 usb_close(t->usb);
73 t->usb = 0;
74}
75
76static void remote_kick(atransport *t)
77{
78 usb_kick(t->usb);
79}
80
Mike Lockwoode45583f2009-08-08 12:37:44 -040081void init_usb_transport(atransport *t, usb_handle *h, int state)
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080082{
83 D("transport: usb\n");
84 t->close = remote_close;
85 t->kick = remote_kick;
86 t->read_from_remote = remote_read;
87 t->write_to_remote = remote_write;
88 t->sync_token = 1;
Mike Lockwoode45583f2009-08-08 12:37:44 -040089 t->connection_state = state;
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080090 t->type = kTransportUsb;
91 t->usb = h;
92
93#if ADB_HOST
94 HOST = 1;
95#else
96 HOST = 0;
97#endif
98}
99
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -0700100#if ADB_HOST
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -0800101int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol)
102{
Elliott Hughes4b8538e2014-11-19 22:07:34 -0800103 return (usb_class == ADB_CLASS && usb_subclass == ADB_SUBCLASS && usb_protocol == ADB_PROTOCOL);
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -0800104}
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -0700105#endif