File: obex.h

package info (click to toggle)
affix 2.1.1-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,908 kB
  • ctags: 1,247
  • sloc: ansic: 13,807; sh: 7,119; yacc: 232; makefile: 152; lex: 126; python: 56
file content (194 lines) | stat: -rw-r--r-- 4,685 bytes parent folder | download
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* 
   Affix - Bluetooth Protocol Stack for Linux
   Copyright (C) 2001 Nokia Corporation
   Original Author: Dmitry Kasatkin <dmitry.kasatkin@nokia.com>

   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.
*/

/* 
   $Id: obex.h,v 1.22 2003/03/02 16:09:18 kds Exp $

   OBEX client lib 

   Fixes:
   		Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
*/		

#ifndef OBEX_CLIENT_H
#define OBEX_CLIENT_H

#include <termios.h>
#include <stdint.h>
#include <openobex/obex.h>

#include <affix/utils.h>

__BEGIN_DECLS

#if defined(CONFIG_AFFIX_SDP)
#include "sdp.h"
#include "sdpclt.h"
#endif

#ifndef OPENOBEX_VERSION
#define OPENOBEX_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#endif

#define OBEX_LS		1
#define OBEX_PUT	2
#define OBEX_GET	3
#define OBEX_SETPATH	4
#define OBEX_PUSH	5
#define OBEX_REMOVE	6
#define OBEX_PULL	7

/* Number of bytes passed at one time to OBEX */
#define OBEX_STREAM_CHUNK	4096

typedef struct {
	uint8_t		len;
	uint8_t		*data;
} obex_target_t;

typedef struct {
	obex_t		*handle;
	int		fd;		/* rfcomm socket */
       	int		clientdone;

	uint32_t	conid;		/* connection id */
	int		rsp;		/* error code */
	int		opcode;		/* internal operation code */
	char		*buf;		/* response storage place */
	int		sfd;		/* stream fd */
	
	uint16_t	family;
} obexclt_t;

/* connect/disconnect */
obexclt_t *obex_connect(struct sockaddr_affix *addr, obex_target_t *target, int *err);
int obex_disconnect(obexclt_t *clt);

int obex_get(obexclt_t *clt, char *local, char *remote, char *type);
int obex_put(obexclt_t *clt, char *local, char *remote, char *type);
/* -- file -- */
int obex_remove(obexclt_t *clt, char *name);
int obex_get_file(obexclt_t *clt, char *local, char *remote);
int obex_put_file(obexclt_t *clt, char *local, char *remote);

#define SETPATH_CREATE	0x0001
int __obex_setpath(obexclt_t *clt, char *path, int flags);

extern obex_target_t	file_target;

static inline obexclt_t *obex_connect_file(struct sockaddr_affix *addr, int *err)
{
	return obex_connect(addr, &file_target, err);
}

static inline int obex_browse(obexclt_t *clt, char *local, char *name)
{
	return obex_get(clt, local, name, "x-obex/folder-listing");
}

static inline int obex_setpath(obexclt_t *clt, char *path)
{
	return __obex_setpath(clt, path, 0);
}

static inline int obex_mkdir(obexclt_t *clt, char *path)
{
	int	err;
	err = __obex_setpath(clt, path, SETPATH_CREATE);
	if (!err)
		err = __obex_setpath(clt, "..", 0);
	return err;
}


/* -------------------------------------------------------------- */

#define CHDIR_CHECK_ONLY		0x0001
#define CHDIR_CREATE_IF_NOT_EXIST	0x0002
#define CHDIR_CREATE_RECURSIVE		0x0004

typedef struct obex_common_hdr {
	uint8_t  opcode;
	uint16_t len;
} __PACK__ obex_common_hdr_t;

typedef struct obex_connect_hdr {
	uint8_t  version;
	uint8_t  flags;
	uint16_t mtu;
} __PACK__ obex_connect_hdr_t;


typedef struct obex_setpath_hdr {
	uint8_t  flags;
	uint8_t	constants;
} __PACK__ obex_setpath_hdr_t;


enum obexsrv_state {
	SRVSTATE_IDLE = 0,
	SRVSTATE_CLOSED
};

typedef struct _obexsrv_t	obexsrv_t;

struct _obexsrv_t {
	obex_t		*handle;
	int		state;
	int		flags;
        int		serverdone;
	int		streamming;
        char		*name;
	int		sfd;
	char		*buf;

	/* callbacks */
	int 		(*connect)(obexsrv_t *srv, obex_target_t *target);
	int 		(*put)(obexsrv_t *srv, char *file, char *name, char *type, int flags);
	int 		(*get)(obexsrv_t *srv, char *name, char *type);
	int 		(*setpath)(obexsrv_t *srv, char *path, int flags);
	void 		(*disconnect)(obexsrv_t *srv);
};

int obexsrv_run(obexsrv_t *srv, int rfd, int wfd);
void obexsrv_set_file(obexsrv_t *srv, char *name, int del);


/* ----------------------------------------------------- */

typedef struct {
	char	*name;
	int	fd;
	void	*map;
	int	map_size;
} obex_file_t;

obex_file_t *obex_create_file(char *name);
void obex_close_file(obex_file_t *file);
int obex_open_file(obex_file_t *file);
void obex_destroy_file(obex_file_t *file, int del);
char *obex_map_file(obex_file_t *file);

char *obex_error(int err);

__END_DECLS

#endif