You are on page 1of 4

2009 International Conference on Wireless Networks and Information Systems

File Transferring via BlueTooth Based on The Obex Protocol


Xue ZhangCheng Department of Automation, Xiamen University, Xiamen, Fujian Province 361005, China xuezhangcheng@126.com Wu Shunxiang Department of Automation, Xiamen University, Xiamen, Fujian Province 361005, China wsx1009@163.com

AbstractIn this paper, any type of files could be transferred via Bluetooth between Windows Mobile-based devices which should have Obex support. The Microsoft supplies COM interfaces for developer to use the obex protocol, so the paper primarily uses the obex interface to implement the file transferring. The OBEX protocols enable synchronous and asynchronous device discovery for Windows Mobile-based devices. This article takes use of asynchronous device discovery, so that application uses fewer system resources than synchronous device discovery. In order to send the file, it needs the path of files stored in the device. KeywordsTransmission; Obex; windows mobile; bluetooth; File

The OBEX client API exports an IStream interface to the underlying OBEX protocol. All protocol interaction is abstracted by simple Component Object Model (COM) interfaces.The following diagram illustrates how the Obexsrvr.dll and extensions supplied by Windows Mobile based on Windows Embedded CE are implemented:

I.

INTRODUCTION

Bluetooth is a wireless communication technology that allows devices, within a 10-meter proximity, to communicate with each other. The discovery process enables devices to query other devices about the services they offer. If a device offers more than one service, the user can select the service they want to use from that particular device. The program use the default service-- OBEX inbox (server module) as the destined service which the client would request to show how to implement file transferring based on OBEX protocol. The OBEX protocol is implemented on top of RFCOMM,it is more convinent to transfer files than winsocket based on RFCOMM channel,but The winsocket based on RFCOMM is superior to the OBEX protocol when sending and receiving data stream.Therefore, in this program, it takes the OBEX protocol as the method to transfer files. The OBEX server acts as a protocol translator and forwards packets to the appropriate transport layer. It is implemented as Obexsrvr.dll, Packet interpretation and request servicing is deferred to OBEX server extensions, which are supplied by original equipment manufacturers (OEMs) and independent software vendors (ISVs). The ObexInbx.dll included with Windows Mobile-based devices offers default inbox server extensions that support object pushing and pulling. The solution is taking advantage of the service to transfer files between Windows Mobile and Symbian system. The OBEX Server: The OBEX server runs under Services.exe and forwards OBEX packets to registered handlers. Two default handlers are included in the public samples, filebrowser (Obexfile.dll) and default inbox (Obexinbx.dll). The OBEX Client:
978-0-7695-3901-0/09 $26.00 2009 IEEE DOI 10.1109/WNIS.2009.56

Figure 1. the Obex server and extensions

II.

HOW TO IMPLEMENT FILE TRANSFERRING

The flow chart illustrate the whole flow of file transferring:

Figure 2. The flow of file transferring

77

A. To implement asynchronous device discovery 1) Instantiate an IObex object. 2) Instantiate and implement an IObexSink object. In the program, it create a new class CMyObexSinkEvent inherit the IObexSink Interface as the IObexSink object, because IObexSink interface just supplies the statement of the method without the realization of the method of the interface.The statement of CMyObexSinkEvent is shown belown: class CObexSinkEvent : public IObexSink { public: CObexSinkEvent(void); public: ~CObexSinkEvent(void); STDMETHODIMP QueryInterface(REFIID iid, void** ppvObject); STDMETHODIMP_(ULONG) AddRef(); STDMETHODIMP_(ULONG) Release(); STDMETHODIMP Notify(OBEX_EVENT Event,IUnknown * pUnk1,IUnknown * pUnk2); public: LONG m_cRef; DWORD m_dwCookie; IPropertyBag* g_ProBag; }; 3) Provide a pointer to the CMyObexSinkEvent object to inform the IObex object, as follows: a) Query for the Windows CE IConnectionPointContainer interface. b) Call the method of IconnectionPointContainer:: FindConnectionPoint. c) Use the returned IConnectionPoint value to create the pointer. d) Use the IConnectionPoint::Advise method to register CMyObexSinkEvent object for monitoring to the device support the OBEX service. 4) Use the IObex::StartDeviceEnum method to begin device enumeration.The CMyObexSinkEvent object receives a notification for each device arrival, departure, and update. When a remote device that supports OBEX enters the range of the local device, the CMyObexSinkEvent::Notify method inherit IObex method is called. The method notifies the local device (local CMyObexSinkEvent object) of the arrival of the new device. The CMyObexSinkEvent::Notify method specifies one of the following values for the Event parameter.
TABLE I. Value OE_DEVICE_ARRIVAL Description A new remote device has arrived OE_DEVICE_DEPARTURE

within range of the local device. A previously listed remote device has left the range of the local device. The local device should release its pointer to the remote device and notify the user through the user interface that the remote device is no longer available. A remote device was initially located but did not provide complete information about itself.

OE_DEVICE_UPDATE

5) Do one of the following based on the value specified for the Event parameter: a) OE_DEVICE_ARRIVAL Query for the remote device IPropertyBag to retrieve information about the device, such as the class ID of the transport and the name of the remote device. IPropertyBag is provided by the pUnk1 parameter for the IObexSink::Notify method. To bind the local device to the remote device, call the IObex::BindToDevice method and pass the property bag of the remote device to this method. IObex::BindToDevice returns a pointer, in the form of an IObexDevice interface, to the remote device. Call the IObexDevice::Connect method to connect to the remote device. b) OE_DEVICE_UPDATE To retrieve information about the device, query for the remote device IPropertyBag. 6) Call the IObex::StopDeviceEnum method to stop the device enumeration process at any point. 7) Release the CMyObexSinkEvent::Notify object when the enumeration process is finished so that this object is unadvised to the IObex object. The flow of Discovering OBEX Devices is as below:

78

Figure 3. The flow of discovering the obex device

B. To Send file to the device Once a connection is established, the client can issue the following commands: The method IObexDevice::Put pushes data from the local device to the OBEX server. This method returns destination pointer to the IStream interface, which is used to write the data.When the Put operation has completed, call IStream::Commit before close the operation.The operating is showing below: int CObexFile::SendFile(LPWSTR lpFilePath,LPWSTR lpFileName) { HRESULT hr; IHeaderCollection *pFileHC = 0; hr = CoCreateInstance(CLSID_HeaderCollection,NULL, CLSCTX_INPROC_SERVER, IID_IHeaderCollection,(void **)&pFileHC); if (hr!=S_OK) {.} HANDLE hFile = CreateFile (lpFilePath, GENERIC_READ, FILE_SHARE_READ,NULL,OPEN_EXISTING, 0, NULL); int nFileSize = GetFileSize (hFile, NULL); hr = pFileHC->AddName(lpFileName); if (hr!=S_OK) {..} IStream *stOut = 0; hr = pObexDevice->Put(pFileHC, &stOut); if (FAILED(hr)) {.} BYTE*pSendBuf=new BYTE[SENDBUF]; ZeroMemory(pSendBuf,SENDBUF); int nSize,nCount; DWORD nWrite; nSize=0; while (nSize<nFileSize) { nCount=min(SENDBUF,nFileSize-nSize); if(!ReadFile(hFile,pSendBuf,nCount,&nWrite,NULL)) {} nCount=(int)nWrite; hr=stOut->Write(pSendBuf,nCount,&nWrite); if (hr!=S_OK) {.} nSize=nSize+(int)nWrite; } hr=stOut->Commit (STGC_DEFAULT); pFileHC->Release(); CloseHandle (hFile); return 0; } III. RESULT In the paper,it take two windowsmobile system phones to achieve the function of file transferring.

One of the phone used as server to receive the file must open the bluetooth equipment for being monitored.The other one install the application as the client to search devices supporting the obex server.Once the client find the destined phone,input the file path to the application and click the SendFile button,so that the file will be send to the destined phone,and the process bar is showing the size of file has been send. The process is showing below:

Figure 4. The application is sending the file to the server phone

Figure 5. The server phone is receiving the file

79

needed to improve and I will also make further research on it to improve the funtion,but the application is very valuable to implement the file transferring on the obex layer. ACKNOWLEDGMENT This Project is supported by the Planning Project of the National Eleventh-Five Science and Technology (2007BAK34B04) and the Chinese National Natural Science Fund (60704042) and Aeronautical Science Foundation (20080768004) and the Program of 211 Innovation Engineering on Information in Xiamen University (20092011) REFERENCES
[1] [2] Fuxi,The development of Windows Mobile,People Post Press, Bejing, 2005.

Doudlas Boling,The application designment of Microsoft windows ce, Peking University Press, Beijing, 2006. [3] Li ChunBin,Chen Peng. Embedded Visual C++. Posts and telecom pres,2009. [4] James Y. Wilson, Aspi Havewala.Building Powerful Platform s with Windows CE. 2006.
[5] Figure 6. The complete of receiving [6] David Kammer,Gordon McNutt,Brian Senese,Jennifer Bray.Bluetooth Application Developers Guide:The Short Range Interconnect solution.The Science Press.

IV.

CONCLUSION

The OBEX Application Development. http://msdn.microsoft.com/en-us/library/aa924302.aspx.


OBEX OS Design Development. http://msdn.microsoft.com/enus/library/aa916778.aspx.

[7] [8]

This article demonstrates how to run OBEX on top of the Bluetooth RFCOMM protocol,but OBEX can also be used with other transport media,the article uses the com interface to accomplish the file transferring is more effective than the RFCOMM protocol. The application can transfer any type of files,but it needs the path of file stored in the phone.There is something

Bluetooth OS Design Development. http://msdn.microsoft.com/en-us/library/aa915905.aspx. Application Development. [9] Bluetooth http://msdn.microsoft.com/en-us/library/aa916530.aspx.

80

You might also like