1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#
# Patch managed by http://www.holgerschurig.de/patcher.html
#
--- obexpush/client/obex_main.c~add-obextool.patch
+++ obexpush/client/obex_main.c
@@ -221,12 +221,7 @@
return NULL;
}
-
- #ifdef OLDLIBOBEX
- custfunc.userdata = gt->userdata;
- #else //OLDLIBOBEX
custfunc.customdata = gt->userdata;
- #endif //OLDLIBOBEX
custfunc.connect = cobex_connect;
custfunc.disconnect = cobex_disconnect;
custfunc.write = cobex_write;
--- /dev/null
+++ obexpush/client/obextool.c
@@ -0,0 +1,411 @@
+/*
+ *
+ * Bluetooth OBEX tool
+ *
+ * Copyright (C) 2002 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <string.h>
+#include <libgen.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
+#include <bluetooth/rfcomm.h>
+
+#include <glib.h>
+#include <openobex/obex.h>
+
+
+
+volatile int finished = 0;
+
+struct btobex_context_t {
+ int fd;
+ bdaddr_t bdaddr;
+ uint8_t channel;
+} btobex_context;
+
+
+gint btobex_connect(obex_t *handle, gpointer userdata)
+{
+ struct btobex_context_t *context = userdata;
+ struct sockaddr_rc laddr, raddr;
+ int s;
+
+ if ((s = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
+ printf("Can't create socket. %s (%d)\n", strerror(errno), errno);
+ return -1;
+ }
+
+ laddr.rc_family = AF_BLUETOOTH;
+ bacpy(&laddr.rc_bdaddr, BDADDR_ANY);
+ laddr.rc_channel = 0;
+ if (bind(s, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {
+ printf("Can't bind socket. %s (%d)\n", strerror(errno), errno);
+ close(s);
+ return -1;
+ }
+
+ raddr.rc_family = AF_BLUETOOTH;
+ bacpy(&raddr.rc_bdaddr, &context->bdaddr);
+ raddr.rc_channel = context->channel;
+ if (connect(s, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) {
+ printf("Can't connect. %s (%d)\n", strerror(errno), errno);
+ close(s);
+ return -1;
+ }
+
+ context->fd = s;
+
+ return 1;
+}
+
+
+gint btobex_disconnect(obex_t *handle, gpointer userdata)
+{
+ struct btobex_context_t *context = userdata;
+
+ close(context->fd);
+
+ return 1;
+}
+
+
+gint btobex_listen(obex_t *handle, gpointer userdata)
+{
+ printf("The listen command is not implemented\n");
+
+ return -1;
+}
+
+
+gint btobex_write(obex_t *handle, gpointer userdata, guint8 *buffer, gint length)
+{
+ struct btobex_context_t *context = userdata;
+
+ return (write(context->fd, buffer, length));
+}
+
+
+gint btobex_handleinput(obex_t *handle, gpointer userdata, gint timeout)
+{
+ struct btobex_context_t *context = userdata;
+ struct timeval to;
+ fd_set fdset;
+ unsigned char buf[1024];
+ int sel, len;
+
+ to.tv_sec = timeout;
+ to.tv_usec = 0;
+
+ FD_ZERO(&fdset);
+ FD_SET(context->fd, &fdset);
+
+ len = 0;
+
+ if ((sel = select(context->fd + 1, &fdset, NULL, NULL, &to)) > 0) {
+ if ((len = read(context->fd, buf, sizeof(buf))) > 0)
+ OBEX_CustomDataFeed(handle, buf, len);
+ }
+
+ return len;
+}
+
+
+obex_ctrans_t btobex_ctrans = {
+ customdata: &btobex_context,
+ connect: btobex_connect,
+ disconnect: btobex_disconnect,
+ listen: btobex_listen,
+ write: btobex_write,
+ handleinput: btobex_handleinput,
+};
+
+
+void btobex_event(obex_t *handle, obex_object_t *object, gint mode, gint event, gint obex_cmd, gint obex_rsp)
+{
+ switch (event) {
+ case OBEX_EV_PROGRESS:
+ break;
+ case OBEX_EV_ABORT:
+ printf("Request aborted\n");
+ finished = 1;
+ break;
+ case OBEX_EV_REQDONE:
+ finished = 1;
+ break;
+ case OBEX_EV_REQHINT:
+ printf("Request hint\n");
+ break;
+ case OBEX_EV_REQ:
+ printf("Server request\n");
+ break;
+ case OBEX_EV_LINKERR:
+ OBEX_TransportDisconnect(handle);
+ printf("Link broken\n");
+ break;
+ case OBEX_EV_PARSEERR:
+ printf("Parse error\n");
+ break;
+ default:
+ printf("Unknown event 0x%02x\n", event);
+ break;
+ }
+}
+
+
+
+guint8 *btobex_readfile(const char *filename, int *filesize)
+{
+ guint8 *buf;
+ struct stat stats;
+ int fd, fs;
+
+ stat(filename, &stats);
+ fs = stats.st_size;
+
+ if ((fd = open(filename, O_RDONLY, 0)) < 0)
+ return NULL;
+
+ if (!(buf = g_malloc(fs))) {
+ close(fd);
+ return NULL;
+ }
+
+ *filesize = read(fd, buf, fs);
+
+ close(fd);
+
+ return buf;
+}
+
+
+int btobex_push(bdaddr_t *bdaddr, uint8_t channel, char *filename, char *alias)
+{
+ obex_t *handle;
+ obex_object_t *object;
+ obex_headerdata_t hd;
+
+ guint8 namebuf[MAXPATHLEN + 1];
+ int namelen;
+ guint8 *databuf;
+ int datalen;
+
+ int err;
+
+ if (!(handle = OBEX_Init(OBEX_TRANS_CUST, btobex_event, 0))) {
+ printf("Init of OBEX failed. %s (%d)", strerror(errno), errno);
+ return -1;
+ }
+
+ bacpy(&btobex_context.bdaddr, bdaddr);
+ btobex_context.channel = channel;
+
+ OBEX_SetUserData(handle, &btobex_context);
+
+ if (OBEX_RegisterCTransport(handle, &btobex_ctrans) < 0) {
+ printf("Custom transport callback registration failed.");
+ return -1;
+ }
|