May 1998
Windows CE 2.0 Networking Offers Exciting Mobile Computing Possibilities |
Microsofts new Windows® CE operating system is designed for small form factor devices. An appealing feature of these devices is their robust networking capability. They support many types of communications hardware, including serial links, modems, and Ethernet cards. |
This article assumes youre familiar with C++ and Network Programming |
Anthony Jones is an engineer at Microsoft in the Developer Support Networking Unit. He is an avid skier who is perfecting the technique of sliding down the mountain on his back.
|
Imagine you're on your way
to the airport for an important business trip when you realize you left the heat on at your house. You pull your Handheld PC out of your briefcase and dial up your ISP through your cellular phone. You then bring up a Home Management app that shows the temperature in your house, the thermostat setting, what lights are on, and the mode of the security system, among other things. You turn the thermostat to the off position and the problem is solved. Sound like science fiction? Well, it's closer than you think!
Microsoft's new Windows® CE operating system is designed for small form factor devices, including Handheld PCs, automobile computers, and many other embedded applications. Just recently, Microsoft and TCI announced a deal to use Windows CE in set top cable boxes. Microsoft has also unveiled plans for the Auto PC, a small computer running Windows CE for use in automobiles. Several manufacturers have already released plans to produce these devices with navigation features that include a GPS (Global Positioning System) tracking device and wireless communications. Of course, most people have heard of those tiny Handheld PCs running the Windows CE operating system. These little devices are amazing in their own right. Handheld PCs come with versions of Microsoft Excel and Word, and their ability to synchronize with your desktop PC via serial or infrared connections makes them the perfect personal organizers. Another appealing feature of these devices is their robust networking capability. They support many types of communications hardware, including serial links, modems, and Ethernet cards. They also support almost all of Microsoft's networking APIs! Windows CE is taking off like wildfire, in large part due to its strong networking features. In this article I will give a detailed overview of the networking capabilities under Windows CE 2.0. I will emphasize the Winsock support and networking features such as infrared socket support (IrSock) because these capabilities open up exciting new possibilities in the world of mobile computing. One important thing to note is that the communications support in Windows CE is an operating system specification and not a requirement for the hardware on which it runs. Handheld PC manufacturers receive the operating system as a set of components, some of which are tagged as optional. The manufacturer can choose which optional features will be supported. When manufacturers leave out a component, it's usually to save space for their own unique features. In the discussion that follows, I will note those APIs that I know are not implemented on Handheld PCs.
Communication Support
Serial Communication
Telephony
Networking Communications
|
Figure 1 API and Protocol Stack |
Winsock Support
Handheld PCs on the Network
Writing Winsock Applications
Blocking Sockets
Nonblocking Sockets
|
|
You'll notice that there are three fd_set parameters, one for checking readability, one for writeability, and one for out-of-band data, respectively. An fd_set is a collection of sockets. Winsock declares several macros for adding, deleting, and clearing these sets. For example, Figure 6 illustrates how to check whether socket s has any incoming data pending.
A single call to select may also include the other fd_set variables, and each fd_set may contain multiple sockets. To keep things simple, it is probably best to call select with only one type of fd_set at a time because select merely returns the number of sockets that meet the given conditions. For example, if a read and a write fd_set were used with each set containing three sockets, and select returned four, all this means is that four sockets are available for reading or writing. It is up to the programmer to figure out which sockets correspond to which event. Each type of socket, blocking and nonblocking, has advantages and disadvantages. Blocking sockets are easier from a conceptual standpoint, but become difficult to use when dealing with multiple connected sockets or when data is sent and received in varying amounts and times. Nonblocking sockets require more code to handle the possibility of receiving a WSAEWOULDBLOCK error on every Winsock call, but the select function offers the ability to manage multiple connected sockets in an organized manner.
Socket Options
Infrared Sockets
|
|
The irdaAddressFamily field is always set to AF_IRDA. The irdaDeviceID field is a four-character string that identifies the device on which a particular service is running. This field is ignored when creating an IrSock server, but it is significant for a client because it specifies the specific IrDA device to connect to. Finally, the irdaServiceName field is the name of the service that the application will either register itself as or is looking for.
IrSock Name Resolution
IrSock Server
|
|
The field of interest in a DEVICELIST is Device, which is an IRDA_DEVICE_INFO structure. Within that structure is an irdaDeviceID that corresponds to the field of the same name in the SOCKADDR_IRDA structure. Any IrSock-capable device will have a device ID associated with it, so a successful query will return one or more IRDA_DEVICE_
INFO structures containing the device ID of each device discovered. If no IrSock-capable devices are detected, the query will return with the numDevice field set to zero. Once a list of these device IDs are returned, a client can either attempt to connect to each server or begin to query the server for services it is running. To connect to the server, the client fills out a SOCKADDR_IRDA with the device ID of the device in question and the service name of the IrSock server to which it wants to connect.
You may have noticed that when searching for available IrSock devices, a device ID and friendly name are returned. A client is required to know both the device ID of the server and the name of the IrSock service for which it is looking. Future releases may add additional "hint" information to the structure returned by an IRLMP_ENUMDEVICES call. This information will better associate a particular server with a found IrDA device. To find the correct server, it is necessary to attempt a connection to each device returned, specifying the service name for which you are looking. Figure 9 illustrates a simple IrSock client, irclient.c, that first searches for IrSock devices in the area, and then attempts to connect to each one in search of a particular server. Also included is code for a simple IrSock server to which this client could connect.
IrSock Socket Options
|
|
An entry within the IAS_QUERY consists of the device ID, class name, and attribute name. The attribute value associated with the name can be an integer, a binary sequence, or a string, which is the reason for the union within the structure. To perform a query, fill in a valid device ID (returned from an IRLMP_ENUMDEVICES), class name, and attribute name. The value returned will be the attribute associated with that particular class and attribute on the given device. For the most part, developers will use connect, which will properly handle the query for the LSAP-SEL on which a service is running. In this case, the device ID would be the device to query, the class name would be the name associated with the service in question, and the attribute would be IrDA:TinyTP:LsapSel.
Another option of some interest is IRLMP_IAS_SET, which is used to change the attribute associated with a particular class name. This option requires passing an IAS_SET structure into setsockopt. The structure is exactly like the IAS_QUERY structure minus the irdaDeviceID field. It is doubtful that one would actually need to change the attributes associated with an IAS entry. The rest of the IrSock options are unlikely to be used, but here are short descriptions of each to satisfy everyone's curiosity. IRLMP_9WIRE_MODE is designed to talk to the Windows 95 IrComm. In this mode, the IrLMP packet contains an additional one-byte IrComm header. Related to this option is IRLMP_SEND_PDU_LEN, which transmits the maximum PDU size of an IrLMP packet to the other side. This is used to determine whether IRLMP_9WIRE_ MODE should be set. IRLMP_EXCLUSIVE_MODE puts the IrLMP layer into exclusive mode, which means only one LSAP-SEL will be active and communicating. For further information about these options, consult the IrDA specifications found at http://www.irda.org.
Secure Socket Layer Support
TCP/IP Registry Options
Conclusion
From the May 1998 issue of Microsoft Systems Journal.
|