2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "sysdeps.h" //liunote <sysdeps.h>
23 #define TRACE_TAG TRACE_TRANSPORT
27 #include "usb_vendors.h"
30 /* XXX better define? */
32 #define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
33 static inline void fix_endians(apacket
*p
)
35 p
->msg
.command
= H4(p
->msg
.command
);
36 p
->msg
.arg0
= H4(p
->msg
.arg0
);
37 p
->msg
.arg1
= H4(p
->msg
.arg1
);
38 p
->msg
.data_length
= H4(p
->msg
.data_length
);
39 p
->msg
.data_check
= H4(p
->msg
.data_check
);
40 p
->msg
.magic
= H4(p
->msg
.magic
);
42 unsigned host_to_le32(unsigned n
)
47 #define fix_endians(p) do {} while (0)
48 unsigned host_to_le32(unsigned n
)
54 static int remote_read(apacket
*p
, atransport
*t
)
56 if(usb_read(t
->usb
, &p
->msg
, sizeof(amessage
))){
57 D("remote usb: read terminated (message)\n");
64 D("remote usb: check_header failed\n");
68 if(p
->msg
.data_length
) {
69 if(usb_read(t
->usb
, p
->data
, p
->msg
.data_length
)){
70 D("remote usb: terminated (data)\n");
76 D("remote usb: check_data failed\n");
83 static int remote_write(apacket
*p
, atransport
*t
)
85 unsigned size
= p
->msg
.data_length
;
89 if(usb_write(t
->usb
, &p
->msg
, sizeof(amessage
))) {
90 D("remote usb: 1 - write terminated\n");
93 if(p
->msg
.data_length
== 0) return 0;
94 if(usb_write(t
->usb
, &p
->data
, size
)) {
95 D("remote usb: 2 - write terminated\n");
102 static void remote_close(atransport
*t
)
108 static void remote_kick(atransport
*t
)
113 void init_usb_transport(atransport
*t
, usb_handle
*h
, int state
)
115 D("transport: usb\n");
116 t
->close
= remote_close
;
117 t
->kick
= remote_kick
;
118 t
->read_from_remote
= remote_read
;
119 t
->write_to_remote
= remote_write
;
121 t
->connection_state
= state
;
122 t
->type
= kTransportUsb
;
125 printf("liu: connect state =%d\n",state
);
135 int is_adb_interface(int vid
, int pid
, int usb_class
, int usb_subclass
, int usb_protocol
)
138 for (i
= 0; i
< vendorIdCount
; i
++) {
139 if (vid
== vendorIds
[i
]) {
140 if (usb_class
== ADB_CLASS
&& usb_subclass
== ADB_SUBCLASS
&&
141 usb_protocol
== ADB_PROTOCOL
) {