<?xml version="1.0" encoding="UTF-8"?>
<!--
  Device:2 Root Data Model: Common Object definitions [MQTT]

  Copyright (c) 2010-2021,2024 Broadband Forum

  Redistribution and use in source and binary forms, with or
  without modification, are permitted provided that the following
  conditions are met:

  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above
     copyright notice, this list of conditions and the following
     disclaimer in the documentation and/or other materials
     provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its
     contributors may be used to endorse or promote products
     derived from this software without specific prior written
     permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

  The above license is used as a license under copyright only.
  Please reference the Forum IPR Policy for patent licensing terms
  <https://www.broadband-forum.org/ipr-policy>.

  Any moral rights which are necessary to exercise under the above
  license grant are also deemed granted under this license.

  Comments or questions about this Broadband Forum data model should be
  directed to <info@broadband-forum.org>.
-->

<dm:document
    xmlns:dm="urn:broadband-forum-org:cwmp:datamodel-1-16"
    xmlns:dmr="urn:broadband-forum-org:cwmp:datamodel-report-1-0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
      urn:broadband-forum-org:cwmp:datamodel-1-16
        https://www.broadband-forum.org/cwmp/cwmp-datamodel-1-16.xsd
      urn:broadband-forum-org:cwmp:datamodel-report-1-0
        https://www.broadband-forum.org/cwmp/cwmp-datamodel-report-1-0.xsd"
    spec="urn:broadband-forum-org:tr-181-2-21-0-mqtt-usp"
    file="tr-181-2-21-0-mqtt-usp.xml">

  <import file="tr-069-biblio.xml" spec="urn:broadband-forum-org:tr-069"/>

  <import file="tr-106-types.xml" spec="urn:broadband-forum-org:tr-106">
    <component name="Alias"/>
    <dataType name="StatsCounter32"/>
    <dataType name="StatsCounter64"/>
  </import>

  <import file="tr-181-2-root.xml"
      spec="urn:broadband-forum-org:tr-181-2-21-root">
    <component name="Root"/>
  </import>

   <import file="tr-181-2-security.xml"
      spec="urn:broadband-forum-org:tr-181-2-21-security">
    <component name="TLSClient"/>
    <component name="TLSServer"/>
  </import>

   <import file="tr-181-2-ip.xml"
      spec="urn:broadband-forum-org:tr-181-2-21-ip">
    <component name="IPVersion"/>
  </import>

  <template id="MQTTReconnect">
    {{template|MQTTChange}} If the change needs to be applied immediately, the
    command {{command|ForceReconnect()}} has to be executed.
  </template>

  <template id="MQTTWillChange">
    {{template|MQTTChange}}

    If will handling is enabled (Parameter {{param|WillEnable}} is set to
    {{true}}) and the change needs to be applied immediately, the command
    {{command|ForceReconnect()}} has to be executed.
  </template>

  <component name="MQTTUSP">
    <object base="Device.MQTT.Client.{i}.">
      <command name="ForceReconnect()" dmr:previousParameter="KeepAliveTime"
          version="2.12" async="false">
        <description>
          Disconnects the MQTT client from the MQTT broker and reconnects it
          again (toggle connection). It is only effective if the MQTT client is
          currently connected to the MQTT broker (Parameter {{param|Status}}
          is {{enum|Connected|Status}}).

          If the MQTT client is in a different state, the command has no
          effect.

          This command may be used to immediately apply changes in the MQTT
          connection settings.
        </description>
      </command>

      <command name="Publish()" async="true" version="2.21">
        <description>
          This command is used to publish a message to the MQTT broker.
        </description>
        <input>
          <parameter name="Topic" mandatory="true">
            <description>
              The topic to publish the message to.
            </description>
            <syntax>
              <string>
                <size maxLength="65535" />
              </string>
            </syntax>
          </parameter>

          <parameter name="QoS" mandatory="false">
            <description>
              The QoS level to use for the message. 

              * 0: At most once delivery (best effort).
              * 1: At least once delivery (guaranteed delivery, possible duplicates).
              * 2: Exactly once delivery (guaranteed delivery, no duplicates).
            </description>
            <syntax>
              <unsignedInt>
                <range minInclusive="0" maxInclusive="2"/>
              </unsignedInt>
              <default type="parameter" value="0"/>
            </syntax>
          </parameter>
          
          <parameter name="Retain" mandatory="false">
            <description>
              Indicates whether the message should be retained by the broker.
            </description>
            <syntax>
              <boolean/>
              <default type="parameter" value="false"/>
            </syntax>
          </parameter>

          <parameter name="PayloadEncoding" mandatory="false">
            <description>
              Specifies the encoding of the payload.
            </description>
            <syntax>
              <string>
                <enumeration value="HexBinary"/>
                <enumeration value="String"/>
              </string>
              <default type="parameter" value="String"/>
            </syntax>
          </parameter>

          <parameter name="Payload" mandatory="true">
            <description>
              The payload of the message.
            </description>
            <syntax>
              <string/>
            </syntax>
          </parameter>

          <parameter name="ContentType" mandatory="false">
            <description>
              Specifies the content type of the message payload, e.g., "application/json" or
              "text/plain". It may also include an optional charset parameter, e.g.,
              "charset=UTF-8".
            </description>
            <syntax>
              <string>
                <size maxLength="256"/>
              </string>
            </syntax>
          </parameter>

          <parameter name="ResponseTopic" mandatory="false">
            <description>
              Specifies the topic on which a response to this message should be received.
            </description>
            <syntax>
              <string>
                <size maxLength="65535"/>
              </string>
            </syntax>
          </parameter>
        </input>
      </command>
    </object>

    <object base="Device.MQTT.Broker.{i}.Bridge.{i}." access="readWrite"
        minEntries="0" maxEntries="unbounded">
      <command name="ForceReconnect()" dmr:previousParameter="KeepAliveTime"
          version="2.12" async="false">
        <description>
          Disconnects the MQTT bridge to the remote MQTT broker and reconnects
          it again (toggle connection). It is only effective if the MQTT bridge
          is currently connected to the remote MQTT broker (Parameter
          {{param|Status}} is {{enum|Connected|Status}}).

          If the MQTT bridge is in a different state, the command has no
          effect.

          This command may be used to immediately apply changes in the MQTT
          connection settings.
        </description>
      </command>
    </object>

    <object base="Device.MQTT.Client.{i}.Subscription.{i}.">
        <event name="OnMessage!" version="2.21">
          <description>
            This event is triggered when a message is received for this subscription.
          </description>

          <parameter name="Topic">
            <description>
              The topic on which the message was received.
            </description>
            <syntax>
              <string>
                <size maxLength="65535"/>
              </string>
            </syntax>
          </parameter>

          <parameter name="PayloadEncoding">
            <description>
              Specifies the encoding of the payload.
            </description>
            <syntax>
              <string>
                <enumeration value="HexBinary"/>
                <enumeration value="String"/>
              </string>
            </syntax>
          </parameter>

          <parameter name="Payload">
            <description>
              The payload of the message.
            </description>
            <syntax>
              <string>
                <size maxLength="65535"/>
              </string>
            </syntax>
          </parameter>
        </event>
    </object>

    <profile name="MQTTClientExtended:1" base="MQTTClientBase:1"
        dmr:previousProfile="MQTTClientSubscribe:1" version="2.10">
      <description>
        Adds client authentication, will handling and extends statistics.
      </description>
      <object ref="Device.MQTT.Client.{i}." requirement="present">
        <parameter ref="Name" requirement="readWrite"/>
        <parameter ref="ClientID" requirement="readWrite"/>
        <parameter ref="Username" requirement="readWrite"/>
        <parameter ref="Password" requirement="readWrite"/>
        <parameter ref="TransportProtocol" requirement="readWrite"/>
        <parameter ref="MessageRetryTime" requirement="readWrite"/>
        <parameter ref="ConnectRetryTime" requirement="readWrite"/>
        <command ref="ForceReconnect()"/>
        <parameter ref="WillEnable" requirement="readWrite"/>
        <parameter ref="WillTopic" requirement="readWrite"/>
        <parameter ref="WillValue" requirement="readWrite"/>
        <parameter ref="WillQoS" requirement="readWrite"/>
        <parameter ref="WillRetain" requirement="readWrite"/>
      </object>
      <object ref="Device.MQTT.Client.{i}.Stats." requirement="present">
        <parameter ref="LastPublishMessageSent" requirement="readOnly"/>
        <parameter ref="LastPublishMessageReceived" requirement="readOnly"/>
        <parameter ref="PublishSent" requirement="readOnly"/>
        <parameter ref="PublishReceived" requirement="readOnly"/>
        <parameter ref="SubscribeSent" requirement="readOnly"/>
        <parameter ref="UnSubscribeSent" requirement="readOnly"/>
        <parameter ref="PublishErrors" requirement="readOnly"/>
      </object>
    </profile>
  </component>
</dm:document>
