Home networking has become popular in USA. The most popular home networking protocol is x10 [1], which has a lot of products in the market today. Also there is a big demand for controlling home appliances from internet.
In addition to that Session Initiation Protocol(SIP)[2] for setting up, controlling sessions has become popular in the field of internet telephone calls and electric appliances. With its feature of signaling message, it is suitable for controlling devices from remote environment.
The goal of this project is to monitor and control X10 lights and appliances remotely using SIP. After adding support for SUBSCRIBE and NOTITY in the device gateway, the gateway can periodically poll the status of the X10 device or get messages from the X10 device. The gateway issue NOTIFY request to the subscriber if the status of the X10 device is changed. In the client side, the SIP clients can also send subscription and notification to other clients when they go online or go offline.
In the SIP client and server system, clients send SIP messages to servers and get response from servers. SIP messages has header information, which includes tags for controlling method, client properties and the body, which include the state information to subscribe to a device gateway.
To subscribe the states of a device with SIP message, "SUBSCRIBE" method is used. , which was proposed in the draft of the ietf group.
In this project, I have implemented the following features in SIP clients, which are developed and tested on sun Solaris machine.
Required OS: Solaris, Linux Required Software: sipua,libsip++,x10 API Required Hardware: x10 Adapter(CM11A,LM465,RR501)
stateparser.tcl parser for the configuration XML file subparser.tcl parser for the subscription XML file gui_subscribe.tcl GUI for sending subscription gui_device.tcl GUI for device control gui_notify.tcl GUI for notification controller_subscribe.tcl handler for sending and handling SUBSCRIBE request and response controller_notify.tcl handler for sending and handling NOTIFY request and response Other files configuraton files in directory XMLFile/
- Column 1: "Subscriber", indicate whether the client in this entry subscribe for our status - Column 2: "State", show the current status of the user/device if we send the subscription for such states.
SUBSCRIBE GUI is a interface for the subscription, which contain: - The sipurl to send the subscription - The events to subscribe at this sipurl - The expiration for this subscription
Definition of related function:
Function name: proc Gui_Subscribe::main{} Description: Function for invoking SUBSCRIBE GUI from main menu Function name: proc Gui_Subscribe::init {} Description: Initialize the parameters for a new subscribe Function name: proc Gui_Subscribe::new {sipURL l_event package} Description: Manage the GUI for a new subscription Parameter: sipURL The sipurl to send the subscription l_event The events to subscribe package The package for the subscription Function name: proc Gui_Subscribe::create {sipURL l_event package} Description: Create the GUI for a new subscription Parameter: sipURL The sipurl to send the subscription l_event The events to subscribe package The package for the subscription Function name: proc Gui_Subscribe::updateExpire {s} Description: When expire scale changed, sync the the display of time Function name: proc Gui_Subscribe::subscribe {flag} Description: Call Controller_subscribe{} to handle the subscribe flag 1 -- indicates subscribe 0 -- indicates unsubscribe Function name: proc Gui_Subscribe::display {sipurl message icon} Description: Create interface for displaying subscribe message Parameter: sipurl The sipurl of the response message detail information for this error icon icon for this type of error
Controller_Subscribe is the API for handling SUBSCRIBE, which support: - Sending SUBSCRIBE request - Handling SUBSCRIBE response - Handling SUBSCRIBE request - Sending SUBSCRIBE response
Definition of related function:
Function name: proc Controller::subscribe {sipurl expire l_event package l_authen} Description: Function for composing and sending SUBSCRIBE request Parameter: sipurl The sipurl to send this subscription expire Expiration for this subscription l_event Events to subscribe package The package for the subscription l_authen The username and password for the subscription Function name: proc Controller::subscribeAuthen{call_id} Description: Create the interface for the authentication for subscription call_id The call_ID for the unauthorized subscription Function name: proc Controller::subAuthenOk{call_id} Description: Collect userName and password before send subscribe with authentication info Parameter: call_id Call-ID for the subscription which need authentication Function name: proc Controller::subAuthenClear{call_id} Description: Clear the userName and password field in the authentication window Function name: proc Controller::getAuthenInfo{sipurl} Description: Retrieve the saved username and password from subscribe.xml Parameter: sipurl sipurl for the subscribe record Function name: proc Controller::subscribeHandle {l_argu} Description: Handle SUBSCRIBE request Parameter: l_argu The argument list of the SUBSCRIBE request Function name: proc Controller::subscribeResponse {call_id cseq code reason l_nheader content} Description: Send response after receiving SUBSCRIBE request Parameter: sipurl The sipurl of the response call_id The call_id for this SUBSCRIBE response cseq CSeq for this response code Code for this response reason Reason for this response l_nheader Message Header for this response content Content for this response Function name: proc Controller::subscribeResponseHandle {l_argu} Description: Handle the response for SUBSCRIBE Parameter: l_argu The argument list of the SUBSCRIBE response Function name: proc Controller::onlineQueryAll {} Description: Send the query to update the subscription for all users/devices which doesn't expire in the subscribe list Function name: proc Controller::updateSubscribeXML {subURL contact call_id cseq package expire l_event username userpass} Description: Update the subscribe records in the subscribe.xml Parameter: subURL The sipurl of the record to update in subscribe.xml contact The contact information for the subscription call_id The call-ID for this record cseq Call sequence number package Package for this subscription expire The expiration for this record l_event Events information for this record username The user name for this record userpass The user password for this record Function name: proc Controller::writeSubscribeBook {SubscribeBook} Description: Write the record to the file subscribe.xml Function name: proc Controller::updateWatchXML {requrl presentity package call_id cseq contact expire} Description: Update the records in the watch.xml Parameter: requrl The sipurl of the user who subscribe for our status call_id The call-ID for the SUBSCRIBE request cseq Call sequence number contact Contact info for the SUBSCRIBE request expire The expiration of the SUBSCRIBE request Function name: proc Controller::writeRequestBook {RequestBook} Description: Write the record to the file watch.xml Function name: proc Controller::initBook {book} Description: Initialize the file for "subscribe.xml" or "watch.xml"NOTIFY API
Controller_Notify is the API for handling Notify, which support: - Sending NOTIFY request - Handling NOTIFY response - Handling NOTIFY request - Sending NOTIFY response
Definition of related function:
Function name: proc Controller::notify {requrl event} Description: Compose and send NOTIFY request Parameter: requrl The sipurl to send notification event The event to notify the receive Function name: proc Controller::notifyHandle {l_argu} Description: Handle NOTIFY request Parameter: l_argu The argument list of the NOTIFY request Function name: proc Controller::notifyResponse {call_id cseq code reason l_nheader content} Description: Send response after receiving Notify request Parameter: sipurl The sipurl of the response call_id The call_id for this NOTIFY response cseq CSeq for this response code Code for this response reason Reason for this response l_nheader Message Header for this response content Content for this response Function name: proc Controller::notifyResponseHandle {l_argu} Description: Handle the response for NOTIFY Parameter: l_argu The argument list of the NOTIFY response Function name: proc Controller::onlineNotifyAll {} Description: Send the notification to all the users who is watching us after we returning to online event Function name: proc Controller::offlineNotifyAll {} Description: Send the notification to all the users who is watching us before we go to offline event Function name: proc Controller::getNotifyList {} Description: Get the list of users that we should send notification before offline or after go online
This operation is done in Solaris(muni) % make -f makefile.unix exe % sipc
user.xml config file for the events that a user support in SUBSCRIBE x10.xml config file for the events that a lamp support in SUBSCRIBE x10.conf config file for the device control commands that a lamp support subscribe.xml xml file for storing the subscription to other user/device watch.xml xml file for storing the user information who subscribe for our status
The message format for subscribe are as follows. In these example, client is from dynasty.cs.columbia.edu and server is muni.cs.columbia.edu. -------------------------------------------------------------------------- Subscribe Request from client to server (Subscribe on/off/dim/bright event) -------------------------------------------------------------------------- 05/09/2001 18:45:01.165871 Sent to: muni.cs.columbia.edu:5090 SUBSCRIBE sip:lamp@muni.cs.columbia.edu:5090 SIP/2.0 Via: SIP/2.0/UDP 128.59.16.9:5060 CSeq: 1 SUBSCRIBE Contact: sip:hz80@128.59.16.9:5060 Expires: 3600 From: sip:hz80@diamond.cs.columbia.edu Date: Wed, 09 May 2001 22:45:01 GMT Call-ID: 994419756@128.59.16.9 Content-Type: application/xml Event: x10 To: sip:lamp@muni.cs.columbia.edu:5090 Content-Length: 160 <?xml version="1.0"?> <subscription expire="3600"> <event event="on"/> <event event="off"/> <event event="dim"/> <event event="bright"/> </subscription> -------------------------------------------------------------------------- -------------------------------------------------------------------------- Authorization needed -- User need to provide authentication information -------------------------------------------------------------------------- 05/09/2001 18:47:29.416447 Recv from: 128.59.19.192:37159 SIP/2.0 401 Unauthorized Via: SIP/2.0/UDP 128.59.16.9:5060 From: sip:hz80@diamond.cs.columbia.edu To: sip:lamp@muni.cs.columbia.edu:5090 Call-ID: 994419757@128.59.16.9 Cseq: 1 SUBSCRIBE Date: Wed, 09 May 2001 22:47:29 GMT Server: SIPUA-Columbia-University/1.0 Content-Length: 0 WWW-Authenticate: Basic realm="cs.columbia.edu" -------------------------------------------------------------------------- -------------------------------------------------------------------------- Subscribe Response from server to client after authentication: (Subscribe for on/off/dim/bright events) -------------------------------------------------------------------------- 05/09/2001 18:47:45.310652 Recv from: 128.59.19.192:37159 SIP/2.0 200 Update Former Subscription Via: SIP/2.0/UDP 128.59.16.9:5060 From: sip:hz80@diamond.cs.columbia.edu To: sip:lamp@muni.cs.columbia.edu:5090 Call-ID: 994419758@128.59.16.9 Cseq: 1 SUBSCRIBE Date: Wed, 09 May 2001 22:47:45 GMT Server: SIPUA-Columbia-University/1.0 Content-Length: 63 Content-Type: application/xml <?xml version="1.0"?> <events> <event>off</event/> </events> -------------------------------------------------------------------------- -------------------------------------------------------------------------- Notify Request from server(muni.cs.columbia.edu) to client (Subscribe for on/off events) -------------------------------------------------------------------------- 5/09/2001 18:57:18.732172 Recv from: 128.59.19.192:37159 NOTIFY sip:lamp@muni.cs.columbia.edu SIP/2.0 Via: SIP/2.0/UDP 128.59.16.9:5060 CSeq: 2 NOTIFY Contact: sip:lamp@128.59.19.192:5090 From: sip:lamp@muni.cs.columbia.edu:5090 Date: Wed, 09 May 2001 22:57:18 GMT Content-Type: application/xml Call-ID: 438155611@128.59.16.5 To: sip:hz80@diamond.cs.columbia.edu Content-Length: 69 <?xml version="1.0"?> <events> <event>on</event/> </events> -------------------------------------------------------------------------- -------------------------------------------------------------------------- Subscribe Request from client(dynasty.cs.columbia.edu) to client(diamond.cs.columbia.edu) -------------------------------------------------------------------------- 05/09/2001 18:57:16.440096 Sent to: diamond.cs.columbia.edu:5060 SUBSCRIBE sip:hz80@diamond.cs.columbia.edu SIP/2.0 Via: SIP/2.0/UDP 128.59.16.5:5060 CSeq: 1 SUBSCRIBE Contact: sip:hz80@128.59.16.5:5060 Expires: 3600 From: sip:hz80@dynasty.cs.columbia.edu Date: Wed, 09 May 2001 22:57:16 GMT Call-ID: 483156511@128.59.16.5 Content-Type: application/xml Event: presence To: sip:hz80@diamond.cs.columbia.edu Content-Length: 144 <?xml version="1.0"?> <subscription expire="3600"> <event event="online"/> <event event="offline"/> <event event="idle"/> </subscription> -------------------------------------------------------------------------- -------------------------------------------------------------------------- Subscribe Response from client(diamond.cs.columbia.edu) to client(dynasty.cs.columbia.edu) -------------------------------------------------------------------------- 5/09/2001 18:57:18.369220 Recv from: 128.59.16.9:5060 SIP/2.0 202 Accepted CSeq: 1 SUBSCRIBE Contact: sip:hz80@128.59.16.9:5060 Via: SIP/2.0/UDP 128.59.16.5:5060 From: sip:hz80@dynasty.cs.columbia.edu Call-ID: 483156511@128.59.16.5 To: sip:hz80@diamond.cs.columbia.edu; tag=49380864971.128.59.16.9 Content-Length: 69 <?xml version="1.0"?> <events> <event>online</event> </events> -------------------------------------------------------------------------- -------------------------------------------------------------------------- Notify request from client(diamond.cs.columbia.edu) to client(dynasty.cs.columbia.edu) -------------------------------------------------------------------------- 5/09/2001 18:57:18.732172 Recv from: 128.59.16.9:5060 NOTIFY sip:hz80@dynasty.cs.columbia.edu SIP/2.0 Via: SIP/2.0/UDP 128.59.16.9:5060 CSeq: 2 NOTIFY Contact: sip:hz80@128.59.16.9:5060 From: sip:hz80@diamond.cs.columbia.edu Date: Wed, 09 May 2001 22:57:18 GMT Content-Type: application/xml Call-ID: 483156511@128.59.16.5 Event: presence To: sip:hz80@dynasty.cs.columbia.edu Content-Length: 69 <?xml version="1.0"?> <events> <event>online</event> </events> -------------------------------------------------------------------------- -------------------------------------------------------------------------- Sample Subscribe Records in "subscribe.xml" (diamond.cs.columbia.edu) -------------------------------------------------------------------------- <?xml version="1.0"?> <subscriptions> <subscription> <sipurl>sip:lamp@muni.cs.columbia.edu:5090</sipurl> <presentity>sip:lamp@muni.cs.columbia.edu:5090</presentity> <package>x10</package> <call_id>994419758@128.59.16.9</call_id> <cseq>{1 SUBSCRIBE}</cseq> <contact>sip:lamp@muni.cs.columbia.edu:5090</contact> <username>hz80@cs.columbia.edu</username> <userpass>123</userpass> <expire>989452065</expire> <event>on</event> <event>off</event> <event>dim</event> <event>bright</event> </subscription> <subscription> <sipurl>sip:hz80@diamond.cs.columbia.edu</sipurl> <presentity>sip:hz80@diamond.cs.columbia.edu</presentity> <package>presence</package> <call_id>483156511@128.59.16.5</call_id> <cseq>{1 SUBSCRIBE}</cseq> <contact>sip:hz80@diamond.cs.columbia.edu</contact> <username></username> <userpass></userpass> <expire>989452638</expire> <event>online</event> <event>offline</event> <event>idle</event> </subscription> </subscriptions> -------------------------------------------------------------------------- -------------------------------------------------------------------------- Sample Subscribe Records in "watch.xml" (diamond.cs.columbia.edu) -------------------------------------------------------------------------- <?xml version="1.0"?> <subscriptions> <subscription> <sipurl>sip:lamp@muni.cs.columbia.edu:5090</sipurl> <presentity>sip:lamp@muni.cs.columbia.edu:5090</presentity> <package>x10</package> <call_id>994419758@128.59.16.9</call_id> <cseq>{1 SUBSCRIBE}</cseq> <contact>sip:lamp@muni.cs.columbia.edu:5090</contact> <username>hz80@cs.columbia.edu</username> <userpass>123</userpass> <expire>989452065</expire> <event>on</event> <event>off</event> <event>dim</event> <event>bright</event> </subscription> </subscriptions> --------------------------------------------------------------------------
The error code for the SUBSCRIBE response is as follows: - Code 400 "Error XML Content" - Code 404 "Device Not Found" - Code 500 "Events Not Found" - Code 501 "Not implemented"
Thank you for continuous advise from Prof. Schulzrinne and PhD Xiaotao Wu.
Huwei Zhang: Implementing the subscription and notification in the SIP user agent.
Last updated: 05/09/2001
By Huwei Zhang