• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2024, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file This file includes definitions for spinel property encoding and decoding functions.
31  */
32 
33 #ifndef SPINEL_PROP_CODEC_HPP_
34 #define SPINEL_PROP_CODEC_HPP_
35 
36 #include <openthread/platform/dnssd.h>
37 
38 #include "lib/spinel/spinel.h"
39 #include "lib/spinel/spinel_decoder.hpp"
40 #include "lib/spinel/spinel_encoder.hpp"
41 
42 namespace ot {
43 namespace Spinel {
44 
45 /**
46  * Use Spinel::Encoder to encode a Dnssd object.
47  *
48  * A Spinel header and command MUST have been encoded by the encoder.
49  *
50  * @param[in] aEncoder    A reference to the encoder object.
51  * @param[in] aObj        A reference to the dnssd object. (otPlatDnssdHost, otPlatDnssdService or otPlatDnssdKey).
52  * @param[in] aRequestId  The request id.
53  * @param[in] aCallback   A callback to receive the dnssd update result.
54  */
55 template <typename DnssdObjType>
56 otError EncodeDnssd(Encoder                    &aEncoder,
57                     const DnssdObjType         &aObj,
58                     otPlatDnssdRequestId        aRequestId,
59                     otPlatDnssdRegisterCallback aCallback);
60 
61 /**
62  * Use Spinel::Decoder to decode a SPINEL_PROP_DNSSD_HOST message to a otPlatDnssdHost.
63  *
64  * The decoder MUST have read the header, command and property key of the frame.
65  *
66  * @param[in]  aDecoder      A reference to the decoder object.
67  * @param[out] aHost         A reference to the dnssd host.
68  * @param[out] aRequestId    A reference to the request id.
69  * @param[out] aCallback     A reference to the pointer to the callback data.
70  * @param[out] aCallbackLen  A reference to the callback data length.
71  */
72 otError DecodeDnssdHost(Decoder              &aDecoder,
73                         otPlatDnssdHost      &aHost,
74                         otPlatDnssdRequestId &aRequestId,
75                         const uint8_t       *&aCallbackData,
76                         uint16_t             &aCallbackDataLen);
77 
78 /**
79  * Use Spinel::Decoder to decode a SPINEL_PROP_DNSSD_SERVICE message to a otPlatDnssdService.
80  *
81  * The decoder MUST have read the header, command and property key of the frame.
82  *
83  * @param[in]  aDecoder        A reference to the decoder object.
84  * @param[out] aService        A reference to the dnssd service.
85  * @param[out] aRequestId      A reference to the request id.
86  * @param[out] aSubTypeLabels  A pointer to the array of sub-type labels.
87  * @param[out] aSubTypeCount   The number of sub-type labels.
88  * @param[out] aCallback       A reference to the pointer to the callback data.
89  * @param[out] aCallbackLen    A reference to the callback data length.
90  */
91 otError DecodeDnssdService(Decoder              &aDecoder,
92                            otPlatDnssdService   &aService,
93                            const char          **aSubTypeLabels,
94                            uint16_t             &aSubTypeLabelsCount,
95                            otPlatDnssdRequestId &aRequestId,
96                            const uint8_t       *&aCallbackData,
97                            uint16_t             &aCallbackDataLen);
98 
99 /**
100  * Use Spinel::Decoder to decode a SPINEL_PROP_DNSSD_KEY_RECORD message to a otPlatDnssdKey.
101  *
102  * The decoder MUST have read the header, command and property key of the frame.
103  *
104  * @param[in]  aDecoder      A reference to the decoder object.
105  * @param[out] aKey          A reference to the dnssd key.
106  * @param[out] aRequestId    A reference to the request id.
107  * @param[out] aCallback     A reference to the pointer to the callback data.
108  * @param[out] aCallbackLen  A reference to the callback data length.
109  */
110 otError DecodeDnssdKey(Decoder              &aDecoder,
111                        otPlatDnssdKey       &aKey,
112                        otPlatDnssdRequestId &aRequestId,
113                        const uint8_t       *&aCallbackData,
114                        uint16_t             &aCallbackDataLen);
115 
116 } // namespace Spinel
117 } // namespace ot
118 
119 #endif // SPINEL_PROP_CODEC_HPP_
120