summaryrefslogtreecommitdiff
path: root/src/FNetBt_BluetoothSppSystemAdapter.cpp
blob: 11fcc36a6161636f67018533b7453591eac58450 (plain)
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
//
// Open Service Platform
// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
//
// Licensed 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.
//
// @file        FNetBt_BluetoothSppSystemAdapter.cpp
// @brief       This is the implementation file for the _BluetoothSppSystemAdapter class.
//

#include <pthread.h>
#include <FBaseByteBuffer.h>
#include <FBaseString.h>
#include <FBaseUuId.h>
#include <FBaseColArrayList.h>
#include <FBaseColHashMapT.h>
#include <FBaseColIComparerT.h>
#include <FBaseColIHashCodeProviderT.h>
#include <FBaseUtilStringUtil.h>
#include <FNetBtBluetoothTypes.h>
#include <FNetBtBluetoothDevice.h>
#include <FBaseSysLog.h>
#include <FBase_StringConverter.h>
#include "FNetBt_BluetoothSppSystemAdapter.h"
#include "FNetBt_BluetoothGapSystemAdapter.h"
#include "FNetBt_BluetoothDeviceImpl.h"
#include "FNetBt_IBluetoothSocketListener.h"

using namespace std;
using namespace Tizen::Base;
using namespace Tizen::Base::Collection;
using namespace Tizen::Base::Utility;

namespace Tizen { namespace Net { namespace Bluetooth
{

struct _SocketFdDeleter
{
	void operator()(int* serverSocketFd)
	{
		(void) bt_socket_destroy_rfcomm(*serverSocketFd);
	}
};

/*
 * @class		_BluetoothAddressComparer
 * @brief		The _BluetoothAddressComparer class provides the comparer about two specified String
 *              which consists of Bluetooth address and service UUID.
 */
class _BluetoothAddressComparer
	: public Tizen::Base::Collection::IComparerT <Tizen::Base::String>
	, public Tizen::Base::Object
{
public:
	_BluetoothAddressComparer(void){}
	virtual ~_BluetoothAddressComparer(void){}

	virtual result Compare(const Tizen::Base::String& obj1, const Tizen::Base::String& obj2, int& cmp) const
	{
		cmp = obj1.CompareTo(obj2);
		return E_SUCCESS;
	}

private:
	_BluetoothAddressComparer(const _BluetoothAddressComparer& value);
	_BluetoothAddressComparer& operator =(const _BluetoothAddressComparer& value);

};	//_BluetoothAddressComparer

/*
 * @class		_BluetoothAddressHashCodeProviderT
 * @brief		The _BluetoothAddressHashCodeProviderT class provides the hash code of a specified String
 *              which consists of Bluetooth address and service UUID.
 */
class _BluetoothAddressHashCodeProvider
	: public Tizen::Base::Collection::IHashCodeProviderT <Tizen::Base::String>
{
public:
	_BluetoothAddressHashCodeProvider(void) {}
	virtual ~_BluetoothAddressHashCodeProvider(void) {}
	virtual int GetHashCode(const Tizen::Base::String& obj) const
	{
		return obj.GetHashCode();
	}

private:
	_BluetoothAddressHashCodeProvider(const _BluetoothAddressHashCodeProvider& value);
	_BluetoothAddressHashCodeProvider& operator =(const _BluetoothAddressHashCodeProvider& value);

};	//_BluetoothAddressHashCodeProvider


static _BluetoothAddressComparer _btAddressComparer;
static _BluetoothAddressHashCodeProvider _btAddressHashCodeProvider;

_BluetoothSppSystemAdapter* _BluetoothSppSystemAdapter::__pInstance = null;

_BluetoothSppSystemAdapter::_BluetoothSppSystemAdapter(void)
	: __pServerSocketMap(null)
	, __pSocketMap(null)
	, __pClientSocketMap(null)
{
}

_BluetoothSppSystemAdapter::~_BluetoothSppSystemAdapter(void)
{
	// unregister the callback methods from the underlying layer
	(void) bt_socket_unset_connection_state_changed_cb();
	(void) bt_socket_unset_data_received_cb();
	(void) bt_socket_unset_connection_requested_cb();
}

void
_BluetoothSppSystemAdapter::InitSingleton(void)
{
	bool r = false;
	static _BluetoothSppSystemAdapter inst;

	r = inst.Construct();
	SysTryReturnVoidResult(NID_NET_BT, r == true, E_SYSTEM, "[E_SYSTEM] Propagating.");

	__pInstance = &inst;
}

_BluetoothSppSystemAdapter*
_BluetoothSppSystemAdapter::GetInstance(void)
{
	static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;

	if (__pInstance == null)
	{
		ClearLastResult();
		pthread_once(&onceBlock, InitSingleton);
		result r = GetLastResult();
		if (IsFailed(r))
		{
			onceBlock = PTHREAD_ONCE_INIT;
		}
	}

	return __pInstance;
}

bool
_BluetoothSppSystemAdapter::Construct(void)
{
	result r = E_SUCCESS;
	int err = BT_ERROR_NONE;
	unique_ptr< Tizen::Base::Collection::HashMapT<int, _IBluetoothSocketListener*> > pServerSocketMap;
	unique_ptr< Tizen::Base::Collection::HashMapT<int, _IBluetoothSocketListener*> > pSocketMap;
	unique_ptr< Tizen::Base::Collection::HashMapT<Tizen::Base::String, _IBluetoothSocketListener*> > pClientSocketMap;

	pServerSocketMap.reset(new (std::nothrow) HashMapT<int, _IBluetoothSocketListener*>);
	SysTryReturn(NID_NET_BT, pServerSocketMap != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
	r = pServerSocketMap->Construct();
	SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));

	pSocketMap.reset(new (std::nothrow) HashMapT<int, _IBluetoothSocketListener*>);
	SysTryReturn(NID_NET_BT, pSocketMap != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
	r = pSocketMap->Construct();
	SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));

	pClientSocketMap.reset(new (std::nothrow) HashMapT<String, _IBluetoothSocketListener*>);
	SysTryReturn(NID_NET_BT, pClientSocketMap != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
	//construct map with default capacity(16) and loadFactor(0.75f) value.
	r = pClientSocketMap->Construct(16, 0.75f, _btAddressHashCodeProvider, _btAddressComparer);
	SysTryReturn(NID_NET_BT, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));

	err = bt_socket_set_connection_state_changed_cb(&OnSocketConnectionStateChanged, null);
	SysTryReturn(NID_NET_BT, err == BT_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] Registering the callback method has failed.");

	err = bt_socket_set_data_received_cb(&OnSocketDataReceived, null);
	if (err != BT_ERROR_NONE)
	{
		(void) bt_socket_unset_connection_state_changed_cb();
	}
	SysTryReturn(NID_NET_BT, err == BT_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] Registering the callback method has failed.");

	err = bt_socket_set_connection_requested_cb(&OnSocketConnectionRequested, null);
	if (err != BT_ERROR_NONE)
	{
		(void) bt_socket_unset_connection_state_changed_cb();
		(void) bt_socket_unset_data_received_cb();
	}
	SysTryReturn(NID_NET_BT, err == BT_ERROR_NONE, false, E_SYSTEM, "[E_SYSTEM] Registering the callback method has failed.");

	__pServerSocketMap = move(pServerSocketMap);
	__pSocketMap = move(pSocketMap);
	__pClientSocketMap = move(pClientSocketMap);

	return true;
}

result
_BluetoothSppSystemAdapter::OpenServerSocket(const UuId& serviceUuid, _IBluetoothSocketListener& listener, int& serverSocketFd)
{
	int err = BT_ERROR_NONE;
	result r = E_FAILURE;
	unique_ptr<char[]> pUuidStr;
	unique_ptr<int, _SocketFdDeleter> pSocketFd(&serverSocketFd);
	bool isUsed = false;

	pUuidStr.reset(_StringConverter::CopyToCharArrayN(serviceUuid.ToString()));
	SysTryReturnResult(NID_NET_BT, pUuidStr != null, E_INVALID_ARG, "The service UUID is invalid.");

	err = bt_adapter_is_service_used(pUuidStr.get(), &isUsed);
	SysTryReturnResult(NID_NET_BT, (err == BT_ERROR_NONE) && !isUsed, E_SERVICE_UNAVAILABLE,
			"Server socket with the specified service UUID is not available.");

	err = bt_socket_create_rfcomm(pUuidStr.get(), &serverSocketFd);
	SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_FAILURE, "Creating a server socket has failed.");

	err = bt_socket_listen(serverSocketFd, 1);
	SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_FAILURE, "Listen of the server socket has failed.");

	SysLog(NID_NET_BT, "A rfcomm server socket (FD: %d) is created.", serverSocketFd);

	// add the _IBluetoothSocketListener pointer to the server socket map.
	r = __pServerSocketMap->Add(serverSocketFd, &listener);
	SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_FAILURE, "Propagating.");

	pSocketFd.release();

	return E_SUCCESS;
}

result
_BluetoothSppSystemAdapter::CloseServerSocket(const int serverSocketFd)
{
	int err = BT_ERROR_NONE;
	result r  = E_SUCCESS;

	err = bt_socket_destroy_rfcomm(serverSocketFd);
	SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_FAILURE, "Closing the server socket has failed.");
	SysLog(NID_NET_BT, "The server socket (FD: %d) is closed.", serverSocketFd);

	// remove the _IBluetoothSocketListener pointer related to the specified socket FD from the server socket map.
	r = __pServerSocketMap->Remove(serverSocketFd);
	if (r != E_SUCCESS)
	{
		SysLog(NID_NET_BT, "But the server socket could not be removed from the server socket map.");
		// 'r', the error result generated after destroying the socket successfully, is NOT propagated
	}

	return E_SUCCESS;
}

result
_BluetoothSppSystemAdapter::AcceptSocketRequest(int serverSocketFd, int& socketFd)
{
	int err = BT_ERROR_NONE;
	result r  = E_SUCCESS;
	_IBluetoothSocketListener* pListener = null;

	// find the appropriate _IBluetoothSocketListener pointer with the server socket FD.
	r = __pServerSocketMap->GetValue(serverSocketFd, pListener);
	SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_FAILURE, "The server socket number is unknown.");

	err = bt_socket_accept(serverSocketFd, &socketFd);
	SysTryReturnResult(NID_NET_BT, err == BT_ERROR_NONE, E_FAILURE, "Accepting the connection request has failed.");

	SysLog(NID_NET_BT, "The connection request to the server socket (FD: %d) is accepted. (child socket FD: %d)",
			serverSocketFd, socketFd);

	// add the _IBluetoothSocketListener pointer to the socket map.
	// In case for server socket event, _IBluetoothSocketListener pointer is copied from __pServerSocketMap to __pSocketMap
	r = __pSocketMap->Add(socketFd, pListener);
	if (r != E_SUCCESS)
	{
		(void) bt_socket_disconnect_rfcomm(socketFd);
	}
	SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_FAILURE, "Propagating.");

	return E_SUCCESS;
}

result
_BluetoothSppSystemAdapter::RejectSocketRequest(int serverSocketFd)
{
	result r = E_FAILURE;

	if (bt_socket_reject(serverSocketFd) ==  BT_ERROR_NONE)
	{
		r = E_SUCCESS;
	}

	SysLog(NID_NET_BT, "Rejecting the connection request to the server socket (FD: %d) ", serverSocketFd,
				r == E_SUCCESS ? "is successful." : "has failed.");

	return r;
}

result
_BluetoothSppSystemAdapter::ConnectSocket(const ByteBuffer& serverAddress, const UuId& serviceUuid,
									_IBluetoothSocketListener& listener)
{
	result r = E_SUCCESS;
	unique_ptr<char[]> pAddressStr;
	unique_ptr<char[]> pUuidStr;
	int err = BT_ERROR_NONE;
	String address;
	String uuid;
	String key;

	SysTryReturnResult(NID_NET_BT, serverAddress.GetRemaining() == _BT_ADDRESS_LENGTH, E_INVALID_ARG,
						"The address of the remote device is incorrect.");

	uuid = serviceUuid.ToString();
	pUuidStr.reset(_StringConverter::CopyToCharArrayN(uuid));
	SysTryReturnResult(NID_NET_BT, pUuidStr != null, E_INVALID_ARG, "The service UUID is invalid.");

	address = _BluetoothDeviceImpl::GetAddressString(serverAddress);
	pAddressStr.reset(_StringConverter::CopyToCharArrayN(address));
	SysTryReturnResult(NID_NET_BT, pAddressStr != null, E_INVALID_ARG, "The service UUID is invalid.");

	err = bt_socket_connect_rfcomm(pAddressStr.get(), pUuidStr.get());
	SysTryReturnResult(NID_NET_BT, err ==  BT_ERROR_NONE, E_FAILURE, "Connecting to the server has failed.");

	SysLog(NID_NET_BT, "Sending a connection request to [%s] is successful.", pAddressStr.get());

	// add the _IBluetoothSocketListener pointer to the client socket map.
	key = address + String(L"+") + uuid;
	r = __pClientSocketMap->Add(key, &listener);
	if (r != E_SUCCESS)
	{
		// TODO: check the feature that cancels the connection request.
		(void) bt_socket_disconnect_rfcomm(_BT_INVALID_SOCKET_FD);
	}
	SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_FAILURE, "Propagating.");

	return E_SUCCESS;
}

result
_BluetoothSppSystemAdapter::DisconnectSocket(int socketFd)
{
	result r = E_SUCCESS;
	int err = BT_ERROR_NONE;

	// TODO: more detailed error resolution is needed
	err = bt_socket_disconnect_rfcomm(socketFd);
	SysTryReturnResult(NID_NET_BT, err ==  BT_ERROR_NONE, E_FAILURE, "Disconnecting the rfcomm socket has failed.");

	SysLog(NID_NET_BT, "Disconnecting the rfcomm socket (FD: %d) is successful.", socketFd);

	r = __pSocketMap->Remove(socketFd);
	if (r != E_SUCCESS)
	{
		SysLog(NID_NET_BT, "But, The socket (FD: %d) could not be removed from the socket map.", socketFd);
		// 'r', the error result generated after destroying the socket successfully, is NOT propagated
	}

	return E_SUCCESS;
}

result
_BluetoothSppSystemAdapter::SendSocketData(int socketFd, const Tizen::Base::ByteBuffer& data)
{
	result r = E_SUCCESS;
	const byte* pSendData = null;
	int dataLength = 0;

	pSendData = data.GetPointer();
	pSendData += data.GetPosition();
	dataLength = data.GetRemaining();

	if (bt_socket_send_data(socketFd, (char*) pSendData, dataLength) == BT_ERROR_NONE)
	{
		r = E_SUCCESS;
	}
	else
	{
		r = E_SYSTEM;
	}

	SysLog(NID_NET_BT, "Sending data (%d bytes) through the rfcomm socket (FD: %d) %s", dataLength, socketFd,
				r == E_SUCCESS ?"is successful." : "has failed.");

	return r;
}

void
_BluetoothSppSystemAdapter::OnSocketConnectionRequested(int serverSocketFd, const char* pRemoteAddress, void* pUserData)
{
	result r = E_SUCCESS;
	ByteBuffer deviceAddress;
	BluetoothDevice requester;
	String deviceAddressStr(pRemoteAddress);
	_IBluetoothSocketListener* pListener = null;
	_BluetoothSppSystemAdapter* pSppAdapter = _BluetoothSppSystemAdapter::GetInstance();

	// find the appropriate _IBluetoothSocketListener pointer with the server socket FD.
	// the server socket FD is used for distinguishing the recipient from the registered server sockets.
	r = pSppAdapter->__pServerSocketMap->GetValue(serverSocketFd, pListener);
	SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] The socket number is unknown.");

	deviceAddress.Construct(_BT_ADDRESS_LENGTH);
	(void) _BluetoothDeviceImpl::GetAddressByteBuffer(deviceAddressStr, L":", deviceAddress);

	r = _BluetoothGapSystemAdapter::GetPairedDevice(deviceAddress, requester);
	SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Getting information of the request has failed.");

	pListener->OnSocketConnectionRequested(requester);
}

void
_BluetoothSppSystemAdapter::OnSocketConnectionStateChanged(int status, bt_socket_connection_state_e connectionState,
															bt_socket_connection_s* pConnectionInfo, void* pUserData)
{
	result r = E_SUCCESS;
	_IBluetoothSocketListener* pListener = null;
	_BluetoothSppSystemAdapter* pSppAdapter = _BluetoothSppSystemAdapter::GetInstance();

	switch (connectionState)
	{
	case BT_SOCKET_CONNECTED:
		if (pConnectionInfo->local_role == BT_SOCKET_CLIENT)
		{
			SysLog(NID_NET_BT, "Connected event from [address: %s, uuid: %s] is received.",
					pConnectionInfo->remote_address, pConnectionInfo->service_uuid);

			String address(pConnectionInfo->remote_address);
			String uuid(pConnectionInfo->service_uuid);
			String key = address + String(L"+") + uuid;

			// find the appropriate _IBluetoothSocketListener pointer with the server address and the service UUID.
			r = pSppAdapter->__pClientSocketMap->GetValue(key, pListener);
			SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] The server address or the service UUID is unknown.");

			// TODO: more detailed error resolution is needed
			if (status == BT_ERROR_NONE)
			{
				// add the _IBluetoothSocketListener pointer to the socket map.
				// In case for client socket event, the _IBluetoothSocketListener ponter is moved
				// from __pClientSocketMap to __pSocketMap
				r = pSppAdapter->__pSocketMap->Add(pConnectionInfo->socket_fd, pListener);
				if (r != E_SUCCESS)
				{
					SysLogException(NID_NET_BT, E_SYSTEM, "[%s] Propagating. the socket could not be added to the socket map.",
							GetErrorMessage(r));
					r = E_SYSTEM;
				}
			}
			else
			{
				SysLog(NID_NET_BT, "[E_SYSTEM] Connection request failure is reported by the subsystem.");
				r = E_SYSTEM;
			}

			pListener->OnSocketConnectionResponded(pConnectionInfo->socket_fd, r);

			// remove the _IBluetoothSocketListener pointer related to the specified server address and UUID
			// from the client socket map.
			r = pSppAdapter->__pClientSocketMap->Remove(key);
			if (r != E_SUCCESS)
			{
				SysLog(NID_NET_BT, "But the socket could not be removed from the client socket map.");
				// 'r', the error result is ignored.
			}

		}
		// this event is ignored in case of SERVER ROLE.

		break;

	case BT_SOCKET_DISCONNECTED:
		SysLog(NID_NET_BT, "Disconnected event with [socket fd: %d] is received.", pConnectionInfo->socket_fd);

		// find the appropriate _IBluetoothSocketListener pointer with the socket FD
		r = pSppAdapter->__pSocketMap->GetValue(pConnectionInfo->socket_fd, pListener);
		SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] The socket number is unknown.");

		// TODO: more detailed error resolution is needed
		r = ((status == BT_ERROR_NONE) ? E_SUCCESS : E_SYSTEM);

		pListener->OnSocketDisconnected(r);

		// remove the _IBluetoothSocketListener pointer related to the specified socket FD from the socket map.
		r = pSppAdapter->__pSocketMap->Remove(pConnectionInfo->socket_fd);
		if (r != E_SUCCESS)
		{
			SysLog(NID_NET_BT, "But the socket (FD: %d) could not be removed from the socket map.",
					pConnectionInfo->socket_fd);
			// 'r', the error result is ignored.
		}

		break;

	default:
		// ignore other cases
		SysLog(NID_NET_BT, "The connection state is invalid.");
		break;
	}
}

void
_BluetoothSppSystemAdapter::OnSocketDataReceived(bt_socket_received_data_s* pData, void* pUserData)
{
	result r = E_SUCCESS;
	ByteBuffer dataBuffer;
	_IBluetoothSocketListener* pListener = null;
	_BluetoothSppSystemAdapter* pSppAdapter = _BluetoothSppSystemAdapter::GetInstance();

	SysLog(NID_NET_BT, "Data (%d bytes) through the socket (FD: %d) is received.", pData->data_size, pData->socket_fd);

	// find the appropriate _IBluetoothSocketListener pointer with the socket FD
	r = pSppAdapter->__pSocketMap->GetValue(pData->socket_fd, pListener);
	SysTryReturnVoidResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] The socket number is unknown.");

	// TODO: The deep copy should be modified to a shallow copy for better performance
	dataBuffer.Construct(pData->data_size);
	dataBuffer.SetArray((byte*) pData->data, 0, pData->data_size);
	dataBuffer.SetPosition(0);

	pListener->OnSocketDataReceived(dataBuffer);
}

} } }  // Tizen::Net::Bluetooth