2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
23 #define TRACE_TAG TRACE_TRANSPORT
27 #include "usb_vendors.h"
30 #ifdef HAVE_BIG_ENDIAN
31 #define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
32 static inline void fix_endians(apacket *p)
34 p->msg.command = H4(p->msg.command);
35 p->msg.arg0 = H4(p->msg.arg0);
36 p->msg.arg1 = H4(p->msg.arg1);
37 p->msg.data_length = H4(p->msg.data_length);
38 p->msg.data_check = H4(p->msg.data_check);
39 p->msg.magic = H4(p->msg.magic);
41 unsigned host_to_le32(unsigned n)
46 #define fix_endians(p) do {} while (0)
47 unsigned host_to_le32(unsigned n)
53 static int remote_read(apacket *p, atransport *t)
55 if(usb_read(t->usb, &p->msg, sizeof(amessage))){
56 D("remote usb: read terminated (message)\n");
63 D("remote usb: check_header failed\n");
67 if(p->msg.data_length) {
68 if(usb_read(t->usb, p->data, p->msg.data_length)){
69 D("remote usb: terminated (data)\n");
75 D("remote usb: check_data failed\n");
82 static int remote_write(apacket *p, atransport *t)
84 unsigned size = p->msg.data_length;
88 if(usb_write(t->usb, &p->msg, sizeof(amessage))) {
89 D("remote usb: 1 - write terminated\n");
92 if(p->msg.data_length == 0) return 0;
93 if(usb_write(t->usb, &p->data, size)) {
94 D("remote usb: 2 - write terminated\n");
101 static void remote_close(atransport *t)
107 static void remote_kick(atransport *t)
112 void init_usb_transport(atransport *t, usb_handle *h, int state)
114 D("transport: usb\n");
115 t->close = remote_close;
116 t->kick = remote_kick;
117 t->read_from_remote = remote_read;
118 t->write_to_remote = remote_write;
120 t->connection_state = state;
121 t->type = kTransportUsb;
132 int is_sdb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol)
135 for (i = 0; i < vendorIdCount; i++) {
136 if (vid == vendorIds[i]) {
137 if (usb_class == SDB_CLASS && usb_subclass == SDB_SUBCLASS &&
138 usb_protocol == SDB_PROTOCOL) {