`
`AMC 1021
`AMERICAN MULTI-CINEMA v. Fall Line Patents
`IPR2019-00610
`
`
`
`BLUETOOTH® APPLICATION PROGRAMMING
`WITH THE JAVATM APIs
`
`2
`
`
`
`The Morgan Kaufmann Series in Networking
`
`Series Editor: David Clark, M.I.T.
`Bluetooth Application Programming with the Java APIs
`C Bala Kumar, Paul J. Kline, and Timothy J. Thompson
`Modern Cable Television Technology: Video, Voice, and Data Communications, Second Edition
`Walter Ciciora, James Farmer, David Large, and Michael Adams
`Policy-Based Network Management: Solutions for the Next Generation
`John Strassner
`Computer Networks: A Systems Approach, Third Edition
`Larry L. Peterson and Bruce S. Davie
`Network Architecture, Analysis, and Design, Second Edition
`James D. McCabe
`MPLS Network Management: MIBs, Tools, and Techniques
`Thomas D. Nadeau
`Developing IP-Based Services: Solutions for Service Providers and Vendors
`Monique Morrow and Kateel Vijayananda
`Telecommunications Law in the Internet Age
`Sharon K. Black
`Optical Networks: A Practical Perspective, Second Edition
`Rajiv Ramaswami and Kumar N. Sivarajan
`Internet QoS: Architectures and Mechanisms
`Zheng Wang
`TCP/IP Sockets in Java: Practical Guide for Programmers
`Michael J. Donahoo and Kenneth L. Calvert
`TCP/IP Sockets in C: Practical Guide for Programmers
`Kenneth L. Calvert and Michael J. Donahoo
`Multicast Communication: Protocols, Programming, and Applications
`Ralph Wittmann and Martina Zitterbart
`MPLS: Technology and Applications
`Bruce Davie and Yakov Rekhter
`High-Performance Communication Networks, Second Edition
`Jean Walrand and Pravin Varaiya
`Internetworking Multimedia
`Jon Crowcroft, Mark Handley, and Ian Wakeman
`Understanding Networked Applications: A First Course
`David G. Messerschmitt
`Integrated Management of Networked Systems: Concepts, Architectures, and their Operational
`Application
`Heinz-Gerd Hegering, Sebastian Abeck, and Bernhard Neumair
`Virtual Private Networks: Making the Right Connection
`Dennis Fowler
`Networked Applications: A Guide to the New Computing Infrastructure
`David G. Messerschmitt
`Switching in IP Networks: IP Switching, Tag Switching, and Related Technologies
`Bruce S. Davie, Paul Doolan, and Yakov Rekhter
`Wide Area Network Design: Concepts and Tools for Optimization
`Robert S. Cahn
`
`For further information on these books and for a list of forthcoming titles,
`please visit our website at http://www.mkp.com
`
`3
`
`
`
`BLUETOOTH® APPLICATION
`PROGRAMMING
`WITH THE JAVATM APIs
`
`C BALA KUMAR
`
`PAUL J. KLINE
`
`TIMOTHY J. THOMPSON
`
`MOTOROLA SEMICONDUCTOR PRODUCTS SECTOR
`
`4
`
`
`
`Acquisitions Editor:
`Associate Editor:
`Publishing Services Manager:
`Project Manager:
`Designer:
`Production Services:
`Composition:
`Illustration:
`Printer:
`Cover Printer:
`
`Rick Adams
`Karyn P. Johnson
`Simon G. Crump
`Mamata N. Reddy
`Eric DeCicco
`Graphic World Publishing Services
`Expo
`Dartmouth Publishing
`The Maple-Vail Book Manufacturing Group
`Phoenix Color
`
`Permissions may be sought directly from Elsevier’s Science & Technology Rights
`Department in Oxford, UK. Telephone: (+44) 1865 843830; FAX: (+44) 1865 853333;
`E-mail: permissions@elsevier.com.uk. You may also complete your request online via the
`Elsevier homepage (www.elsevier.com), by selecting “Customer Support” and then
`“Obtaining Permissions.”
`
`Morgan Kaufmann Publishers
`An imprint of Elsevier Inc.
`500 Sansome Street, Suite 400
`San Francisco, CA 94111
`www.mkp.com
`
`© 2004 by Elsevier Inc.
`All rights reserved
`Printed in the United States of America
`
`08 07 06 05 04
`
`5 4 3 2 1
`
`No part of this publication may be reproduced or transmitted in any form or by any
`means, electronic or mechanical, including photocopying, recording, or any
`information storage and retrieval system, without permission in writing from the
`publisher.
`
`MOTOROLA, the Stylized M Logo and all other trademarks indicated as such herein
`are trademarks of Motorola, Inc. registered in the U.S. Patent and Trademark Office.
`The Bluetooth trademark is owned by its proprietor and used by Motorola, Inc. under
`license. Java and all other Java-based terms are trademarks or registered trademarks
`of Sun Microsystems, Inc. in the United States and other countries. All other product
`or service names are the property of their respective owners. © 2003 Motorola, Inc.
`All rights reserved.
`
`Library of Congress Control Number: 2003107476
`International Standard Book Number: 1-55860-934-2
`
`This book is printed on acid-free paper.
`
`5
`
`
`
`To my wife, Sundari, and sons, Sailesh and Shiva
`—Bala
`
`To my wife, Dianne
`—Paul
`
`To my wife, Karmen
`—Tim
`
`6
`
`
`
`This Page Intentionally Left Blank
`
`7
`
`
`
`Contents
`
`LIST OF TABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
`LIST OF FIGURES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
`PREFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
`ACKNOWLEDGMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
`
`CHAPTER 1
`
`Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
`1.1 Wireless Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . .
`1
`1.2 What is Bluetooth Wireless Technology?. . . . . . . . . . . . . .
`3
`1.2.1 History of Bluetooth Wireless Technology . . . . . . . . . .
`4
`1.2.2 Bluetooth Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . .
`5
`1.2.3 Bluetooth Specification . . . . . . . . . . . . . . . . . . . . . . .
`7
`1.3 Overview of the Bluetooth Stack Architecture. . . . . . . . . .
`8
`1.3.1 Bluetooth Protocols . . . . . . . . . . . . . . . . . . . . . . . . . .
`9
`1.3.2 Bluetooth Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
`1.3.3 Bluetooth Qualification . . . . . . . . . . . . . . . . . . . . . . . 13
`1.4 What is J2ME? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
`1.4.1 Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
`1.4.2 Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
`1.4.3 Optional Packages. . . . . . . . . . . . . . . . . . . . . . . . . . . 18
`1.5 Why Java Technology for Bluetooth Devices? . . . . . . . . . . 18
`1.5.1 Java Community Process and JSR-82. . . . . . . . . . . . . . 19
`1.5.2 What about J2SE and PersonalJava? . . . . . . . . . . . . . . 20
`1.5.3 Jini, JXTA, and Bluetooth Networks. . . . . . . . . . . . . . . 20
`1.6 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
`
`CHAPTER 2
`
`An Overview of JABWT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
`2.1 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
`2.1.1 Target Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
`2.1.2 Keeping Up with the Bluetooth Profiles . . . . . . . . . . . 24
`
`vii
`
`8
`
`
`
`viii
`
`Contents
`
`CHAPTER 3
`
`CHAPTER 4
`
`CHAPTER 5
`
`2.1.3 JABWT Use Cases. . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
`2.2 API Characteristics and Hardware Requirements. . . . . . . . 27
`2.2.1 JABWT Specification Characteristics . . . . . . . . . . . . . . 27
`2.2.2 J2ME Device Requirements . . . . . . . . . . . . . . . . . . . . 28
`2.2.3 Bluetooth System Requirements . . . . . . . . . . . . . . . . . 29
`2.3 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
`2.4 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
`
`High-Level Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
`3.1 Architecture of JABWT. . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
`3.1.1 CLDC, MIDP, and JABWT . . . . . . . . . . . . . . . . . . . . . . 35
`3.1.2 Java Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
`3.1.3 Client and Server Model . . . . . . . . . . . . . . . . . . . . . . 37
`3.1.4 Device Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
`3.2 Bluetooth Control Center . . . . . . . . . . . . . . . . . . . . . . . . . 41
`3.2.1 Conflict Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . 42
`3.2.2 Modifying Device Properties . . . . . . . . . . . . . . . . . . . 43
`3.2.3 User Interaction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
`3.2.4 BCC on Devices with No User Interface . . . . . . . . . . . 43
`3.3 Simple JABWT Application . . . . . . . . . . . . . . . . . . . . . . . . 43
`3.4 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
`
`RFCOMM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
`4.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
`4.2 API Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
`4.3 Programming with the API . . . . . . . . . . . . . . . . . . . . . . . . 58
`4.3.1 Establishing a Server Connection . . . . . . . . . . . . . . . . 60
`4.3.2 Establishing a Client Connection . . . . . . . . . . . . . . . . 65
`4.4 Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
`
`OBEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
`5.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
`5.1.1 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
`5.1.2 Protocol Description. . . . . . . . . . . . . . . . . . . . . . . . . . 79
`5.1.3 Example Session. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
`5.2 API Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
`5.3 Programming with the API . . . . . . . . . . . . . . . . . . . . . . . . 87
`5.3.1 Establishing a Connection . . . . . . . . . . . . . . . . . . . . . 88
`5.3.2 Manipulating OBEX Headers . . . . . . . . . . . . . . . . . . . 90
`
`9
`
`
`
`Contents
`
`ix
`
`CHAPTER 6
`
`CHAPTER 7
`
`5.3.3 Sending a Request to the Server . . . . . . . . . . . . . . . . 92
`5.3.4 Receiving a Request from a Client . . . . . . . . . . . . . . . 98
`5.3.5 Using OBEX Authentication . . . . . . . . . . . . . . . . . . . . 102
`5.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
`
`Device Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
`6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
`6.2 API Capabilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
`6.3 Programming with the API . . . . . . . . . . . . . . . . . . . . . . . . 113
`6.3.1 Accessing the Local Device . . . . . . . . . . . . . . . . . . . . 114
`6.3.2 Device Discovery via Inquiry . . . . . . . . . . . . . . . . . . . 125
`6.3.3 Retrieving Information from a Remote Device. . . . . . . 132
`6.3.4 Using the DeviceClass Class . . . . . . . . . . . . . . . . . 135
`6.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
`
`Service Discovery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
`7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
`7.1.1 Key Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
`7.1.2 Services Delivered by Bluetooth Profiles . . . . . . . . . . . 142
`7.1.3 Custom Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
`7.2 API Capabilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
`7.2.1 Run-before-Connect Services . . . . . . . . . . . . . . . . . . . 143
`7.2.2 Servers Are Usually Discoverable . . . . . . . . . . . . . . . . 144
`7.2.3 Register a Service . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
`7.2.4 Modifications to Service Records . . . . . . . . . . . . . . . . 158
`7.2.5 Device Service Classes . . . . . . . . . . . . . . . . . . . . . . . . 160
`7.3 Programming with the API . . . . . . . . . . . . . . . . . . . . . . . . 161
`7.3.1 Automatic Generation of Service Records . . . . . . . . . . 161
`7.3.2 Modifying a Service Record . . . . . . . . . . . . . . . . . . . . 167
`7.3.3 Support for String Attributes in Several
`Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
`7.3.4 Service Records for Bluetooth Profiles. . . . . . . . . . . . . 173
`7.3.5 Service Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
`7.3.6 Working with Service Records . . . . . . . . . . . . . . . . . . 191
`7.3.7 Retrieving Additional Attributes after Service
`Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
`7.3.8 Simple Device and Service Discovery . . . . . . . . . . . . . 199
`7.3.9 Connect-Anytime Services . . . . . . . . . . . . . . . . . . . . . 202
`7.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
`
`10
`
`
`
`x
`
`CHAPTER 8
`
`CHAPTER 9
`
`CHAPTER 10
`
`Contents
`
`L2CAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
`8.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
`8.1.1 L2CAP Channels and L2CAP Packets . . . . . . . . . . . . . 207
`8.1.2 Reasons for Using L2CAP. . . . . . . . . . . . . . . . . . . . . . 208
`8.2 API Capabilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
`8.2.1 JABWT for L2CAP . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
`8.2.2 Open an L2CAP Connection . . . . . . . . . . . . . . . . . . . 212
`8.2.3 L2CAP Channel Configuration . . . . . . . . . . . . . . . . . . 215
`8.2.4 No Flow Control in L2CAP. . . . . . . . . . . . . . . . . . . . . 218
`8.2.5 Types of Applications Using L2CAP . . . . . . . . . . . . . . 220
`8.3 Programming with the API . . . . . . . . . . . . . . . . . . . . . . . . 221
`8.3.1 Example: Echo L2CAP Packets . . . . . . . . . . . . . . . . . . 221
`8.3.2 User Interface for MTU Values . . . . . . . . . . . . . . . . . . 230
`8.3.3 L2CAP Clients and Servers Have the Same
`Capabilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
`8.3.4 Flow Control
`. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
`8.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
`
`Example Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
`9.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
`9.2 Tic-Tac-Toe MIDlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
`9.2.1 Defining the TicTacToeMIDlet . . . . . . . . . . . . . . . 244
`9.2.2 The PauseCanvas and PauseTimerTask
`Helper Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
`9.2.3 Creating the Game Thread . . . . . . . . . . . . . . . . . . . . 257
`9.2.4 Playing the Game . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
`9.3 OBEX Application Download . . . . . . . . . . . . . . . . . . . . . . 288
`9.3.1 The Message Server Application. . . . . . . . . . . . . . . . . 289
`9.3.2 The Message Client Application . . . . . . . . . . . . . . . . . 301
`9.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
`
`Implementing JABWT on a Device . . . . . . . . . . . . . . . . . . . 319
`10.1 Porting Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
`10.2 Steps 1 and 2: Adding J2ME and Bluetooth Support . . . 322
`10.3 Step 3: Implementing JABWT . . . . . . . . . . . . . . . . . . . . . 325
`10.3.1 KVM-Stack Interface . . . . . . . . . . . . . . . . . . . . . . . 327
`10.3.2 Implementing the BCC . . . . . . . . . . . . . . . . . . . . . 330
`10.3.3 OBEX Implementation . . . . . . . . . . . . . . . . . . . . . . 331
`
`11
`
`
`
`Contents
`
`xi
`
`10.4 Step 4: TCK Compliance . . . . . . . . . . . . . . . . . . . . . . . . . 332
`10.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
`
`CHAPTER 11
`
`Closing Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
`
`APPENDIX A
`
`Complete Code Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
`
`APPENDIX B
`
`javax.bluetooth API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
`
`APPENDIX C
`
`javax.obex API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
`
`REFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
`INDEX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
`
`12
`
`
`
`This Page Intentionally Left Blank
`
`13
`
`
`
`List of Tables
`
`Table 7.2
`
`Table 7.3
`Table 7.4
`
`3
`Comparison of Wireless Communication Technologies . . . . . . . . . . . . . . .
`Table 1.1
`Valid Parameters for RFCOMM Connection Strings . . . . . . . . . . . . . . . . . 59
`Table 4.1
`Table 5.1 OBEX Header Constants in the HeaderSet Interface, Their Meaning,
`and Their Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
`Table 5.2 How OBEX Requests Are Translated to Methods by the JSR-82
`Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
`Properties Available through LocalDevice.getProperty() . . . . . . . 116
`Table 6.1
`Table 6.2 Major Service Classes Defined by the Bluetooth SIG . . . . . . . . . . . . . . . . 136
`Table 6.3 Major Device Classes Defined by the Bluetooth SIG. . . . . . . . . . . . . . . . . 137
`Table 7.1
`Service Record Created by Connector.open("btspp:
`//localhost:…") . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
`Some Service Record Attribute IDs Defined by Bluetooth Assigned
`Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
`Examples of Conversions from a 16-Bit UUID to a 128-Bit UUID . . . . . . . 151
`Service Record Created by Connector.open("btl2cap:
`//localhost:…") . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
`Service Record Created by Connector.open("btgoep:
`//localhost:…") . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
`Table 7.6 Methods That Create a Service Record. . . . . . . . . . . . . . . . . . . . . . . . . . 157
`Table 7.7 Methods That Add Service Records to the SDDB . . . . . . . . . . . . . . . . . . . 158
`Table 7.8 Methods That Remove Service Records from the SDDB . . . . . . . . . . . . . . 158
`Table 7.9
`Service Record for a Bluetooth Game . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
`Table 7.10 Selected Attributes from a Service Record with English and
`French Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
`Table 7.11 Service Record Defined by Bluetooth Object Push Profile . . . . . . . . . . . . . 174
`Table 7.12 Service Record for an OBEX Object Push Server. . . . . . . . . . . . . . . . . . . . 176
`Table 7.13 Status Codes for Service Searches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
`Table 7.14 Bluetooth Data Element Types and Their Associated Java Types . . . . . . . . 192
`Table 8.1
`Protocols and Profiles above Line Are Candidates for L2CAP API. . . . . . . . 209
`
`Table 7.5
`
`xiii
`
`14
`
`
`
`This Page Intentionally Left Blank
`
`15
`
`
`
`List of Figures
`
`Figure 1.1
`Figure 1.2
`Figure 1.3
`Figure 1.4
`Figure 1.5
`Figure 1.6
`Figure 1.7
`Figure 1.8
`Figure 2.1
`Figure 2.2
`
`Figure 3.1
`Figure 3.2
`Figure 3.3
`Figure 3.4
`Figure 3.5
`
`Figure 4.1
`Figure 4.2
`
`Figure 4.3
`
`Figure 4.4
`Figure 4.5
`Figure 4.6
`Figure 4.7
`Figure 4.8
`Figure 4.9
`Figure 5.1
`Figure 5.2
`
`5
`Bluetooth SIG timeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
`6
`Bluetooth use cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
`8
`Bluetooth host and device classification. . . . . . . . . . . . . . . . . . . . . . . .
`9
`Bluetooth protocol stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
`Bluetooth profile hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
`Java 2 platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
`Components of J2ME architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
`Jini and JXTA on a Bluetooth device with JABWT. . . . . . . . . . . . . . . . . . 21
`Target devices for JABWT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
`JABWT provides access to selected functionality of the
`Bluetooth stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
`CLDC + MIDP + Bluetooth architecture diagram . . . . . . . . . . . . . . . . . 36
`Package structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
`Bluetooth components involved in service discovery . . . . . . . . . . . . . . . 38
`How the BCC fits into a JABWT implementation . . . . . . . . . . . . . . . . . . 42
`Run using the Impronto Simulator. (a) HelloServer.
`(b) HelloClient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
`Bluetooth profiles defined by the Bluetooth SIG [3] . . . . . . . . . . . . . . . 52
`Multiple Bluetooth connections can exist over a single
`Bluetooth link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
`For two devices to complete the pairing process, a common
`PIN must be entered . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
`Device A attempts to authenticate device B . . . . . . . . . . . . . . . . . . . . . 54
`Example of encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
`GCF defined by CLDC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
`Master connects to slave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
`EchoServer MIDlet when it starts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
`EchoClient (a) and EchoServer (b) communicating over RFCOMM . . . . . 75
`OBEX CONNECT operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
`OBEX SETPATH operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
`
`xv
`
`16
`
`
`
`xvi
`
`List of Figures
`
`Figure 5.3
`Figure 5.4
`Figure 5.5
`Figure 5.6
`Figure 5.7
`Figure 5.8
`
`Figure 5.9
`Figure 5.10
`Figure 6.1
`Figure 6.2
`
`Figure 6.3
`Figure 6.4
`Figure 6.5
`Figure 7.1
`Figure 7.2
`Figure 7.3
`Figure 7.4
`Figure 7.5
`Figure 8.1
`Figure 8.2
`Figure 8.3
`Figure 8.4
`
`OBEX PUT operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
`OBEX DISCONNECT operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
`OBEX client API results from combination of two connection types . . . . 85
`OBEX server API created by combining two well-known APIs . . . . . . . . . 86
`GCF with OBEX API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
`PUT request that combines OutputStream and HeaderSet into
`an OBEX packet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
`Phases of a PUT request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
`Phases of a GET operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
`Cell phone performs a general inquiry. . . . . . . . . . . . . . . . . . . . . . . . . 110
`All general and limited discoverable devices respond to a
`general inquiry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
`BluetoothInfoMIDlet running in J2ME Wireless Toolkit. . . . . . . . . 121
`DiscoveryMIDlet retrieving list of preknown and cached devices. . . 123
`DiscoveryMIDlet after discovering devices via inquiry . . . . . . . . . . 130
`Unlike an inquiry, a service search is between only two devices . . . . . . . 140
`Life cycle of a service record for a run-before-connect service. . . . . . . . . 145
`Example of server modifying its service record . . . . . . . . . . . . . . . . . . . 159
`Example code displays information about the default service record. . . . 162
`Lifecycle of a service record for a connect-anytime service . . . . . . . . . . . 203
`Position of L2CAP in the Bluetooth stack . . . . . . . . . . . . . . . . . . . . . . . 206
`L2CAP channels transmit L2CAP packets to multiple destinations . . . . . 207
`JABWT defines two interfaces for L2CAP communications . . . . . . . . . . . 213
`User interface for MTU experiments. (a) A receiveMTU of
`672 bytes is entered for the server. (b) A transmitMTU of
`500 bytes is entered for the client. . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
`First Screen of Tic-Tac-Toe MIDlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
`Figure 9.1
`Screenshot of TTTCanvas. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
`Figure 9.2
`Figure 10.1 Components of JABWT device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
`Figure 10.2 Components of native Bluetooth device. . . . . . . . . . . . . . . . . . . . . . . . 322
`Figure 10.3 Components of MIDP device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
`Figure 10.4 Device with MIDP and a native Bluetooth stack . . . . . . . . . . . . . . . . . . 323
`Figure 10.5
`Implementation components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
`Figure 10.6 Components of KVM extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
`Figure 10.7 Context-switching in J2ME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
`Figure 10.8 Not blocking the KVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
`Figure 10.9 OBEX implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
`Figure 10.10 JSR-82 TCK setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
`
`17
`
`
`
`Preface
`
`Bluetooth® wireless technology is a short-range radio standard that
`provides new opportunities for wireless devices. This radio standard
`was designed originally as a way of eliminating the cables currently
`attached to nearly all consumer electronic devices. However, the goals
`for Bluetooth wireless technology grew as its designers recognized
`that it enables a new kind of wireless network between electronic
`devices.
`Recent developments in the Java™ programming language make it
`possible for Java developers to write applications for wireless devices
`such as cell phones and personal digital assistants. In 2000, the Java pro-
`gramming community recognized the importance of creating a standard
`extension to the Java programming language for use with Bluetooth
`devices. A standard application programming interface (API) for
`Bluetooth was needed because each Bluetooth software protocol stack
`had its own API for application programmers. These proprietary APIs
`meant that a Bluetooth application had to be ported to different
`Bluetooth stacks to run on different devices. Apart from the work
`involved in writing the code, interoperability testing on the various
`devices cost time and money for the involved companies. A standard
`API would help alleviate all these problems.
`A team of experts from across the industry was assembled for this
`effort under Java Specification Request 82 (JSR-82). The result was a
`specification for Java APIs for Bluetooth wireless technology (JABWT).
`The specification was the result of collaboration of many companies and
`individuals in the industry. Some helped define the specification by
`participating in the JSR-82 expert group, and many others contributed
`by providing valuable comments.
`This book introduces and explains to the community of Java
`programmers the new standard extensions of the Java programming
`language for Bluetooth wireless technology.
`
`xvii
`
`18
`
`
`
`xviii
`
`Preface
`
`Specification documents provide you with the API to which you
`are programming. But a book like this one explains why an API is
`needed and how to use it. In addition, because we were members of the
`Motorola team leading the JSR-82 standardization effort, we believe we
`can explain the rationale for various features of JABWT.
`The objectives of this book are to
`
`• Give an overview of Java 2 Platform, Micro Edition (J2METM) and
`Bluetooth wireless technology
`• Outline the JABWT architecture
`• Explain the API in detail
`• Provide example applications
`• Present the issues related to implementing JABWT on a device
`
`Intended Audience
`The book is intended for software developers, academics, and other
`professionals who want to develop Java software for Bluetooth
`devices. The book also is aimed at device manufacturers who want to
`build devices with Java technology and Bluetooth wireless technol-
`ogy. To gain the most out of this book, you will find it helpful to have
`a working knowledge of J2ME and familiarity with Bluetooth wireless
`technology. The book cites several references that provide additional
`information on these subjects. We believe that a J2ME programmer
`will need no additional reading beyond this book to write JABWT
`applications.
`
`How This Book Is Organized
`Different readers of this book will be seeking different information. We
`have identified three sets of people:
`
`1. Those looking for an overview to make decisions on projects
`2. Those who will be leading projects or managing projects in this
`area
`3. Programmers who need detailed information on how to program
`using JABWT
`
`19
`
`
`
`Preface
`
`xix
`
`Apart from the introductory chapters, the chapters are organized
`into three main sections to accommodate the three sets of people
`identified above. The three divisions are
`
`1. Overview: The executive introduction
`2. API capabilities: The explanation for the project manager
`3. Programming with the API: The programmer’s guide
`
`Readers can choose the sections that suit their needs in each
`chapter. Chapters 1 through 3 are overview chapters. Chapters 4
`through 8 detail the various sections of the API. Chapter 9 provides
`examples of JABWT applications. Chapter 10 explains how device man-
`ufacturers can implement JABWT on a new device. Throughout the
`book many code examples are given to explain the API. The complete
`code for the examples can be found either in the chapters or in
`Appendix A. The complete JSR-82 API is in Appendixes B and C.
`There is a website for this book where you can access the complete
`code examples found in the book. In addition, you can find the latest
`news about JABWT, book errata, and other useful links. To access the
`website, go to www.mkp.com and use the search option with the title of
`this book.
`
`The topics in this book are organized as follows:
`Chapter 1, Introduction, presents an overview of Bluetooth wireless
`technology and J2ME. It also provides a context for the JABWT
`specification.
`Chapter 2, An Overview of JABWT, defines the goals, characteristics,
`and scope of JABWT.
`Chapter 3, High-Level Architecture, presents the high-level architec-
`ture of JABWT.
`Chapter 4, RFCOMM, discusses the APIs for Bluetooth serial port
`communications using RFCOMM.
`Chapter 5, OBEX, introduces the architecture and the APIs for making
`OBEX connections.
`Chapter 6, Device Discovery, discusses the APIs for Bluetooth device
`discovery.
`Chapter 7, Service Discovery, describes the APIs for service discovery
`and service registration.
`Chapter 8, L2CAP, presents the API for Bluetooth communications
`using the logical link control and adaptation protocol.
`
`20
`
`
`
`xx
`
`Preface
`
`illustrates the use of JABWT
`
`Chapter 9, Example Applications,
`through two sample applications.
`Chapter 10, Implementing JABWT on a Device, describes the basic
`porting process and highlights the major issues.
`Chapter 11, Closing Remarks, provides a summary of the topics dis-
`cussed in the book and discusses future trends.
`Appendix A contains code for the examples from Chapters 7 and 8.
`Appendix B contains the Bluetooth API from the package javax.blue-
`tooth.
`Appendix C contains the OBEX API from the package javax.obex.
`
`21
`
`
`
`Acknowledgments
`
`A large number of people were involved with the original development
`of the Java APIs for Bluetooth wireless technology. As the three of us set
`out to write a book explaining those Bluetooth APIs, we were pleased to
`discover that we would again receive contributions and assistance from
`a large number of dedicated and talented individuals.
`The authors thank Glade Diviney, Peter Kembro, and Ashwin
`Kamal Whitchurch for reviewing the entire book in draft form
`and making valuable comments and suggestions. Thanks also to
`R. Thiagarajan, N. Murugan, and Franck Thibaut, who commented on
`various chapters. Ramesh Errabolu, Ranjani Vaidyanathan, and Ravi
`Viswanathan from the Motorola JSR-82 team also reviewed and com-
`mented on several of the chapters. Of course, the authors are totally
`responsible for