• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2016, 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
31  *   This file contains definitions for the CLI interpreter.
32  */
33 
34 #ifndef CLI_DATASET_HPP_
35 #define CLI_DATASET_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <stdarg.h>
40 
41 #include <openthread/dataset.h>
42 
43 #include "cli/cli_utils.hpp"
44 
45 namespace ot {
46 namespace Cli {
47 
48 /**
49  * Implements the Dataset CLI interpreter.
50  */
51 class Dataset : private Utils
52 {
53 public:
Dataset(otInstance * aInstance,OutputImplementer & aOutputImplementer)54     Dataset(otInstance *aInstance, OutputImplementer &aOutputImplementer)
55         : Utils(aInstance, aOutputImplementer)
56     {
57     }
58 
59     /**
60      * Processes a CLI sub-command.
61      *
62      * @param[in]  aArgs     An array of command line arguments.
63      *
64      * @retval OT_ERROR_NONE              Successfully executed the CLI command.
65      * @retval OT_ERROR_PENDING           The CLI command was successfully started but final result is pending.
66      * @retval OT_ERROR_INVALID_COMMAND   Invalid or unknown CLI command.
67      * @retval OT_ERROR_INVALID_ARGS      Invalid arguments.
68      * @retval ...                        Error during execution of the CLI command.
69      */
70     otError Process(Arg aArgs[]);
71 
72 private:
73     using Command    = CommandEntry<Dataset>;
74     using Components = otOperationalDatasetComponents;
75 
76     struct ComponentMapper
77     {
Compareot::Cli::Dataset::ComponentMapper78         int Compare(const char *aName) const { return strcmp(aName, mName); }
79 
AreInOrderot::Cli::Dataset::ComponentMapper80         constexpr static bool AreInOrder(const ComponentMapper &aFirst, const ComponentMapper &aSecond)
81         {
82             return AreStringsInOrder(aFirst.mName, aSecond.mName);
83         }
84 
85         const char *mName;
86         bool Components::*mIsPresentPtr;
87         void (Dataset::*mOutput)(const otOperationalDataset &aDataset);
88         otError (Dataset::*mParse)(Arg *&aArgs, otOperationalDataset &aDataset);
89     };
90 
91     const ComponentMapper *LookupMapper(const char *aName) const;
92 
93     void OutputActiveTimestamp(const otOperationalDataset &aDataset);
94     void OutputChannel(const otOperationalDataset &aDataset);
95     void OutputWakeupChannel(const otOperationalDataset &aDataset);
96     void OutputChannelMask(const otOperationalDataset &aDataset);
97     void OutputDelay(const otOperationalDataset &aDataset);
98     void OutputExtendedPanId(const otOperationalDataset &aDataset);
99     void OutputMeshLocalPrefix(const otOperationalDataset &aDataset);
100     void OutputNetworkKey(const otOperationalDataset &aDataset);
101     void OutputNetworkName(const otOperationalDataset &aDataset);
102     void OutputPanId(const otOperationalDataset &aDataset);
103     void OutputPendingTimestamp(const otOperationalDataset &aDataset);
104     void OutputPskc(const otOperationalDataset &aDataset);
105     void OutputSecurityPolicy(const otOperationalDataset &aDataset);
106 
107     otError ParseActiveTimestamp(Arg *&aArgs, otOperationalDataset &aDataset);
108     otError ParseChannel(Arg *&aArgs, otOperationalDataset &aDataset);
109     otError ParseWakeupChannel(Arg *&aArgs, otOperationalDataset &aDataset);
110     otError ParseChannelMask(Arg *&aArgs, otOperationalDataset &aDataset);
111     otError ParseDelay(Arg *&aArgs, otOperationalDataset &aDataset);
112     otError ParseExtendedPanId(Arg *&aArgs, otOperationalDataset &aDataset);
113     otError ParseMeshLocalPrefix(Arg *&aArgs, otOperationalDataset &aDataset);
114     otError ParseNetworkKey(Arg *&aArgs, otOperationalDataset &aDataset);
115     otError ParseNetworkName(Arg *&aArgs, otOperationalDataset &aDataset);
116     otError ParsePanId(Arg *&aArgs, otOperationalDataset &aDataset);
117     otError ParsePendingTimestamp(Arg *&aArgs, otOperationalDataset &aDataset);
118     otError ParsePskc(Arg *&aArgs, otOperationalDataset &aDataset);
119     otError ParseSecurityPolicy(Arg *&aArgs, otOperationalDataset &aDataset);
120 
121     otError ParseTlvs(Arg &aArg, otOperationalDatasetTlvs &aDatasetTlvs);
122 
123     otError ProcessCommand(const ComponentMapper &aMapper, Arg aArgs[]);
124 
125     template <CommandId kCommandId> otError Process(Arg aArgs[]);
126 
127     otError Print(otOperationalDatasetTlvs &aDatasetTlvs);
128 
129 #if OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
130     otError     ProcessUpdater(Arg aArgs[]);
131     static void HandleDatasetUpdater(otError aError, void *aContext);
132     void        HandleDatasetUpdater(otError aError);
133 #endif
134 
135     void    OutputSecurityPolicy(const otSecurityPolicy &aSecurityPolicy);
136     otError ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, Arg *&aArgs);
137 
138     static otOperationalDatasetTlvs sDatasetTlvs;
139 };
140 
141 } // namespace Cli
142 } // namespace ot
143 
144 #endif // CLI_DATASET_HPP_
145