The goal of this project is to use SIP or the Session Initiation protocol to automatically forward calls to Bluetooth users based on their presence information. This project succeeded in the creation of a Bluetooth-SIP user agent which is capable of registering and publishing the availability of users who allow themselves to be discovered by the Bluetooth protocol when they are in the vicinity of a PC Basestation. The agent polls for Bluetooth devices using the HCI Inquire function of the Bluetooth protocol, generates SIP requests for mapping the device identifiers to the users' SIP AOR and generates SIP messages for registration and conveying user presence for each associated user discovered.
The main component of the application is a Bluetooth-SIP agent which maintains a list of devices that are discoverable by the agent. When a user with a headset needs to register himself with basestation running the agent as his contact, he enters into pairing mode with the basestation. The Bluetooth-SIP agent discovers that the list of discoverable devices has changed and issues a SIP request to retreive the mapping of the undiscovered device. When this request is answered by a mapping server with the user's SIP AOR, the user agent registers the user with SIPD and publishes the user's availability to a presence server. When the user leaves the pairing mode, the change in status is published to the presence server.
The Bluetooth/SIP agent makes use of the Bluez implementation of the Bluetooth stack on Linux. The HCI (Host controller interface) layer of Bluetooth provides a interface to communicate, access and control the hardware layer. L2CAP provides connection-oriented and connectionless services to upper layers. The BNEP layer lies on top of the L2CAP layer and provides support for IP.
The basic data structure used to specify a Bluetooth device address is the bdaddr_t. All Bluetooth addresses in BlueZ are stored and manipulated as bdaddr_t structures. Local Bluetooth adapters are assigned identifying numbers starting with 0, and a program must specify which adapter to use when allocating system resources. hci_get_route will retrieve the resource number of the first available Bluetooth adapter. After choosing the local Bluetooth adapter to use and allocating system resources, the program can scan for nearby Bluetooth devices. hci_inquiry performs a Bluetooth device discovery and returns a list of detected devices and some basic information about them in a inquiry_info structure. The timeperiod of the inquiry and the maximum number of responders can be varied.
A key component of the user agent is a BTManageAgent (BTM) object which handles bluetooth related functions. On startup of the useragent the handle_bluetooth function is called which creates the BTM object. The BTM object maintains a list of device identifiers which it updates after every polling period as it discovers new devices.
Base-station Presence Server | SIPD |
------- Mapping server |______| |______|
>>>>>>>> | | MAP | | |______| ^
>>>>>>>> | |----------------> | ^ |
>>>>>>>> | | |<---------------|_| | |
DISCOVER |--|--|------------------------REGISTER-------------
| |
|______PUBLISH________________|
On the discovery of a new device a devices added handler which sends a PUBLISH request to the mapping server. The From and To fields in the header of this message contain the device address in sip format. (e.g. sip:00-0A-3A-06-CA-78@cs.columbia.edu). The mapping server then responds with the AOR mapped to the bluetooth address received and sends a SIP 302 response with the AOR contained in the Contact Header. On successful mapping the Bluetooth-SIP agent calls the mapping successful handler, which sends a PUBLISH message to the presence server to update the presence status of the person with the basestation as his contact, and a pidf content showing him to be in pairing mode. The agent also generates a REGISTER message to SIPD with the basestation as his contact in the Contact header.
1. bluetooth.cpp - Maintains list of discovered devices. Tracks devices entering or leaving pairing mode. Sets HCI Inquiry parameters.
2. main.cpp - Starts the bluetooth handler. Queries the mapping server for new devices. Maintains hash of mapped devices. Contains the mapping response handler and mapping succesul handler and publish and register request handling functions.
Example Usage and Output:
[root@lirr sipua]# ./sipua -d net -M sip:delhi.clic.cs.columbia.edu -R sip:copenhagen.clic.cs.columbia.edu -P sip:delhi.clic.cs.columbia.edu
SIP-Bluetooth Gateway 1.24, (c) 2005, Columbia University
Visit http://www.cs.columbia.edu/IRT/cinema for more info
read params
2005-12-21 08:02:52.806: thread 3086337728: InitSocketListener: Started socket listener, thread = 2740169648
SIP Endpoint listening at 0.0.0.0:9000 [::]:9000
2005-12-21 08:02:52.810: thread 2740169648: setup_fds: Set up pollfd list, nfds=1
device detected is 00-20-E0-79-8A-54
device id created to be stored is sip:00-20-E0-79-8A-54@cs.columbia.edu
2005-12-21 08:03:03.167: thread 3075845040: ClientGetLocations: calling servers("delhi.clic.cs.columbia.edu", "sip", 2, -5060)
2005-12-21 08:03:03.169: thread 3075845040: CreateClientSocket: [128.59.15.41/5060] Trying to open UDP connection
2005-12-21 08:03:03.169: thread 3075845040: CreateClientSocket: Returning socket 10
2005-12-21 08:03:03.169: thread 3075845040: SendRequest: Proxying request to socket 10:
PUBLISH sip:00-20-E0-79-8A-54@cs.columbia.edu SIP/2.0
Via: SIP/2.0/UDP lirr.win.cs.columbia.edu:9000;branch=z9hG4bKfFKpQ3spDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_
From: ;tag=2698450696
To:
CSeq: 1 PUBLISH
Call-ID: 3408827001@lirr.win.cs.columbia.edu
Contact:
Content-Length: 0
Event: lookup
Expires: 3600
2005-12-21 08:03:03.173: thread 2719189936: ReceiveUDP: [128.59.15.41/33942] Got packet (457) bytes
SIP/2.0 302 Mapping Present
Via: SIP/2.0/UDP lirr.win.cs.columbia.edu:9000;branch=z9hG4bKfFKpQ3spDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_
From: ;tag=2698450696
To: ; tag=1635199944
Call-ID: 3408827001@lirr.win.cs.columbia.edu
CSeq: 1 PUBLISH
Date: Wed, 21 Dec 2005 13:03:55 GMT
Server: SIPUA-Columbia-University/1.24
Contact: sip:vs2140@cs.columbia.edu
Content-Length: 0
OnFailure Response Called
Response 302Mapping Present
from address is
New contact is sip:vs2140@cs.columbia.edu
2005-12-21 08:03:03.179: thread 3012905904: ClientGetLocations: calling servers("delhi.clic.cs.columbia.edu", "sip", 2, -5060)
2005-12-21 08:03:03.182: thread 3054865328: ClientGetLocations: calling servers("copenhagen.clic.cs.columbia.edu", "sip", 2, -5060)
2005-12-21 08:03:03.183: thread 3012905904: CreateClientSocket: [128.59.15.41/5060] Trying to open UDP connection
2005-12-21 08:03:03.183: thread 3012905904: CreateClientSocket: Returning socket 11
2005-12-21 08:03:03.183: thread 3012905904: SendRequest: Proxying request to socket 11:
PUBLISH sip:vs2140@cs.columbia.edu SIP/2.0
Via: SIP/2.0/UDP lirr.win.cs.columbia.edu:9000;branch=z9hG4bKfFKpQ3spDAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_
From: ;tag=2698450696
To:
CSeq: 1 PUBLISH
Call-ID: 3249474863@lirr.win.cs.columbia.edu
Contact:
Content-Length: 281
Content-Type: application/pidf+xml
Event: presence
Expires: 3600
pairing
2005-12-21 08:03:03.186: thread 3054865328: CreateClientSocket: [128.59.15.45/5060] Trying to open UDP connection
2005-12-21 08:03:03.186: thread 3054865328: CreateClientSocket: Returning socket 12
2005-12-21 08:03:03.187: thread 3054865328: SendRequest: Proxying request to socket 12:
REGISTER sip:cs.columbia.edu SIP/2.0
Via: SIP/2.0/UDP lirr.win.cs.columbia.edu:9000;branch=z9hG4bKfFKpQ3spDAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_
From: ;tag=2698450696
To:
CSeq: 1 REGISTER
Call-ID: 2987549641@lirr.win.cs.columbia.edu
Expires: 3600
Contact:
Content-Length: 0
2005-12-21 08:03:03.187: thread 2719189936: ReceiveUDP: [128.59.15.41/33942] Got packet (385) bytes
SIP/2.0 200 OK
Via: SIP/2.0/UDP lirr.win.cs.columbia.edu:9000;branch=z9hG4bKfFKpQ3spDAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_
From: ;tag=2698450696
To: ; tag=1635199944
Call-ID: 3249474863@lirr.win.cs.columbia.edu
CSeq: 1 PUBLISH
Date: Wed, 21 Dec 2005 13:03:56 GMT
Server: SIPUA-Columbia-University/1.24
Content-Length: 0
2005-12-21 08:03:03.189: thread 2719189936: ReceiveUDP: [128.59.15.45/5060] Got packet (496) bytes
SIP/2.0 200 OK
Via: SIP/2.0/UDP lirr.win.cs.columbia.edu:9000;branch=z9hG4bKfFKpQ3spDAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA_
From: ;tag=2698450696
To: ; tag=gE1zj1LDApW.FJT1KYumkw
Call-ID: 2987549641@lirr.win.cs.columbia.edu
Cseq: 1 REGISTER
Date: Wed, 21 Dec 2005 13:03:55 GMT
Server: Columbia-SIP-Server/1.24
Content-Length: 0
Contact: ; expires=3600; action=proxy; q=1.00
Expires: 3600
I would like to thank Kundan Singh for taking the time to help me out on debugging my many SIPUA problems.
I would like to thank Vishal Singh for helping me understand SIP presence message flow.