<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
  <!ENTITY % ents SYSTEM 'xep.ent'>
%ents;
]>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep>
<header>
  <title>Rayo CPA</title>
  <abstract>This specification defines an extension to the Rayo protocol (XEP-0327) to provide provision for performing Call Progress Analysis on a call under the control of a Rayo client.</abstract>
  &LEGALNOTICE;
  <number>0341</number>
  <status>Experimental</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0327 Rayo</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>NOT_YET_ASSIGNED</shortname>
  <author>
    <firstname>Ben</firstname>
    <surname>Langfeld</surname>
    <email>ben@langfeld.me</email>
    <jid>ben@langfeld.me</jid>
    <uri>http://langfeld.me</uri>
  </author>
  <revision>
    <version>0.1</version>
    <date>2014-01-14</date>
    <initials>psa</initials>
    <remark><p>Initial published version approved by the XMPP Council.</p></remark>
  </revision>
  <revision>
    <version>0.0.2</version>
    <date>2014-01-14</date>
    <initials>bl</initials>
    <remark><p>Second draft.</p></remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2013-10-02</date>
    <initials>bl</initials>
    <remark><p>First draft.</p></remark>
  </revision>
</header>
<section1 topic='Introduction' anchor='intro'>
  <p>Rayo allows for the third-party control of media sessions such as telephone calls. A common requirement in telephony applications is to establish the progress characteristics of the session, such as dtmf, fax or modem tones, or to differentiate between a human and an answering machine. This specification extends the core Rayo specification, and specifically its Input component to describe a protocol for establishing such progress analysis and gathering its results.</p>
</section1>
<section1 topic='Terminology' anchor='terms'>
  <section2 topic='Glossary' anchor='terms-glossary'>
    <dl>
      <di>
        <dt>CPA</dt>
        <dd>Call progress analysis.</dd>
      </di>
    </dl>
  </section2>
</section1>
<section1 topic='Session Flow' anchor='session'>
  <p>This section describes the form, function and order of Rayo stanzas sent across the wire, and the circumstances in which they apply and/or may arise.</p>

  <p>CPA is achieved as a special case of the core input component. All rules regarding component execution and the input component in particular apply from the core specification. When a call's controlling party wishes to begin detection of signals from the suported set, it SHOULD begin an input component with the mode attribute set as 'cpa'.</p>

  <p>The grammars supplied determine the types of signal detected and parameters applied to their detection. The grammars MUST be referenced by URI in the format described <link url="#def-grammar">below</link>. If a Rayo server supports this specification, it MUST invoke its supported CPA function using the parameters provided from the grammars; if it does not support this specification or any of the supplied parameters within the grammar, it MUST raise an error according to the rules in the core specification.</p>

  <example caption='Client requests CPA from a call, indicating interest in speech detection and DTMF'><![CDATA[
<iq from='juliet@capulet.lit/balcony'
    to='9f00061@call.shakespeare.lit'
    type='set'
    id='h7ed2'>
  <input xmlns='urn:xmpp:rayo:input:1' mode='cpa'>
    <grammar url="urn:xmpp:rayo:cpa:speech:1?maxTime=4000;minSpeechDuration=4000;minVolume=10;finalSilence=2000;terminate=true" />
    <grammar url="urn:xmpp:rayo:cpa:dtmf:1" />
  </input>
</iq>
  ]]></example>

  <p>The server MUST validate that it has appropriate resources/mechanisms to collect the requested signals before acknowledging the component creation.</p>

  <section2 topic='Events' anchor='session-events'>
    <p>If the meta-attribute named 'terminate' is set to true in the grammar, the component MUST terminate on the first signal match it detects. If it is set to false, signals MUST be reported as events until the component is instructed to stop.</p>

    <example caption="Component indicates that a signal was detected"><![CDATA[
<presence from='9f00061@call.shakespeare.lit/eh3u28' to='juliet@capulet.lit/courtyard'>
  <signal xmlns="urn:xmpp:rayo:cpa:1" type="urn:xmpp:rayo:cpa:dtmf:1" duration="4690" value="1"/>
</presence>
    ]]></example>
  </section2>

  <section2 topic='Completion' anchor='session-completion'>
    <p>The input completion reason MUST be one of the supported reasons from the core specification or a <link url='#def-signal'>signal</link>, indicating that the CPA engine detected one of the requested signals. Any signals other than those requested by the input grammar should be ignored.</p>

    <example caption="Component indicates it has completed due to one of the grammars matching a detected signal"><![CDATA[
<presence from='9f00061@call.shakespeare.lit/eh3u28'
      to='juliet@capulet.lit/courtyard'
      type='unavailable'>
  <complete xmlns='urn:xmpp:rayo:ext:1'>
    <signal xmlns="urn:xmpp:rayo:cpa:1" type="urn:xmpp:rayo:cpa:speech:1" duration="4690" value="machine"/>
  </complete>
</presence>
    ]]></example>
  </section2>
</section1>
<section1 topic='Formal Definition' anchor='def'>
  <section2 topic='Grammar Format' anchor='def-grammar'>
    <p>The grammar URI declares the signal type of interest and the parameters which apply to their detection. The URI should be composed of a URN from <link url='#def-signal-types'>the following list of allowed signal types</link>, and parameters to modify their detection as a query string. The names and allowed values of these parameters are implementation specific. Servers MUST support one reserved parameter named 'terminate', whose value indicates the termination behaviour of the component on signal detection as described <link url='#session-events'>above</link>.</p>
  </section2>

  <section2 topic='Signal Element' anchor='def-signal'>
    <p>Describes a detected signal.</p>
    <p>The attributes of the &lt;grammar/&gt; element are as follows.</p>
    <table caption='Attributes of Signal Element'>
      <tr>
        <th>Attribute</th>
        <th>Definition</th>
        <th>Possible Values</th>
        <th>Default</th>
        <th>Inclusion</th>
      </tr>
      <tr>
        <td>type</td>
        <td>Indicates the type of signal detected.</td>
        <td>Any URI value from <link url='#def-signal-types'>the listed signal types</link></td>
        <td>none</td>
        <td>REQUIRED</td>
      </tr>
      <tr>
        <td>duration</td>
        <td>Indicates the duration of the received signal in milliseconds</td>
        <td>An integer value in milliseconds.</td>
        <td>none</td>
        <td>OPTIONAL</td>
      </tr>
      <tr>
        <td>value</td>
        <td>Indicates the value of the signal received if applicable.</td>
        <td>For dtmf tones it is the digit detected, for speech may be human|machine|notsure and for beeps may be a frequency in Hz.</td>
        <td>none</td>
        <td>OPTIONAL</td>
      </tr>
    </table>
  </section2>

  <section2 topic='Signal Types' anchor='def-signal-types'>
    <p>Signal types may be one of the following:</p>
    <table caption='Signal type URIs'>
      <tr>
        <th>URI</th>
        <th>Description</th>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:beep:1</td>
        <td>Detect a beep.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:dtmf:1</td>
        <td>Detect DTMF tones.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:vad:1</td>
        <td>Detect voice activity.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:speech:1</td>
        <td>Detect speech and decide human or machine.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:fax-ced:1</td>
        <td>Detect a fax CED tone.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:fax-cng:1</td>
        <td>Detect a fax CNG tone.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:ring:1</td>
        <td>Detect a ringing tone.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:busy:1</td>
        <td>Detect a busy tone.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:congestion:1</td>
        <td>Detect a congestion tone.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:sit:1</td>
        <td>Detect a Special Information Tone.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:modem:1</td>
        <td>Detect a modem tone.</td>
      </tr>
      <tr>
        <td>urn:xmpp:rayo:cpa:offhook:1</td>
        <td>Detect an off-hook tone.</td>
      </tr>
    </table>
  </section2>
</section1>
<section1 topic='Determining Support' anchor='support'>
  <p>If a Rayo server supports Rayo CPA, it MUST advertise that fact by returning a feature of "urn:xmpp:rayo|cpa:0" &VNOTE; in response to a &xep0030; information request.</p>
  <example caption="Service Discovery Information Request - Client to Server"><![CDATA[
<iq from='kingclaudius@shakespeare.lit/castle'
    id='disco1'
    to='call.rayo.org'
    type='get'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
  ]]></example>
  <example caption="Service Discovery Information Response - Client to Server"><![CDATA[
<iq from='call.rayo.org'
    id='disco1'
    to='kingclaudius@shakespeare.lit/castle'
    type='result'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <feature var='urn:xmpp:rayo:0'/>
    <feature var='urn:xmpp:rayo:cpa:0'/>
  </query>
</iq>
  ]]></example>
  <p>In order for an application to determine whether an entity supports this protocol, where possible it SHOULD use the dynamic, presence-based profile of service discovery defined in &xep0115;. However, if an application has not received entity capabilities information from an entity, it SHOULD use explicit service discovery instead.</p>
</section1>
<section1 topic='Implementation Notes' anchor='impl'>
  <p>A server MUST document any cases where its behaviour differs from that in this specification (such as lack of support for particular options/components/etc) and return an error whenever a command is not understood. A server MUST NOT silently ignore any instructions.</p>
</section1>
<section1 topic='Security Considerations' anchor='security'>
  <p>This document introduces no additional security considerations above and beyond those defined in the documents on which it depends.</p>
</section1>
<section1 topic='IANA Considerations' anchor='iana'>
  <p>This document requires no interaction with &IANA;.</p>
</section1>
<section1 topic='XMPP Registrar Considerations' anchor='registrar'>
    <section2 topic='Protocol Namespaces' anchor='registrar-ns'>
    <p>This specification defines the following XML namespaces:</p>
    <ul>
      <li>urn:xmpp:rayo:cpa:1</li>
      <li>urn:xmpp:rayo:cpa:beep:1</li>
      <li>urn:xmpp:rayo:cpa:dtmf:1</li>
      <li>urn:xmpp:rayo:cpa:vad:1</li>
      <li>urn:xmpp:rayo:cpa:speech:1</li>
      <li>urn:xmpp:rayo:cpa:fax-ced:1</li>
      <li>urn:xmpp:rayo:cpa:fax-cng:1</li>
      <li>urn:xmpp:rayo:cpa:ring:1</li>
      <li>urn:xmpp:rayo:cpa:busy:1</li>
      <li>urn:xmpp:rayo:cpa:congestion:1</li>
      <li>urn:xmpp:rayo:cpa:sit:1</li>
      <li>urn:xmpp:rayo:cpa:modem:1</li>
      <li>urn:xmpp:rayo:cpa:offhook:1</li>
    </ul>
    <p>The &REGISTRAR; includes the foregoing namespaces in its registry at &NAMESPACES;, as governed by &xep0053;.</p>
  </section2>
  <section2 topic='Namespace Versioning' anchor='registrar-versioning'>
    <p>If the protocol defined in this specification undergoes a major revision that is not fully backward-compatible with an older version, or that contains significant new features, the XMPP Registrar shall increment the protocol version number found at the end of the XML namespaces defined herein, as described in Section 4 of <cite>XEP-0053</cite>.</p>
  </section2>
</section1>
<section1 topic='XML Schema' anchor='schema'>
  <section2 topic='Rayo CPA' anchor='schema-rayo-cpa'>
  <code><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
  targetNamespace="urn:xmpp:rayo:input:1"
  xmlns:tns="urn:xmpp:rayo:cpa:1"
  elementFormDefault="qualified"
  xmlns:core="urn:xmpp:rayo:1">

  <annotation>
    <documentation>
      The protocol documented by this schema is defined at http://rayo.org/xep
    </documentation>
  </annotation>

  <!-- Signal element -->
  <element name="signal">
    <annotation>
      <documentation>
        Describes a detected signal.
      </documentation>
    </annotation>
    <complexType>
      <simpleContent>
        <attribute name="type" use="required">
          <annotation>
            <documentation>
              Indicates the type of signal detected.
            </documentation>
          </annotation>
          <simpleType>
            <restriction base="token">
              <enumeration value="urn:xmpp:rayo:cpa:beep:1" />
              <enumeration value="urn:xmpp:rayo:cpa:dtmf:1" />
              <enumeration value="urn:xmpp:rayo:cpa:vad:1" />
              <enumeration value="urn:xmpp:rayo:cpa:speech:1" />
              <enumeration value="urn:xmpp:rayo:cpa:fax-ced:1" />
              <enumeration value="urn:xmpp:rayo:cpa:fax-cng:1" />
              <enumeration value="urn:xmpp:rayo:cpa:ring:1" />
              <enumeration value="urn:xmpp:rayo:cpa:busy:1" />
              <enumeration value="urn:xmpp:rayo:cpa:congestion:1" />
              <enumeration value="urn:xmpp:rayo:cpa:sit:1" />
              <enumeration value="urn:xmpp:rayo:cpa:modem:1" />
              <enumeration value="urn:xmpp:rayo:cpa:offhook:1" />
            </restriction>
          </simpleType>
        </attribute>
        <attribute name="duration" type="core:durationType" use="optional" default="">
          <annotation>
            <documentation>
              Indicates the duration of the received signal in milliseconds
            </documentation>
          </annotation>
        </attribute>
        <attribute name="value" type="token" use="optional" default="">
          <annotation>
            <documentation>
              Indicates the value of the signal received if applicable. For dtmf tones it is the digit detected, for speech may be human|machine|notsure and for beeps may be a frequency in Hz.
            </documentation>
          </annotation>
        </attribute>
      </simpleContent>
    </complexType>
  </element>
</schema>
    ]]></code>
  </section2>
</section1>
<section1 topic='Acknowledgements' anchor='acknowledgements'>
  <p>The authors would like to acknowledge the input of teams at Tropo Inc, Mojo Lingo and Grasshopper in the development of this specification.</p>

  <p>Specific individuals who have contributed to the specification or to software significant to its completion include:</p>
  <ul>
    <li>Ben Langfeld</li>
    <li>Chris Rienzo</li>
    <li>Martín Pérez</li>
  </ul>
</section1>
</xep>
