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
24 #define LOG_TAG "SDBD_TRACE_TRANSPORT"
29 #ifdef HAVE_BIG_ENDIAN
30 #define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
31 static inline void fix_endians(apacket *p)
33 p->msg.command = H4(p->msg.command);
34 p->msg.arg0 = H4(p->msg.arg0);
35 p->msg.arg1 = H4(p->msg.arg1);
36 p->msg.data_length = H4(p->msg.data_length);
37 p->msg.data_check = H4(p->msg.data_check);
38 p->msg.magic = H4(p->msg.magic);
40 unsigned host_to_le32(unsigned n)
45 #define fix_endians(p) do {} while (0)
46 unsigned host_to_le32(unsigned n)
52 static int remote_read(apacket *p, atransport *t)
54 if(usb_read(t->usb, &p->msg, sizeof(amessage))){
55 E("remote usb: read terminated (message)\n");
61 if(check_header(p, t)) {
62 E("remote usb: check_header failed\n");
66 if(p->msg.data_length) {
67 if(usb_read(t->usb, p->data, p->msg.data_length)){
68 E("remote usb: terminated (data)\n");
74 E("remote usb: check_data failed\n");
81 static int remote_write(apacket *p, atransport *t)
83 unsigned size = p->msg.data_length;
87 if(usb_write(t->usb, &p->msg, sizeof(amessage))) {
88 E("remote usb: 1 - write terminated\n");
91 if(p->msg.data_length == 0) return 0;
92 if(usb_write(t->usb, &p->data, size)) {
93 E("remote usb: 2 - write terminated\n");
100 static void remote_close(atransport *t)
106 static void remote_kick(atransport *t)
111 void init_usb_transport(atransport *t, usb_handle *h, int state)
113 D("transport: usb\n");
114 t->close = remote_close;
115 t->kick = remote_kick;
116 t->read_from_remote = remote_read;
117 t->write_to_remote = remote_write;
119 t->connection_state = state;
120 t->type = kTransportUsb;