Presentation - Technion

clappingknaveΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

77 εμφανίσεις

Universal Plug and Play
(UPnP)

Presented by:




Kamal Kamal


Mohammad Atieh


Contents


Introduction


UPnP Protocol


Development Levels


Control Point: Data structures and
Modules


Control Point User Interface



Introduction to UPnP


The UPnP is a technology that provides a peer
-
to
-
peer
connectivity of intelligent appliance, wireless devices,
and PCs of all factors, and creates a distributed
network such that each device that is connected to the
network offers its services to all the other connected
devices.



In this project a UPnP on mobile phone is
implemented, such that the devices of the distributed
network are mobile phones of Qualcomm (Brew), So
the project is part of the development of the Brew
mobile phone.

Introduction (Cont.)


The nodes of the created network are classified
into two parts: Devices that offer the services, and
a Control Point that uses these services.


Two teams are working on this project: our team
has to implement the Control Point, the other
should implement the Device.


The implementation will be tested by a Brew
simulator.


UPnP Steps


Discovery


advertisements by the devices


search requests from the control points


Description


Requested information about the device is sent to control point


Control


requests for actions from the control points to the devices


Eventing


subscription for events by the control points


notification of events by the device


Presentation (control point)


GUI to the user by the control point

UPnP Protocol Stack


The UPnP discovery protocol is based on the Simple Service Discovery
Protocol (SSDP).



Control messages are expressed in XML using the Simple Object
Access Protocol (SOAP).



Event messages are also expressed in XML and formatted using the
General Event Notification Architecture (GENA).


SSDP works over UDP, SOAP and GENA works over TCP.




Control Point side of the UPnP Subsystem



Network

Discovery

Search

Discovery

Response

Discovery

Description

Request

Description

Description

Response

Control

Request

Control

Control

Response

Eventing


Event


subscription

Events


notification

Presentation

Control point user

Discovery


The control point sends msearch:




M
-
SEARCH * HTTP/1.1

HOST:

239.255.255.250:1900

MAN:

"ssdp:discover"

MX:

seconds to delay response

ST:

ssdp:all




Discovery Cont.


The device responds with:




HTTP/1.1 200 OK


CACHE
-
CONTROL:

max
-
age = seconds until advertisement expires


DATE:

when response was generated

LOCATION:

URL for UPnP description for device

SERVER:

OS/version UPnP/1.0 product/version

ST:

device type : device version


USN:

device UUID :: device type : device version


Description


Device Description


defines logical devices


contains URLs for service description, control,
eventing.


Service Description


tells how to form a request for a service


events that can be subscribed to by control points


fetched using HTTP GET

XML in UPnP: Device Description

<xml version="1.0"?>

<root xmlns="urn:schemas
-
upnp
-
org:device
-
1
-
0">


<
specVersion
> <
major
>
1</major
> <
minor
>
0</minor
>
</specVersion
>


<
device
>


<
serviceList
>


<
service
>


<
serviceType
>
urn:schemas
-
upnp
-
org:service:
serviceType:v
</serviceType
>


<
serviceId>urn:upnp
-
org:serviceId:
serviceID
</serviceId
>


<
SCPDURL
>URL to service description
</SCPDURL
>


<
controlURL
> URL for control
</controlURL
>


<
eventSubURL
> URL for eventing
</eventSubURL
>


</service
>


Declarations for other services defined by a UPnP Forum (if any) go here


Declarations for other services added by UPnP vendor (if any) go here


</serviceList
>


<deviceList
>


Description of embedded devices defined by a UPnP Forum (if any) go here


Description of embedded devices added by UPnP vendor (if any) go here


</deviceList
>


<
presentationURL
>URL for presentation
</presentationURL
>


</device
>

</root
>

XML in UPnP: Service Description

<
scpd

xmlns="urn:schemas
-
upnp
-
org:service
-
1
-
0"
>

<
actionList
>


<
action
> <
name
>
actionName
</name
>


<
argumentList
>


<
argument
>


<
name
>
formalParameterName
</name
>


<
direction
> in or out
</direction
>


<
relatedStateVariable
>
stateVariableName
</
relatedStateVariable
>


</argument
>


</argumentList
>


</action
>

</actionList
>

<
serviceStateTable
>


<
stateVariable

sendEvents="yes">


<
name
>
variableName
</name
>


<
dataType
>
variable data type
</dataType
>


<
defaultValue
>
default value
</defaultValue
>


<
allowedValueList
>


<
allowedValue
>
enumerated value
</allowedValue
>


</allowedValueList
>


</stateVariable
>


</serviceStateTable
>

</scpd
>

Control


Uses Simple Object Access Protocol (SOAP)


Control points


fetch the URL for control


construct requests using SOAP


send the requests over HTTP


wait for the SOAP responses from devices


Devices


parse the SOAP requests


carry out the required action and return responses
in SOAP messages

XML in UPnP: SOAP


Uses XML and HTTP for control calls


SOAP request


POST
path

of

control

URL

HTTP/1.1

HOST:
host

of

co
n
trol
URL
:
port

of
control

URL

CONTENT
-
LENGTH:
bytes

in

body

CONTENT
-
TYPE: text/xml; charset="utf
-
8"

SOAPACTION: "urn:schemas
-
upnp
-
org:service:
serviceType:v#actionName



<s:Envelope xmlns: s=“http://schemas.xmlsoap.org/soap/envelope”


s:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding”>

<s:Body>


<
u:
actionName

xmlns:u="urn:schemas
-
upnp
-
org:service:
serviceType:v
">


<
argumentName
>
in arg value
</
argumentName
>


other

in

args

and

their

values

go

here
,
if

any


</u:
actionName
>

</s:Body>

</s:Envelope>

Eventing


Device publishes a list of events for which
control points can subscribe and get
notifications


Control points subscribe with the devices for
the events published


Event notifications by the devices over TCP to
control points

XML in UPnP: Event
Notification

NOTIFY
delivery

path

HTTP/1.1

HOST:
delivery

host
:
delivery

port

CONTENT
-
TYPE: text/xml

CONTENT
-
LENGTH:
Bytes

in
body

NT: upnp:event

NTS: upnp:propchange

SID: uuid:
subscription
-
UUID

SEQ:
event

key


<e:propertyset xmlns:e="urn:schemas
-
upnp
-
org:event
-
1
-
0">


<
e:property
>


<
variableName
>
new

value
</variableName>


</
e:property
>


Other variable names and values (if any) go here
.

</e:propertyset
>


Development Levels

Project Steps


Reading and understanding the UPnP.


Installation of the BREW SDK v.3.1.3.


Reading relevant information from the BREW API
reference ,and making the necessary steps in order to
develop on the BREW SDK.


Writing a first simple program on the simulator, and
running it.


Building the infrastructure of the connection between
two devices , by sockets, and understanding how
connection works.


Project Steps (Cont.)


Implementation of each protocol step: the implementation
is based on sending special messages to the device
according to the protocol of each step via a socket which
listens on a selected port, then receiving messages from
the device ,via the same socket, parsing the message,
getting needed information from it, and updating the
control point data structure according to this information.


The last step is building a GUI, which offers a friendly
interface to make the protocol usage easy and funny!!

Special Challenges and Solutions


Multicasting:

the protocol is based on sending http
multicast messages at the discovery step, however we
don’t have the ability to do such a thing , since the
BREW SDK doesn’t support multicasting .


Synchronization

problems such like listening to
many sockets at the same time, and updating the data
structure when getting information from the device:
we bypassed these problems by using callback
functions that act when a special events occur.


Parsing

the XML format messages: we implemented
a special XML parser that satisfies our needs.


The Control Point:


Data Structures and Modules



The Control Point Data Structure


The control point struct contains:




Identifier



Connection sockets (one socket for each protocol
step)


List of connected devices


…….




Cont.


The device struct contains:




Information about the device : device type ,device

version, identifier ,name and manufacturer.




The device description URL.




List of UPnP Services.



Cont.


The service struct contains:


Information about the service : service version, service ID
and service type.


Service Description URL.


Control URL.


Subscription URL.


List of actions that can be invoked by this service.


List of state variables.


…..




Cont.


Each control action has a name and a list of
arguments.


A state variable struct is consisted of:


Name, data type , default value and value.



Data Structure Schema



Control Point


ID


Sockets


Device List



UDP Socket

Description Sockets

Control Socket

Subscription Socket

Eventing Socket

Device 1

Device 2

……….

Service 1

Service 2

Control Action

1

State variable

1

……….

……….

……….

Main Modules


Building message module
: creating messages
according to the protocol syntax rules in every step of
the protocol.


Discovery Module:

this module actually activates
the control point, and creates UDP socket ,sends,
receives and reads messages in the Discovery step,
and according to these messages updates the data
structure.


Device description and Service Description
Modules:

creating connection, sending, receiving
and reading messages in the description step, and
according to these messages updating the data
structure.


Cont.


Control Module:

creating connection,
sending, receiving and reading messages in
the control step of the protocol.


Eventing Module:

creating connection,
reading , sending and receiving eventing and
subscription messages in the eventing step,
and updating the data structure if needed.


List Module:

removing , adding and getting
items (e.g devices, services) from the lists in
the data structure .

Cont.


Parsing Module:

Parsing different
formats of messages according to the
protocol step. (e.g. control ,eventing
messages).


Menu Module:

This module creates
graphical interface, that makes the usage
of the protocol services easy and funny!!


User Interface

The Protocol Interface


The service we have tested is a clock:
the control point sends a request to the
device (demo device in this case)
which reply with the time.


The state variable is the location of the
device.


At first the user chooses the protocol
icon on the mobile, then he/she clicks
start:


Cont.


The control point starts searching for a
device (discovery step).


Afterwards the control point discovers
a device and proposes getting the
device description.

Cont.


The user is asked if he is
interested in getting the service
description (Description step):

Cont.


Control Step: The device is
ready to invoke an action :






References


Universal Plug and Play forum, http;//www.upnp.org


UPnP architecture,
http://www.upnp.org/resources/documents/CleanUPnPDA101
-
20031202s.pdf


Intel’s UPnP SDK for Linux, http://developer.intel.com/ial/upnp/


Simple object access protocol, http://www.w3.org/TR/SOAP/


http://www.artima.com/spontaneous/upnp_digihome2.html


http://brewforums.qualcomm.com/