Joyful Project/android

Android Bluetooth Introduction - Presentation Transcript

deity4u 2010. 5. 19. 15:21

Android Bluetooth Introduction - Presentation Transcript

  1. Android Bluetooth Introduction Erin Yueh 2009/06/26    
  2. Agenda 
    1. ● Android Bluetooth architecture 
    2. ● Related source code 
    3. ● Init Bluetooth  
    4. ● Connect with other BT devices (dbus) 
    5. ● RFCOMM
    6.  ● OBEX (socket)    
  3. Android architecture    
  4. The diagram above offers a library-oriented   view of the Bluetooth stack.  
  5.    
  6. Related source code 
    1. ● Bluez 3.36 (user space and kernel) 
    2.  /mydroid/externel/bluez  /mydroid/kernel/drivers/bluetooth 
    3.  /mydroid/kernel/net/bluetooth 
    4. ● Android app framework (java & c++)  /mydroid/frameworks/base/core/jni/android_bluetooth_*.cpp   /mydroid/frameworks/base/core/java/android/bluetooth/*.java  /mydroid/frameworks/base/services/java/com/android/server/ (SystemServer) ● Android UI application   /mydroid/packages/apps/Phone/src/com/android/phone/ (Phone App)  /mydroid/packages/apps/Settings/src/com/android/settings/bluetooth/ (Settings App)    
  7. Init Bluetooth  
    1. ● /root/init.rc  mkdir /data/misc/hcid (store device info)
    2.  service dbus /system/bin/dbus daemon 
    3. service hcid /system/bin/hcid (disabled) 
    4. service hfag /system/bin/sdptool add  channel=10 HFAG (handsfree, disabled, one shot) 
    5. service hsag /system/bin/sdptool add  channel=11 HSAG (headset, disabled, one shot)
    6.  ● /root/init.trout.rc service hciattach (disabled)  
    7. ● system server decice BT power On or Off from settings value start related services    
  8. ddms: dalvik debug monitor I.    
  9. ddms: dalvik debug monitor II.    
  10. Bluetooth headset Music player + Dialer     
  11. Connect with other BT devices
    1.  ● Bluez: hcid daemon 
    2. ● dbus-daemon: connections between hcid and system server
    3.  ● D-Bus is a simple inter-process communication (IPC) system for software applications to communicate with one another.
    4.  ● dbus-daemon is the D-Bus message bus daemon. D-Bus is first a library that provides one-to-one communication between any two applications; dbus-daemon is an application that uses this library to implement a message bus daemon. Multiple programs connect to the message bus daemon and can exchange messages with one another. 
    5. ● debug utility: d-feet, dbus-monitor, dbus-send    
  12. BlueZ D Bus Architecture     
  13. D Feet: D Bus viewer and debugger    
  14. Dbus send: send a message to a message  bus    
  15. Scan nearby BT devices in Android 
    1. ● Bluez utility: hcitool scan 
    2. ● DiscoverDevices: bluez/util/hcid/dbus­api.txt This method starts the device discovery procedure. This includes an inquiry  procedure and remote device name resolving. On start up this process will  generate a DiscoveryStarted signal and then return DeviceFound singals. If the  procedure has been finished an DiscoveryCompleted signal will be sent.
    3.  ● Source code: android_server_BluetoothDeviceService.cpp /* Compose the command */ msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC, nat >adapter,  DBUS_CLASS_NAME, "DiscoverDevices"); /* Send the command. */ reply = dbus_connection_send_with_reply_and_block(nat >conn, msg,  1, &err);    
  16. Signals    
  17. How to pair with a BT device? I. Register  Passkey Agent    
  18. II. Request PIN code    
  19. RFCOMM (Radio Frequency  Communication)
    1.  ● The Bluetooth protocol RFCOMM is a simple set of  transport protocols. 
    2. ● RFCOMM is sometimes called Serial Port Emulation. 
    3.  ● The Bluetooth Serial Port Profile is based on this protocol.
    4.  ● In the protocol stack, RFCOMM is bound to L2CAP 
    5. ● RFCOMM provides a simple reliable data stream to the  user, similar to TCP. It is used directly by many telephony  related profiles as a carrier for AT commands    
  20. Send AT commands via bluetooth 
    1. ● Connect with Nokia N73 phone 
    2. ● > sdptool browse 00:18:C5:42:18:78
    3.  ● > sudo rfcomm connect 0 00:18:C5:42:18:78 2
    4.  ● minicom ● > AT ● > AT+CGMR ● > AT+CGMI    
  21. OBEX (Object EXchange) 
    1. ● a communications  protocol that  facilitates the  exchange of binary  objects between  devices. 
    2. ● in the protocol stack,  OBEX is bound to  RFCOMM    
  22. SOCKET  
    1. ● UNIX socket  (AF_BLUETOOTH) 
    2. ● inter process  communication 
    3.  ● like Internet socket recv() send() 
    4. ● client server    
  23. Receive files via BT in Android
    1.  ● openobex + obexpushd  
    2.  ● Run an OBEX data server in Android 
    3. ● > obexpushd 
    4. ● listen RFCOMM connections 
    5. ● File permission    
  24. Send files via BT in Android 
    1. ● Openobex + obexftp 
    2. ● Connect to a RFCOMM connection 
    3. ● > obex_test ­b BTADDR CHANNEL
    4.  ● > obexftp  b BTADDR  B CHANNEL  list    
  25. Thank You!