CALIFORNIA SOFTWARE LABS R E A L I Z E Y O U R I D E A S California Software Labs 6800 Koll Center Parkway, Suite 100 Pleasanton CA 94566, USA. Phone (925) 249 3000 Fax (925) 426 2556 info@cswl.com http://www.cswl.com
Mobile printing on HP printers with Bluetooth from Palm OS 5.0 A Technical Report INDEX INTRODUCTION... 3 MOBILE PRINTING TODAY... 3 PRINTER DRIVERS... 3 DRIVER-LESS PRINTING... 4 BLUETOOTH TECHNOLOGY... 5 BLUETOOTH TECHNOLOGY... 5 BLUETOOTH SPECIFICATION OVERVIEW:... 6 Bluetooth Protocol Stack... 6 What is a Bluetooth Profile?... 7 COMMUNICATION BETWEEN BLUETOOTH DEVICES... 7 BLUETOOTH PROFILE OVERVIEW... 8 BLUETOOTH SECURITY... 8 PALM OS SUPPORT FOR BLUETOOTH... 9 Palm OS Bluetooth architecture... 9 MOBILE PRINTING SUPPORT FOR HP PRINTERS... 11 BLUETOOTH SUPPORT FOR HP PRINTERS... 11 BLUETOOTH PRINTING SUPPORT... 11 BASIC PRINTING PROFILE... 11 SAMPLE INTEGRATION AND IMPLEMENTATION... 12 SAMPLE PROGRAMMING ON PALMOS... 12 OVERVIEW OF IMPLEMENTATION... 13 Pre-requisite for Palm Bluetooth development:... 13 Implementation:... 13 SOURCE-CODE BASICS... 15 Opening serial Port code:... 15 Sending data over serial Port code:... 16 Close serial Port code:... 16 CONCLUSION... 16 REFERENCES:... 17 CSWL Inc, Pleasanton, California - 2
Introduction This document aims to provide some basics of using the Bluetooth technoloy for mobile printing, from a Palm handheld. Mobile printing techniques are introduced first, followed by a brief coverage of Bluetooth technology. Subsequently, features of the Bluetooth stack as it applies to PalmOs 5 are taken up. The discussion ends with sample code snippets that demonstrate communication with a Bluetooth enabled printer, such as certain HP Deskjets. Mobile Printing Today Mobile Printing is the term used for printing from mobile devices such as a Palm handheld, a laptop, a PocketPC or similar device, without cables and without complex printer drivers, and directed towards a printer in the vicinity. Mobile printing is essentially wireless printing. Depending on the capabilities of the mobile device, and that of the printer, the following scenarios are possible: Printing via printer drivers. Driver-less printing Printer drivers Printer drivers are printer-specific code, and not very suitable for smaller devices. They are useful in mobile devices like notebooks that run operating systems such as Windows and Linux. However, it is possible to address a whole family of printers (such as the DeskJet series from HP) using a monolithic driver built from toolkits such as the HP APDK. While it is possible to have specific printer drivers loaded on devices such as a Palm handheld, this generally curtails mobility, restricting printing to those printers alone. CSWL Inc, Pleasanton, California - 3
Driver-less printing With mobile devices having smaller footprints of memory, display and other resources, driver-less printing is the method of choice. To support this, the following techniques are used: Dynamic Printer discovery Identification of document to print Sending a print stream to the printer Dynamic printer discovery is possible using protocols such as Bluetooth, IrDA, UPnP, and through next generation print services on the LAN (WiFi) or WAN (cellular - GSM/GPRS/CDMA2000). In the latter case, a print service way be discovered on the local wireless LAN, or an ISP hosted service may be consulted, with the requests routed via a VPN to a corporate setting. This would result in a user selection from a choice of printers offered. As of this writing such protocols have been established and are being implemented (for details, see Printer Working Group at www.pwg.org). Identifying the document to print could be accomplished in a number of ways. For devices such as a mobile phone, a URL is one option. For less heavy content, the document may be present on the device itself. Sending a print stream to the printer after discovery can be done in the following ways: Send a URL to the printer. Printer can fetch the URL content, transform to a print stream (perhaps using another print service) and print Send the URL to a print service with printer description. Proper print stream formatting may be done by the print service. The resulting stream may be sent from the print service to the printer directly, or siphoned through the mobile device to the printer. CSWL Inc, Pleasanton, California - 4
Use a standard document format such as XHTML and send the stream to the printer Use a standard protocol such as IPP (Internet Printing Protocol), which is supported by many new printers. Use Generic Object Exchange formats used in printing address books, business cards etc. Many printers support this. Bluetooth technology Bluetooth Technology The Bluetooth technology is an open specification for short-range wireless communication between electronic devices. It has become a standard for interconnecting small mobile devices in wireless world. Bluetooth specification is developed, published and promoted by Bluetooth Special Interest Group (SIG). Bluetooth technology is used for Wireless Personal Area Networks (WPANs) with range around 10 m. It is a low-power short-range radio communication technology. The characteristic of the technology offers lot of advantages as listed below: Low power requirement makes it ideal for small mobile devices, which run on battery. Low Cost makes it ideal for mobile device manufactures to built in Bluetooth support. Short Range of 10 m makes ideal for mobile users to connect to other mobile device in a room or adjacent room eliminating wired connection. Transmission speed of 800 kbps makes it good enough for transferring small to medium size files. 2.4 GHz ISM band enabling developing devices and solutions, which can work worldwide. CSWL Inc, Pleasanton, California - 5
Bluetooth Security, specification provides support for security at its core protocol level, includes authentication, encryption and secure link. Bluetooth specification overview: Bluetooth Protocol Stack The below diagram show the core building layers of the Bluetooth architecture. Source www.palmos.com Baseband The baseband layer and the link control layer enable the physical Radio Frequency (RF) link between Bluetooth devices. Two kinds of physical links can be formed with their corresponding baseband packets: Synchronous Connection-Oriented (SCO) and Asynchronous Connectionless (ACL). Link Manager Protocol (LMP) The Link Manager Protocol is responsible for setting up the link between Bluetooth devices. This includes security aspects like authentication and encryption by generating, exchanging, and checking of link and encryption keys. Logical Link Control and Adaptation Protocol (L2CAP) L2CAP provides both connection-oriented and connectionless data services to the upper layer protocols with protocol multiplexing capability, segmentation and reassembly operation, and group abstractions. L2CAP is defined only for ACL links and not supported for SCO links, as specified by the Bluetooth Specification. CSWL Inc, Pleasanton, California - 6
Service Discovery Protocol (SDP) SDP is used to get specific information about a remote device, such as available services. Using SDP characteristics of these services can be queried. RFCOMM The RFCOMM protocol provides emulation of serial ports over the L2CAP protocol. The protocol is based on the ETSI standard TS 07.10. Only a subset of the TS 07.10 standard is used, and some adaptations of the protocol are specified in the Bluetooth RFCOMM specification. What is a Bluetooth Profile? The Bluetooth Specification defines a set of usage models or scenarios for using Bluetooth enabled radio devices. These usage modules, referred to as profiles, define standard ways of communicating with Bluetooth-enabled devices. It is intended to reduced the risk of interoperability issues between different manufacturers and provide a basis for the development of a common set of functions that Bluetooth enable devices will support. A profile does not need to include all the protocols defined in the Bluetooth protocol stack. It can be a subset of various protocols in the stack Communication between Bluetooth devices Piconets (a, b) and Scatternet (C) (Source www.palmos.com) Point-to-Point connection: In this type of connection, only two Bluetooth devices are involved. One device acts as a master and other as a slave. The two devices form a network called Piconet. CSWL Inc, Pleasanton, California - 7
Point-to- Multipoint: In this type of connection, two or more (Max 8) Bluetooth devices are involved. One device acts as a master and others act as a slave. These devices form a network called Piconet. Scatternet: Two or more Piconet when connected form a Scatternet. Bluetooth Profile Overview Bluetooth specification v1.1 includes following general profiles: 1. General Access Profile 2. Service Discovery Application Profile 3. Cordless Telephony Profile 4. Intercom Profile 5. Serial Port profile 6. Headset Profile 7. Dial-up Networking Profile 8. Fax Profile 9. LAN Profile 10. Generic Object Exchange Profile 11. Object Push Profile 12. File Transfer Profile 13. Synchronization Profile Additional profiles for a Printing usage model: 1. Basic Printing Profile 2. Hardcopy cable replacement Profile Bluetooth Security Bluetooth security includes both authentication and encryption, and is based around the SAFER+ encryption algorithm. CSWL Inc, Pleasanton, California - 8
Palm OS support for Bluetooth Palm OS 5.0 has a built in support for Bluetooth. Palm OS Bluetooth architecture (Reference: Palm documentation www.palmos.com) Recent releases of Palm OS includes a Bluetooth stack and SDK for developers. The Palm Bluetooth SDK includes the Palm bluetooth library and bluetooth specific drivers. As of this writing, PalmOS does not support all Bluetooth profiles. In the diagram, the profiles marked in red are not supported on Palm. CSWL Inc, Pleasanton, California - 9
(Source www.palmos.com) Bluetooth specifications specify three security modes for a device. Security mode 1 (non-secure): A device will not initiate any security procedure. Security mode 2 (service-level enforced security): A device does not initiate security procedures before channel establishment at L2CAP level. This mode allows different and flexible access policies for applications, especially running applications with different security requirements in parallel. Security mode 3 (link level enforced security): A device initiates security procedures before the link set-up at the LMP level is completed. Palm currently supports security modes 1 and 2. CSWL Inc, Pleasanton, California - 10
Mobile printing support for HP Printers Bluetooth support for HP Printers HP has included built-in support for Bluetooth in its mobile printer DeskJet 995c. Other printers may be expected to follow suit. In any case, HP also makes available Bluetooth printer adapters so that existing printers may be Bluetooth enabled. HP s Mobile printing initiative and associated software also has Bluetooth as a key ingredient. Bluetooth Printing Support Bluetooth specification has define following profile related to printing Basic Printing profile (BPP): Supports driverless printing for mobile devices such as mobile phones, pagers, and PDAs. BPP is explained below. Hard Copy Replacement profile The data is rendered through the use of a driver on the client device like mobile laptops and desktop computer. Basic Printing profile This application profile defines the application requirements for Bluetooth devices necessary for the support of the Basic Printing usage model. This Profile makes use of the Generic Object Exchange Profile (GOEP) to define the interoperability requirements for the protocols needed by applications. The most common devices using these usage models are mobile devices such as mobile phones, pagers, and PDAs, although more complex devices are not excluded. Usage models include printing of text emails, short messages, and formatted documents. Optional support for the printing of structured data objects such as vcard and vcalendar is also defined, as well as methods for negotiating the use of other formats supported by the printer. CSWL Inc, Pleasanton, California - 11
The Basic Printing Profile is dependent on the Generic Object Exchange, Serial Port, and Generic Access Profiles. Source www.bluetooth.org Sample Integration and Implementation Sample programming on PalmOs A sample mobile printing application was developed to print to an HP995c printer from Palm Tungsten OS 5.0 using Bluetooth wireless technology. Platform and Devices considered for sample implementation: Palm OS 5.0 Palm OS 5.0 has a built-in support for Bluetooth in its architecture. CSWL Inc, Pleasanton, California - 12
Palm OS supports Service Discovery Profile, Serial Port profile and Object Push profile. HP DeskJet 995c HP 995c has built-in support for Bluetooth. It supports Service Discovery Profile, Serial Port Profile and Object push Bluetooth profiles. Overview of Implementation Pre-requisite for Palm Bluetooth development: Palm OS SDK: Palm OS SDK can be downloaded from website. They have a developer program to which we can register and get the SDK, which has a support for Bluetooth. Palm Tungsten: Palm Tungsten is the current lastest model of Palm which comes with Palm OS 5.0. Development Environment: Metrowerks CodeWarrior or Falch.Net developer studio. Implementation: 1. Simple Palm OS application was created. 2. Palm Bluetooth library support was included in the application. The Palm Bluetooth Library is a shared library that provides an API for developing Bluetooth enabled application. The API provides functions in the following areas: Managing remote devices, piconets Communicating with Bluetooth devices at L2CAP and RFCOMM protocol level. Advertising services and querying for remote services using SDP Maintaining a list of trusted devices An applications should check if the Bluetooth system is running on the handheld before using any Bluetooth APIs. To do so, the following code was include in the Application open routine: UInt32 btversion; // Make sure Bluetooth components are installed CSWL Inc, Pleasanton, California - 13
// This check also ensures Palm OS 4.0 or greater if (FtrGet(btLibFeatureCreator, btlibfeatureversion,&btversion)!= errnone) { // Alert the user if it's the active application if ((launchflags & sysapplaunchflagnewglobals) && (launchflags & sysapplaunchflaguiapp)) FrmAlert (MissingBtComponentsAlert); return syserrromincompatible; } 3. Serial Port Profile was implemented using the Palm Virtual Serial Manager: www.cswl.com The Bluetooth system implements the serial port profile with a Virtual Serial Driver. Virtual Serial driver work with RFCOMM protocol to emulate cable-less serial connection. This driver has the following characteristics: Opens a background thread for the Bluetooth stack. Supports only one current active serial channel (point-to-point connection ) at a time. Opens the device as a client or server An RFCOMM-based virtual serial port is less symmetrical than a physical serial port. In a traditional serial port there is no need to establish the underlying transport. When establishing a Bluetooth serial port, there are roles for a client and a server device on three different stack levels ACL, L2CAP, and RFCOMM as well as responsibilities for registering with and querying SDP. 4. Scenario used The Palm hand-held acts as a Bluetooth client to the HP printer. The palm device first uses Bluetooth SDP to search for a printer in the vicinity. The printer and any other bluetooth enabled device in the vicinity responds with its address (48 bit number), which is unique for each Bluetooth device. This process of searching for Bluetooth device is called Device Discovery Process. Once the device is identified, an RFCOMM-virtual serial channel is created between the client (Palm) and server (Printer). This process creates a data channel between the client and server through which a print stream is sent. CSWL Inc, Pleasanton, California - 14
Following data streams were used: ASCII Test data PCL data stream generated from HP APDK Reference on using the HP APDK is available at http://www.cswl.com/hpapdk and http://www.cswl.com/whiteppr/tech/printing.html Source-code Basics Opening serial Port code: SrmExtOpen API is used for opening an RFCOMM-virtual serial port. Parameters for this API 1. Type of port i.e. Bluetooth RFCOMM 2. Port configuration structure 3. Size of port configuration structure 4. Port id, output param //opening virtual serial port Err err; SrmOpenConfigType config; BtVdOpenParams btparams; BtLibSdpUuidType sppuuid; // Set up a SerialPort service class UUID MemSet( &sppuuid, sizeof(sppuuid), 0 ); sppuuid.size = btlibuuidsize16; sppuuid.uuid[0] = 0x11;//corresponds to serial port sppuuid.uuid[1] = 0x01;//corresponds to serial port // // Set up a Bluetooth parameter block: play client role, use null remote device address, // // and use sdp to search for the serial port profile service class uuid. // // MemSet( &btparams, sizeof(btparams), 0 ); // note this leaves the remote dev addr null btparams.role = btvdclient; // we are the client side btparams.u.client.method = btvduseuuidlist; // use SDP to look for service class uuids btparams.u.client.u.uuidlist.tab = &sppuuid; // the list of service uuids to search for btparams.u.client.u.uuidlist.len = 1; // the number of uuids in the list // CSWL Inc, Pleasanton, California - 15
// // Set up the SrmExtOpen param block to reference our Bluetooth param block // // MemSet( &config, sizeof(config), 0 ); config.function = 0; // must be zero config.drvrdatap = (MemPtr)&btParams; // Bluetoothspecific params go here config.drvrdatasize = sizeof(btparams); // size of Bluetooth-specific params // // // Call SrmExtOpen with the parameters we just set up. // // err = SrmExtOpen ( sysfilecvirtrfcomm, // type of port == Bluetooth RfComm &config, // port configuration params sizeof(config), // size of port config params instance ); &btportid www.cswl.com // receives the id of this virtual port Sending data over serial Port code: UInt32 tosend, numsent; char msg[] = "Hello World\n";//Fill the array with PCL or //ASCII file when testing those mode. tosend = StrLen(msg); numsent = SrmSend (btportid, msg, tosend, &err); Close serial Port code: SrmClose(btPortId); Conclusion Bluetooth is a key ingredient to enabling mobile printing from low-cost low-power devices. Not only printing, the technology is relevant to a very wide range of industry segments like computing, telecom, networking, automotive, consumer electronics, medical and military. With industry leaders like Erricson, Nokia and Intel adopting and driving the technology, and the explosive growth of mobile market and the need to be Always connected, Bluetooth is becoming a very significant and crucial technology. Industry experts project that, by the year 2006, there will be a shipment of 150 million Bluetooth enabled devices from Western CSWL Inc, Pleasanton, California - 16
Europe itself. Also it is projected that by the year 2004, there will be more than 1 billion mobile subscribers using the internet in some form. Techniques described in this document can be easily adapted to printing from other mobile platforms as well, such as a PocketPC or mobile-phone. Mobile printing opens an opportunity in the software market to create sophisticated mobile printing network solutions, and this field is still in its early stages. References: 1. Plam Bluetooth support document http://www.plamos.com 2. Bluetooth specifications and profiles http://www.bluetoothsig.org 3. Bluetooth official site http://www.bluetooth.org 4. Printer Working Group http://www.pwg.org 5. Hewlett Packard http://www.hp.com 6. HP Appliance Printing Development Kit http://www.hpapdk.com 7. Palm APDK printing http://www.cswl.com/whiteppr/tech/printing.html ------------------------------------------------------------------------------------------------------------ Copyright Notice: 2002 California Software Labs. All rights Reserved. The contents on the document are not to be reproduced or duplicated in any form or kind, either in part or full, without the written permission of California Software labs. Product and company names mentioned here in are the trademarks of their respective companies. CSWL Inc, Pleasanton, California - 17