]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/obexpush/obexpush/add-obextool.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / obexpush / obexpush / add-obextool.patch
1
2 #
3 # Patch managed by http://www.holgerschurig.de/patcher.html
4 #
5
6 --- obexpush/client/obex_main.c~add-obextool.patch
7 +++ obexpush/client/obex_main.c
8 @@ -221,12 +221,7 @@
9          return NULL;
10      }
11  
12 -
13 -    #ifdef OLDLIBOBEX
14 -    custfunc.userdata = gt->userdata;
15 -    #else //OLDLIBOBEX
16      custfunc.customdata = gt->userdata;
17 -    #endif //OLDLIBOBEX
18      custfunc.connect = cobex_connect;
19      custfunc.disconnect = cobex_disconnect;
20      custfunc.write = cobex_write;
21 --- /dev/null
22 +++ obexpush/client/obextool.c
23 @@ -0,0 +1,411 @@
24 +/*
25 + *
26 + *  Bluetooth OBEX tool
27 + *
28 + *  Copyright (C) 2002  Marcel Holtmann <marcel@holtmann.org>
29 + *
30 + *
31 + *  This program is free software; you can redistribute it and/or modify
32 + *  it under the terms of the GNU General Public License as published by
33 + *  the Free Software Foundation; either version 2 of the License, or
34 + *  (at your option) any later version.
35 + *
36 + *  This program is distributed in the hope that it will be useful,
37 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
38 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39 + *  GNU General Public License for more details.
40 + *
41 + *  You should have received a copy of the GNU General Public License
42 + *  along with this program; if not, write to the Free Software
43 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
44 + *
45 + */
46 +
47 +#include <stdio.h>
48 +#include <errno.h>
49 +#include <fcntl.h>
50 +#include <getopt.h>
51 +#include <string.h>
52 +#include <libgen.h>
53 +#include <stdlib.h>
54 +#include <unistd.h>
55 +#include <sys/stat.h>
56 +#include <sys/time.h>
57 +#include <sys/param.h>
58 +#include <sys/socket.h>
59 +
60 +#include <bluetooth/bluetooth.h>
61 +#include <bluetooth/hci.h>
62 +#include <bluetooth/hci_lib.h>
63 +#include <bluetooth/rfcomm.h>
64 +
65 +#include <glib.h>
66 +#include <openobex/obex.h>
67 +
68 +
69 +
70 +volatile int finished = 0;
71 +
72 +struct btobex_context_t {
73 +       int fd;
74 +       bdaddr_t bdaddr;
75 +       uint8_t channel;
76 +} btobex_context;
77 +
78 +
79 +gint btobex_connect(obex_t *handle, gpointer userdata)
80 +{
81 +       struct btobex_context_t *context = userdata;
82 +       struct sockaddr_rc laddr, raddr;
83 +       int s;
84 +
85 +       if ((s = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
86 +               printf("Can't create socket. %s (%d)\n", strerror(errno), errno);
87 +               return -1;
88 +       }
89 +
90 +       laddr.rc_family = AF_BLUETOOTH;
91 +       bacpy(&laddr.rc_bdaddr, BDADDR_ANY);
92 +       laddr.rc_channel = 0;
93 +       if (bind(s, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {
94 +               printf("Can't bind socket. %s (%d)\n", strerror(errno), errno);
95 +               close(s);
96 +               return -1;
97 +       }
98 +
99 +       raddr.rc_family = AF_BLUETOOTH;
100 +       bacpy(&raddr.rc_bdaddr, &context->bdaddr);
101 +       raddr.rc_channel = context->channel;
102 +       if (connect(s, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) {
103 +               printf("Can't connect. %s (%d)\n", strerror(errno), errno);
104 +               close(s);
105 +               return -1;
106 +       }
107 +
108 +       context->fd = s;
109 +
110 +       return 1;
111 +}
112 +
113 +
114 +gint btobex_disconnect(obex_t *handle, gpointer userdata)
115 +{
116 +       struct btobex_context_t *context = userdata;
117 +
118 +       close(context->fd);
119 +
120 +       return 1;
121 +}
122 +
123 +
124 +gint btobex_listen(obex_t *handle, gpointer userdata)
125 +{
126 +       printf("The listen command is not implemented\n");
127 +
128 +       return -1;
129 +}
130 +
131 +
132 +gint btobex_write(obex_t *handle, gpointer userdata, guint8 *buffer, gint length)
133 +{
134 +       struct btobex_context_t *context = userdata;
135 +
136 +       return (write(context->fd, buffer, length));
137 +}
138 +
139 +
140 +gint btobex_handleinput(obex_t *handle, gpointer userdata, gint timeout)
141 +{
142 +       struct btobex_context_t *context = userdata;
143 +       struct timeval to;
144 +       fd_set fdset;
145 +       unsigned char buf[1024];
146 +       int sel, len;
147 +
148 +       to.tv_sec = timeout;
149 +       to.tv_usec = 0;
150 +
151 +       FD_ZERO(&fdset);
152 +       FD_SET(context->fd, &fdset);
153 +
154 +       len = 0;
155 +
156 +       if ((sel = select(context->fd + 1, &fdset, NULL, NULL, &to)) > 0) {
157 +               if ((len = read(context->fd, buf, sizeof(buf))) > 0)
158 +                       OBEX_CustomDataFeed(handle, buf, len);
159 +       }
160 +
161 +       return len;
162 +}
163 +
164 +
165 +obex_ctrans_t btobex_ctrans = {
166 +       customdata:  &btobex_context,
167 +       connect:     btobex_connect,
168 +       disconnect:  btobex_disconnect,
169 +       listen:      btobex_listen,
170 +       write:       btobex_write,
171 +       handleinput: btobex_handleinput,
172 +};
173 +
174 +
175 +void btobex_event(obex_t *handle, obex_object_t *object, gint mode, gint event, gint obex_cmd, gint obex_rsp)
176 +{
177 +       switch (event) {
178 +       case OBEX_EV_PROGRESS:
179 +               break;
180 +       case OBEX_EV_ABORT:
181 +               printf("Request aborted\n");
182 +               finished = 1;
183 +               break;
184 +       case OBEX_EV_REQDONE:
185 +               finished = 1;
186 +               break;
187 +       case OBEX_EV_REQHINT:
188 +               printf("Request hint\n");
189 +               break;
190 +       case OBEX_EV_REQ:
191 +               printf("Server request\n");
192 +               break;
193 +       case OBEX_EV_LINKERR:
194 +               OBEX_TransportDisconnect(handle);
195 +               printf("Link broken\n");
196 +               break;
197 +       case OBEX_EV_PARSEERR:
198 +               printf("Parse error\n");
199 +               break;
200 +        default:
201 +               printf("Unknown event 0x%02x\n", event);
202 +               break;
203 +       }
204 +}
205 +
206 +
207 +
208 +guint8 *btobex_readfile(const char *filename, int *filesize)
209 +{
210 +       guint8 *buf;
211 +       struct stat stats;
212 +       int fd, fs;
213 +
214 +       stat(filename, &stats);
215 +       fs = stats.st_size;
216 +
217 +       if ((fd = open(filename, O_RDONLY, 0)) < 0)
218 +               return NULL;
219 +
220 +       if (!(buf = g_malloc(fs))) {
221 +               close(fd);
222 +               return NULL;
223 +       }
224 +
225 +       *filesize = read(fd, buf, fs);
226 +
227 +       close(fd);
228 +
229 +       return buf;
230 +}
231 +
232 +
233 +int btobex_push(bdaddr_t *bdaddr, uint8_t channel, char *filename, char *alias)
234 +{
235 +       obex_t *handle;
236 +       obex_object_t *object;
237 +       obex_headerdata_t hd;
238 +
239 +       guint8 namebuf[MAXPATHLEN + 1];
240 +       int namelen;
241 +       guint8 *databuf;
242 +       int datalen;
243 +
244 +       int err;
245 +
246 +       if (!(handle = OBEX_Init(OBEX_TRANS_CUST, btobex_event, 0))) {
247 +               printf("Init of OBEX failed. %s (%d)", strerror(errno), errno);
248 +               return -1;
249 +       }
250 +
251 +       bacpy(&btobex_context.bdaddr, bdaddr);
252 +       btobex_context.channel = channel;
253 +
254 +       OBEX_SetUserData(handle, &btobex_context);
255 +
256 +       if (OBEX_RegisterCTransport(handle, &btobex_ctrans) < 0) {
257 +               printf("Custom transport callback registration failed.");
258 +               return -1;
259 +       }
260 +
261 +       if (OBEX_TransportConnect(handle, (void *)1, 0) != 1)
262 +               return -1;
263 +
264 +
265 +       object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
266 +       err = OBEX_Request(handle, object);
267 +
268 +       finished = 0;
269 +       while (!finished) {
270 +               if ((err = OBEX_HandleInput(handle, 1)) < 0) {
271 +                       printf("Error while handling input.\n");
272 +                       break;
273 +               }
274 +       }
275 +
276 +
277 +       object = OBEX_ObjectNew(handle, OBEX_CMD_PUT);
278 +
279 +       namelen = OBEX_CharToUnicode(namebuf, alias, MAXPATHLEN);
280 +       hd.bs = namebuf;
281 +       OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, namelen, 0);
282 +
283 +       if (!(databuf = btobex_readfile(filename, &datalen))) {
284 +               OBEX_TransportDisconnect(handle);
285 +               return -1;
286 +       }
287 +
288 +       hd.bq4 = datalen;
289 +       OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hd, sizeof(guint32), 0);
290 +
291 +       hd.bs = databuf;
292 +       OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hd, datalen, 0);
293 +
294 +       printf("Sending object ...\n");
295 +
296 +       err = OBEX_Request(handle, object);
297 +
298 +       finished = 0;
299 +       while (!finished) {
300 +               if ((err = OBEX_HandleInput(handle, 1)) < 0) {
301 +                       printf("Error while handling input.\n");
302 +                       break;
303 +               }
304 +       }
305 +
306 +
307 +       object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT);
308 +       err = OBEX_Request(handle, object);
309 +
310 +       finished = 0;
311 +       while (!finished) {
312 +               if ((err = OBEX_HandleInput(handle, 1)) < 0) {
313 +                       printf("Error while handling input.\n");
314 +                       break;
315 +               }
316 +       }
317 +
318 +
319 +       OBEX_TransportDisconnect(handle);
320 +
321 +       return 0;
322 +}
323 +
324 +
325 +
326 +static void usage(void);
327 +
328 +
329 +void cmd_push(bdaddr_t *local, int argc, char **argv)
330 +{
331 +       char *filename;
332 +       char *alias;
333 +       bdaddr_t bdaddr;
334 +       uint8_t channel;
335 +
336 +       if (argc < 3) {
337 +               usage();
338 +               return;
339 +       }
340 +
341 +       filename = argv[1];
342 +       alias = basename(filename);
343 +       str2ba(argv[2], &bdaddr);
344 +       channel = (argc > 3) ? atoi(argv[3]) : 10;
345 +
346 +       btobex_push(&bdaddr, channel, filename, alias);
347 +}
348 +
349 +
350 +struct {
351 +       char *cmd;
352 +       void (*func)(bdaddr_t *bdaddr, int argc, char **argv);
353 +       char *opt;
354 +       char *doc;
355 +} command[] = {
356 +       { "push", cmd_push, "<file> <bdaddr> [channel]", "Push a file" },
357 +       { NULL, NULL, 0, 0 }
358 +};
359 +
360 +
361 +static void usage(void)
362 +{
363 +       int i;
364 +
365 +       printf("Bluetooth OBEX tool\n\n");
366 +
367 +       printf("Usage:\n"
368 +               "\tobextool [options] <command>\n"
369 +                "\n");
370 +
371 +       printf("Options:\n"
372 +               "\t-i [hciX|bdaddr]   Local HCI device or BD Address\n"
373 +               "\t-h, --help         Display help\n"
374 +               "\n");
375 +
376 +       printf("Commands:\n");
377 +        for (i = 0; command[i].cmd; i++)
378 +               printf("\t%-6s %-18s\t%s\n", command[i].cmd,
379 +               command[i].opt ? command[i].opt : " ",
380 +               command[i].doc);
381 +       printf("\n");
382 +}
383 +
384 +
385 +static struct option main_options[] = {
386 +       { "help",       0, 0, 'h' },
387 +       { "device",     1, 0, 'i' },
388 +       { 0, 0, 0, 0 }
389 +};
390 +
391 +
392 +int main(int argc, char *argv[])
393 +{
394 +       bdaddr_t bdaddr;
395 +       int i, opt;
396 +
397 +       bacpy(&bdaddr, BDADDR_ANY);
398 +
399 +       while ((opt = getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
400 +               switch(opt) {
401 +               case 'i':
402 +                       if (strncmp(optarg, "hci", 3) == 0)
403 +                               hci_devba(atoi(optarg + 3), &bdaddr);
404 +                       else
405 +                               str2ba(optarg, &bdaddr);
406 +                       break;
407 +               case 'h':
408 +                       usage();
409 +                       exit(0);
410 +               default:
411 +                       exit(0);
412 +               }
413 +       }
414 +
415 +       argc -= optind;
416 +       argv += optind;
417 +       optind = 0;
418 +
419 +       if (argc < 1) {
420 +               usage();
421 +               exit(0);
422 +       }
423 +
424 +       for (i = 0; command[i].cmd; i++) {
425 +               if (strncmp(command[i].cmd, argv[0], 3))
426 +                       continue;
427 +               command[i].func(&bdaddr, argc, argv);
428 +               exit(0);
429 +       }
430 +
431 +       usage();
432 +
433 +       return 0;
434 +}
435 --- obexpush/client/Makefile~add-obextool.patch
436 +++ obexpush/client/Makefile
437 @@ -35,11 +35,21 @@
438  #
439  
440  ussp-push: obex_main.o obex_socket.o
441 -       gcc obex_main.o obex_socket.o ${GLIBLIB} ${OBEXLIB} -o ussp-push
442 +       $(CC) obex_main.o obex_socket.o ${GLIBLIB} ${OBEXLIB} -o ussp-push
443   
444  obex_main.o: obex_main.c obex_socket.h
445 -       gcc ${OBEXINC} ${GLIBINC} -c obex_main.c -o obex_main.o
446 +       $(CC) ${OBEXINC} ${GLIBINC} -c obex_main.c -o obex_main.o
447  
448  obex_socket.o: obex_socket.c obex_socket.h
449 -       gcc ${OBEXINC} ${GLIBINC} -c obex_socket.c -o obex_socket.o
450 +       $(CC) ${OBEXINC} ${GLIBINC} -c obex_socket.c -o obex_socket.o
451 +
452 +
453 +
454 +obextool: obextool.o
455 +       $(CC) obextool.o ${GLIBLIB} ${OBEXLIB} -lbluetooth -o obextool
456
457 +obextool.o: obextool.c
458 +       $(CC) ${OBEXINC} ${GLIBINC} -c obextool.c -o obextool.o
459 +
460 +all: ussp-push obextool
461