My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**
* BlueCove - Java library for Bluetooth
* Copyright (C) 2006-2008 Vlad Skarzhevskyy
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @version $Id$
*/

#include "common.h"
#include "commonObjects.h"

#ifdef _WIN32_WCE
#define WIDCOMM_CE30
// Even so some the function declared in BTW-CE, use of one will not allow to load dll on our test device Dell Axim X30
#define WIDCOMM_CE_MINUMUM

#ifdef WIDCOMM_CE30
#define WIDCOMM_DLL L"BtSdkCE30.dll"
#else
#define WIDCOMM_DLL L"BtCoreIf.dll"
#endif
#else // _WIN32_WCE
#define WIDCOMM_DLL L"wbtapi.dll"
// DLL wbtapi.dll -> WIDCOMM version 3.x and 4.x and SDK BTW-5_0_1_902-SDK
// DLL btwapi.dll -> WIDCOMM 5.1.x and SDK BTW-5_1_0_3101
#endif // #else // _WIN32_WCE


#ifdef _BTWLIB

#ifdef _WIN32_WCE
#ifdef WIDCOMM_CE30
#pragma comment(lib, "BtSdkCE30.lib")
// Bug in BtSdkCE30.lib. See function CRfCommIf::SetSecurityLevel(unsigned short *,unsigned char,int)
#define WCHAR unsigned short
#else
#define WIDCOMM_DLL L"BtSdkCE50.lib"
#endif
#else // _WIN32_WCE
// BTW-5_1_0_3101
// #pragma comment(lib, "BtWdSdkLib.lib")
// BTW-5_0_1_902-SDK and BTW-6_1_0_1501-SDK
#pragma comment(lib, "WidcommSdklib.lib")

#endif // #else // _WIN32_WCE

//#include "btwlib.h"
#include "BtIfDefinitions.h"
#include "BtIfClasses.h"
#include "com_intel_bluetooth_BluetoothStackWIDCOMM.h"

// Have no idea how we can use BTWPRODUCTVERSION from btversinfo.h
#ifdef ATTR_ID_FAX_1_OR_AUD_VOL_OR_DEV_NAME
#define BTW_SDK_6_0_1_300
#else
#ifdef L2CAP_CONN_CFG_FAILED_NO_REASON
#define BTW_SDK_5_1_0_3101
#else
#define BTW_SDK_5_0_1_902
#endif
#endif

#ifdef BTW_SDK_6_0_1_300
#define BWT_SINCE_SDK_5_0_1
#define BWT_SINCE_SDK_5_1_0
#define BWT_SINCE_SDK_6_0_1
#endif

#ifdef BTW_SDK_5_1_0_3101
#define BWT_SINCE_SDK_5_0_1
#define BWT_SINCE_SDK_5_1_0
#endif

#ifdef BTW_SDK_5_0_1_902
#define BWT_SINCE_SDK_5_0_1
#endif

// Used for MS stack detection
#include <winsock2.h>

#ifndef _WIN32_WCE
#ifdef VC6
#define AF_BTH 32
#define BTHPROTO_RFCOMM 0x0003
#else
#include <ws2bth.h>
#endif // VC6
#else
#define AF_BTH 32
#define BTHPROTO_RFCOMM 0x0003
#endif // _WIN32_WCE

void BcAddrToString(wchar_t* addressString, BD_ADDR bd_addr);

jlong BcAddrToLong(BD_ADDR bd_addr);

void LongToBcAddr(jlong addr, BD_ADDR bd_addr);

jint DeviceClassToInt(DEV_CLASS devClass);

typedef struct {
jlong deviceAddr;
jint deviceClass;
BD_NAME bdName;
DEV_CLASS devClass;
} DeviceFound;

#define DEVICE_FOUND_MAX 50
#define SDP_DISCOVERY_RECORDS_USED_MAX 300
#define SDP_DISCOVERY_RECORDS_DEVICE_MAX 50
#define SDP_DISCOVERY_RECORDS_HOLDER_MARK 70000
#define SDP_DISCOVERY_RECORDS_HANDLE_OFFSET 1
// 7 for Server and 7 for Client, Bluetooth Can't have more
#define COMMPORTS_POOL_MAX 100
#define OPEN_COMMPORTS_MAX 14

class WIDCOMMStackRfCommPort;
class WIDCOMMStackServerConnectionBase;
class WIDCOMMStackRfCommPortServer;
class WIDCOMMStackL2CapConn;
class WIDCOMMStackL2CapServer;

class DiscoveryRecHolder {
public:
BOOL oddHolder;
int sdpDiscoveryRecordsUsed;
CSdpDiscoveryRec sdpDiscoveryRecords[SDP_DISCOVERY_RECORDS_USED_MAX];

DiscoveryRecHolder();
};

class WIDCOMMStack : public CBtIf {
public:
HANDLE hEvent;

DeviceFound deviceResponded[DEVICE_FOUND_MAX];
int deviceRespondedIdx;
BOOL deviceInquiryInProcess;
BOOL deviceInquiryTerminated;
BOOL deviceInquiryComplete;
BOOL deviceInquirySuccess;

BOOL searchServicesComplete;
BOOL searchServicesTerminated;

// Switch this buffers sequencialy when current if full
DiscoveryRecHolder* discoveryRecHolderCurrent;
DiscoveryRecHolder* discoveryRecHolderHold;

BOOL delayDeleteComm;
ObjectPool* commPool;
// CRfCommIf shared by application, lock it when connection is made
CRITICAL_SECTION csCommIf;
CRfCommIf rfCommIfClient;
//CRfCommIf rfCommIf;

WIDCOMMStack();
virtual ~WIDCOMMStack();
void destroy(JNIEnv * env);

void throwExtendedBluetoothStateException(JNIEnv * env);
char* getExtendedError();

// methods to replace virtual methods in base class CBtIf
virtual void OnDeviceResponded(BD_ADDR bda, DEV_CLASS devClass, BD_NAME bdName, BOOL bConnected);
virtual void OnInquiryComplete(BOOL success, short num_responses);

virtual void OnDiscoveryComplete();

void deleteConnection(PoolableObject* object);

WIDCOMMStackRfCommPort* createCommPort();
WIDCOMMStackRfCommPortServer* createCommServer();

WIDCOMMStackL2CapConn* createL2CapConn();
WIDCOMMStackL2CapServer* createL2CapServer();
};

BOOL isValidStackObject(PoolableObject* object);

extern WIDCOMMStack* stack;

// --- Client RFCOMM connections

WIDCOMMStackRfCommPort* validRfCommHandle(JNIEnv *env, jlong handle);
WIDCOMMStackRfCommPortServer* validRfCommServerHandle(JNIEnv *env, jlong handle);

class WIDCOMMStackConnectionBase : public PoolableObject {
public:
BOOL isClosing;
BOOL isConnected;
HANDLE hConnectionEvent;

GUID service_guid;
BT_CHAR service_name[BT_MAX_SERVICE_NAME_LEN + 1];

WIDCOMMStackServerConnectionBase* server;

WIDCOMMStackConnectionBase();
virtual ~WIDCOMMStackConnectionBase();

virtual void close(JNIEnv *env, BOOL allowExceptions) = 0;
};

class WIDCOMMStackRfCommPort : public CRfCommPort, public WIDCOMMStackConnectionBase {
public:

int isConnectionErrorType;
BOOL isConnectionError;

HANDLE hDataReceivedEvent;
HANDLE hDataTransmitEvent;

UINT32 other_event_code;

ReceiveBuffer receiveBuffer;

WIDCOMMStackRfCommPort();
virtual ~WIDCOMMStackRfCommPort();

void readyForReuse();
void resetReceiveBuffer();

virtual void close(JNIEnv *env, BOOL allowExceptions);

virtual void OnEventReceived(UINT32 event_code);
virtual void OnDataReceived(void *p_data, UINT16 len);
};

class WIDCOMMStackServerConnectionBase : public WIDCOMMStackConnectionBase {
public:
CSdpService* sdpService;
//Use in finalizeSDPRecord
BOOL sdpRecordCommited;
GUID* service_guids;
int service_guids_len;
tSDP_PROTOCOL_ELEM* proto_elem_list;
int proto_num_elem;

WIDCOMMStackConnectionBase* conn[OPEN_COMMPORTS_MAX];


WIDCOMMStackServerConnectionBase();
virtual ~WIDCOMMStackServerConnectionBase();

void addClient(WIDCOMMStackConnectionBase* c);
void closeClient(JNIEnv *env, WIDCOMMStackConnectionBase* c);
virtual void close(JNIEnv *env, BOOL allowExceptions);

BOOL finalizeSDPRecord(JNIEnv *env);
};

class WIDCOMMStackRfCommPortServer : public WIDCOMMStackServerConnectionBase {
public:
UINT8 scn;

CRfCommIf rfCommIf;

WIDCOMMStackRfCommPortServer();
virtual ~WIDCOMMStackRfCommPortServer();
};

// --- Client and Server L2CAP connections

WIDCOMMStackL2CapConn* validL2CapConnHandle(JNIEnv *env, jlong handle);
WIDCOMMStackL2CapServer* validL2CapServerHandle(JNIEnv *env, jlong handle);

class WIDCOMMStackL2CapConn : public CL2CapConn, public WIDCOMMStackConnectionBase {
public:
CL2CapIf* pL2CapIf;

BOOL isDisconnected;

UINT16 receiveMTU;
UINT16 transmitMTU;
UINT16 connectionTransmitMTU;

HANDLE hDataReceivedEvent;
ReceiveBuffer receiveBuffer;

WIDCOMMStackL2CapConn();
virtual ~WIDCOMMStackL2CapConn();

virtual void close(JNIEnv *env, BOOL allowExceptions);

void selectConnectionTransmitMTU(JNIEnv *env);

virtual void OnConnected();
virtual void OnDataReceived(void *p_data, UINT16 length);
virtual void OnRemoteDisconnected(UINT16 reason);

//Server
virtual void OnIncomingConnection();
};

class WIDCOMMStackL2CapServer : public WIDCOMMStackServerConnectionBase {
public:
CL2CapIf l2CapIf;

UINT16 receiveMTU;
UINT16 transmitMTU;

WIDCOMMStackL2CapServer();
virtual ~WIDCOMMStackL2CapServer();

virtual void close(JNIEnv *env, BOOL allowExceptions);
};

#endif // _BTWLIB

Change log

r2519 by skarzhevskyy on Dec 6, 2008   Diff
Even so some the function declared in BTW-
CE, use of one will not allow to load dll
on our test device Dell Axim X30
Go to: 
Project members, sign in to write a code review

Older revisions

r2416 by skarzhevskyy on Oct 9, 2008   Diff
Change license to Apache License,
Version 2.0
r2408 by skarzhevskyy on Oct 9, 2008   Diff
organize product to modules
r2310 by skarzhevskyy on Jun 27, 2008   Diff
Allow update of serviceClassIDList SDP
record
All revisions of this file

File info

Size: 8807 bytes, 325 lines

File properties

svn:mime-type
text/plain
svn:eol-style
CRLF
svn:keywords
Date Author Id Revision
Powered by Google Project Hosting