blob: 96ccdad23fcc9c8e5f8297af02e008b5e2db325e [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
Dan Albertdb6fe642015-03-19 15:21:08 -070017#define TRACE_TAG TRACE_TRANSPORT
18
19#include "sysdeps.h"
20#include "transport.h"
21
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080022#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080026#include "adb.h"
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080027
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080028static int remote_read(apacket *p, atransport *t)
29{
30 if(usb_read(t->usb, &p->msg, sizeof(amessage))){
31 D("remote usb: read terminated (message)\n");
32 return -1;
33 }
34
Tamas Berghammera1c60c02015-07-13 19:12:28 +010035 if(check_header(p, t)) {
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080036 D("remote usb: check_header failed\n");
37 return -1;
38 }
39
40 if(p->msg.data_length) {
41 if(usb_read(t->usb, p->data, p->msg.data_length)){
42 D("remote usb: terminated (data)\n");
43 return -1;
44 }
45 }
46
47 if(check_data(p)) {
48 D("remote usb: check_data failed\n");
49 return -1;
50 }
51
52 return 0;
53}
54
55static int remote_write(apacket *p, atransport *t)
56{
57 unsigned size = p->msg.data_length;
58
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080059 if(usb_write(t->usb, &p->msg, sizeof(amessage))) {
60 D("remote usb: 1 - write terminated\n");
61 return -1;
62 }
63 if(p->msg.data_length == 0) return 0;
64 if(usb_write(t->usb, &p->data, size)) {
65 D("remote usb: 2 - write terminated\n");
66 return -1;
67 }
68
69 return 0;
70}
71
72static void remote_close(atransport *t)
73{
74 usb_close(t->usb);
75 t->usb = 0;
76}
77
78static void remote_kick(atransport *t)
79{
80 usb_kick(t->usb);
81}
82
Dan Albert9a50f4c2015-05-18 16:43:57 -070083void init_usb_transport(atransport *t, usb_handle *h, ConnectionState state)
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080084{
85 D("transport: usb\n");
86 t->close = remote_close;
87 t->kick = remote_kick;
88 t->read_from_remote = remote_read;
89 t->write_to_remote = remote_write;
90 t->sync_token = 1;
Mike Lockwoode45583f2009-08-08 12:37:44 -040091 t->connection_state = state;
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080092 t->type = kTransportUsb;
93 t->usb = h;
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080094}
95
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -070096#if ADB_HOST
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -080097int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol)
98{
Elliott Hughes4b8538e2014-11-19 22:07:34 -080099 return (usb_class == ADB_CLASS && usb_subclass == ADB_SUBCLASS && usb_protocol == ADB_PROTOCOL);
The Android Open Source Project9ca14dc2009-03-03 19:32:55 -0800100}
Xavier Ducrohet2ef5fc22009-05-20 17:33:53 -0700101#endif