2 * Copyright (c) 2019, The OpenThread Authors.
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.
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.
31 * This file includes definitions for ubus API.
34 #ifndef OTBR_AGENT_OTUBUS_HPP_
35 #define OTBR_AGENT_OTUBUS_HPP_
37 #include "openthread-br/config.h"
42 #include <openthread/ip6.h>
43 #include <openthread/link.h>
44 #include <openthread/netdiag.h>
45 #include <openthread/udp.h>
47 #include "common/code_utils.hpp"
50 #include <libubox/blobmsg_json.h>
51 #include <libubox/uloop.h>
52 #include <libubox/ustream.h>
53 #include <libubox/utils.h>
59 class ControllerOpenThread;
65 * @namespace otbr::ubus
68 * This namespace contains definitions for ubus related instance.
78 * @param[in] aController A pointer to OpenThread Controller structure.
80 static void Initialize(Ncp::ControllerOpenThread *aController);
83 * This method return the instance of the global UbusServer.
85 * @retval the reference of the UbusServer Instance.
88 static UbusServer &GetInstance(void);
91 * This method install ubus object onto OpenWRT.
94 void InstallUbusObject(void);
97 * This method handle ubus scan function request.
99 * @param[in] aContext A pointer to the ubus context.
100 * @param[in] aObj A pointer to the ubus object.
101 * @param[in] aRequest A pointer to the ubus request.
102 * @param[in] aMethod A pointer to the ubus method.
103 * @param[in] aMsg A pointer to the ubus message.
105 * @retval 0 Successfully handler the request.
108 static int UbusScanHandler(struct ubus_context * aContext,
109 struct ubus_object * aObj,
110 struct ubus_request_data *aRequest,
111 const char * aMethod,
112 struct blob_attr * aMsg);
115 * This method handle ubus get channel function request.
117 * @param[in] aContext A pointer to the ubus context.
118 * @param[in] aObj A pointer to the ubus object.
119 * @param[in] aRequest A pointer to the ubus request.
120 * @param[in] aMethod A pointer to the ubus method.
121 * @param[in] aMsg A pointer to the ubus message.
123 * @retval 0 Successfully handler the request.
126 static int UbusChannelHandler(struct ubus_context * aContext,
127 struct ubus_object * aObj,
128 struct ubus_request_data *aRequest,
129 const char * aMethod,
130 struct blob_attr * aMsg);
133 * This method handle ubus set channel function request.
135 * @param[in] aContext A pointer to the ubus context.
136 * @param[in] aObj A pointer to the ubus object.
137 * @param[in] aRequest A pointer to the ubus request.
138 * @param[in] aMethod A pointer to the ubus method.
139 * @param[in] aMsg A pointer to the ubus message.
141 * @retval 0 Successfully handler the request.
144 static int UbusSetChannelHandler(struct ubus_context * aContext,
145 struct ubus_object * aObj,
146 struct ubus_request_data *aRequest,
147 const char * aMethod,
148 struct blob_attr * aMsg);
151 * This method handle ubus get networkname function request.
153 * @param[in] aContext A pointer to the ubus context.
154 * @param[in] aObj A pointer to the ubus object.
155 * @param[in] aRequest A pointer to the ubus request.
156 * @param[in] aMethod A pointer to the ubus method.
157 * @param[in] aMsg A pointer to the ubus message.
159 * @retval 0 Successfully handler the request.
162 static int UbusNetworknameHandler(struct ubus_context * aContext,
163 struct ubus_object * aObj,
164 struct ubus_request_data *aRequest,
165 const char * aMethod,
166 struct blob_attr * aMsg);
169 * This method handle ubus set networkname function request.
171 * @param[in] aContext A pointer to the ubus context.
172 * @param[in] aObj A pointer to the ubus object.
173 * @param[in] aRequest A pointer to the ubus request.
174 * @param[in] aMethod A pointer to the ubus method.
175 * @param[in] aMsg A pointer to the ubus message.
177 * @retval 0 Successfully handler the request.
180 static int UbusSetNetworknameHandler(struct ubus_context * aContext,
181 struct ubus_object * aObj,
182 struct ubus_request_data *aRequest,
183 const char * aMethod,
184 struct blob_attr * aMsg);
187 * This method handle ubus get state function request.
189 * @param[in] aContext A pointer to the ubus context.
190 * @param[in] aObj A pointer to the ubus object.
191 * @param[in] aRequest A pointer to the ubus request.
192 * @param[in] aMethod A pointer to the ubus method.
193 * @param[in] aMsg A pointer to the ubus message.
195 * @retval 0 Successfully handler the request.
198 static int UbusStateHandler(struct ubus_context * aContext,
199 struct ubus_object * aObj,
200 struct ubus_request_data *aRequest,
201 const char * aMethod,
202 struct blob_attr * aMsg);
205 * This method handle ubus set state function request.
207 * @param[in] aContext A pointer to the ubus context.
208 * @param[in] aObj A pointer to the ubus object.
209 * @param[in] aRequest A pointer to the ubus request.
210 * @param[in] aMethod A pointer to the ubus method.
211 * @param[in] aMsg A pointer to the ubus message.
213 * @retval 0 Successfully handler the request.
216 static int UbusMacfilterSetStateHandler(struct ubus_context * aContext,
217 struct ubus_object * aObj,
218 struct ubus_request_data *aRequest,
219 const char * aMethod,
220 struct blob_attr * aMsg);
223 * This method handle ubus get panid function request.
225 * @param[in] aContext A pointer to the ubus context.
226 * @param[in] aObj A pointer to the ubus object.
227 * @param[in] aRequest A pointer to the ubus request.
228 * @param[in] aMethod A pointer to the ubus method.
229 * @param[in] aMsg A pointer to the ubus message.
231 * @retval 0 Successfully handler the request.
234 static int UbusPanIdHandler(struct ubus_context * aContext,
235 struct ubus_object * aObj,
236 struct ubus_request_data *aRequest,
237 const char * aMethod,
238 struct blob_attr * aMsg);
241 * This method handle ubus set panid function request.
243 * @param[in] aContext A pointer to the ubus context.
244 * @param[in] aObj A pointer to the ubus object.
245 * @param[in] aRequest A pointer to the ubus request.
246 * @param[in] aMethod A pointer to the ubus method.
247 * @param[in] aMsg A pointer to the ubus message.
249 * @retval 0 Successfully handler the request.
252 static int UbusSetPanIdHandler(struct ubus_context * aContext,
253 struct ubus_object * aObj,
254 struct ubus_request_data *aRequest,
255 const char * aMethod,
256 struct blob_attr * aMsg);
259 * This method handle ubus get pskc function request.
261 * @param[in] aContext A pointer to the ubus context.
262 * @param[in] aObj A pointer to the ubus object.
263 * @param[in] aRequest A pointer to the ubus request.
264 * @param[in] aMethod A pointer to the ubus method.
265 * @param[in] aMsg A pointer to the ubus message.
267 * @retval 0 Successfully handler the request.
270 static int UbusPskcHandler(struct ubus_context * aContext,
271 struct ubus_object * aObj,
272 struct ubus_request_data *aRequest,
273 const char * aMethod,
274 struct blob_attr * aMsg);
277 * This method handle ubus set pskc function request.
279 * @param[in] aContext A pointer to the ubus context.
280 * @param[in] aObj A pointer to the ubus object.
281 * @param[in] aRequest A pointer to the ubus request.
282 * @param[in] aMethod A pointer to the ubus method.
283 * @param[in] aMsg A pointer to the ubus message.
285 * @retval 0 Successfully handler the request.
288 static int UbusSetPskcHandler(struct ubus_context * aContext,
289 struct ubus_object * aObj,
290 struct ubus_request_data *aRequest,
291 const char * aMethod,
292 struct blob_attr * aMsg);
295 * This method handle ubus get masterkey function request.
297 * @param[in] aContext A pointer to the ubus context.
298 * @param[in] aObj A pointer to the ubus object.
299 * @param[in] aRequest A pointer to the ubus request.
300 * @param[in] aMethod A pointer to the ubus method.
301 * @param[in] aMsg A pointer to the ubus message.
303 * @retval 0 Successfully handler the request.
306 static int UbusMasterkeyHandler(struct ubus_context * aContext,
307 struct ubus_object * aObj,
308 struct ubus_request_data *aRequest,
309 const char * aMethod,
310 struct blob_attr * aMsg);
313 * This method handle ubus set masterkey function request.
315 * @param[in] aContext A pointer to the ubus context.
316 * @param[in] aObj A pointer to the ubus object.
317 * @param[in] aRequest A pointer to the ubus request.
318 * @param[in] aMethod A pointer to the ubus method.
319 * @param[in] aMsg A pointer to the ubus message.
321 * @retval 0 Successfully handler the request.
324 static int UbusSetMasterkeyHandler(struct ubus_context * aContext,
325 struct ubus_object * aObj,
326 struct ubus_request_data *aRequest,
327 const char * aMethod,
328 struct blob_attr * aMsg);
331 * This method handle ubus get rloc16 function request.
333 * @param[in] aContext A pointer to the ubus context.
334 * @param[in] aObj A pointer to the ubus object.
335 * @param[in] aRequest A pointer to the ubus request.
336 * @param[in] aMethod A pointer to the ubus method.
337 * @param[in] aMsg A pointer to the ubus message.
339 * @retval 0 Successfully handler the request.
342 static int UbusRloc16Handler(struct ubus_context * aContext,
343 struct ubus_object * aObj,
344 struct ubus_request_data *aRequest,
345 const char * aMethod,
346 struct blob_attr * aMsg);
349 * This method handle ubus get extpanid function request.
351 * @param[in] aContext A pointer to the ubus context.
352 * @param[in] aObj A pointer to the ubus object.
353 * @param[in] aRequest A pointer to the ubus request.
354 * @param[in] aMethod A pointer to the ubus method.
355 * @param[in] aMsg A pointer to the ubus message.
357 * @retval 0 Successfully handler the request.
360 static int UbusExtPanIdHandler(struct ubus_context * aContext,
361 struct ubus_object * aObj,
362 struct ubus_request_data *aRequest,
363 const char * aMethod,
364 struct blob_attr * aMsg);
367 * This method handle ubus set extpanid function request.
369 * @param[in] aContext A pointer to the ubus context.
370 * @param[in] aObj A pointer to the ubus object.
371 * @param[in] aRequest A pointer to the ubus request.
372 * @param[in] aMethod A pointer to the ubus method.
373 * @param[in] aMsg A pointer to the ubus message.
375 * @retval 0 Successfully handler the request.
378 static int UbusSetExtPanIdHandler(struct ubus_context * aContext,
379 struct ubus_object * aObj,
380 struct ubus_request_data *aRequest,
381 const char * aMethod,
382 struct blob_attr * aMsg);
385 * This method handle ubus get mode function request.
387 * @param[in] aContext A pointer to the ubus context.
388 * @param[in] aObj A pointer to the ubus object.
389 * @param[in] aRequest A pointer to the ubus request.
390 * @param[in] aMethod A pointer to the ubus method.
391 * @param[in] aMsg A pointer to the ubus message.
393 * @retval 0 Successfully handler the request.
396 static int UbusModeHandler(struct ubus_context * aContext,
397 struct ubus_object * aObj,
398 struct ubus_request_data *aRequest,
399 const char * aMethod,
400 struct blob_attr * aMsg);
403 * This method handle ubus set mode function request.
405 * @param[in] aContext A pointer to the ubus context.
406 * @param[in] aObj A pointer to the ubus object.
407 * @param[in] aRequest A pointer to the ubus request.
408 * @param[in] aMethod A pointer to the ubus method.
409 * @param[in] aMsg A pointer to the ubus message.
411 * @retval 0 Successfully handler the request.
414 static int UbusSetModeHandler(struct ubus_context * aContext,
415 struct ubus_object * aObj,
416 struct ubus_request_data *aRequest,
417 const char * aMethod,
418 struct blob_attr * aMsg);
421 * This method handle ubus get partitionid function request.
423 * @param[in] aContext A pointer to the ubus context.
424 * @param[in] aObj A pointer to the ubus object.
425 * @param[in] aRequest A pointer to the ubus request.
426 * @param[in] aMethod A pointer to the ubus method.
427 * @param[in] aMsg A pointer to the ubus message.
429 * @retval 0 Successfully handler the request.
432 static int UbusPartitionIdHandler(struct ubus_context * aContext,
433 struct ubus_object * aObj,
434 struct ubus_request_data *aRequest,
435 const char * aMethod,
436 struct blob_attr * aMsg);
439 * This method handle ubus get leaderdata function request.
441 * @param[in] aContext A pointer to the ubus context.
442 * @param[in] aObj A pointer to the ubus object.
443 * @param[in] aRequest A pointer to the ubus request.
444 * @param[in] aMethod A pointer to the ubus method.
445 * @param[in] aMsg A pointer to the ubus message.
447 * @retval 0 Successfully handler the request.
450 static int UbusLeaderdataHandler(struct ubus_context * aContext,
451 struct ubus_object * aObj,
452 struct ubus_request_data *aRequest,
453 const char * aMethod,
454 struct blob_attr * aMsg);
457 * This method handle ubus get networkdata function request.
459 * @param[in] aContext A pointer to the ubus context.
460 * @param[in] aObj A pointer to the ubus object.
461 * @param[in] aRequest A pointer to the ubus request.
462 * @param[in] aMethod A pointer to the ubus method.
463 * @param[in] aMsg A pointer to the ubus message.
465 * @retval 0 Successfully handler the request.
468 static int UbusNetworkdataHandler(struct ubus_context * aContext,
469 struct ubus_object * aObj,
470 struct ubus_request_data *aRequest,
471 const char * aMethod,
472 struct blob_attr * aMsg);
475 * This method handle ubus get parent function request.
477 * @param[in] aContext A pointer to the ubus context.
478 * @param[in] aObj A pointer to the ubus object.
479 * @param[in] aRequest A pointer to the ubus request.
480 * @param[in] aMethod A pointer to the ubus method.
481 * @param[in] aMsg A pointer to the ubus message.
483 * @retval 0 Successfully handler the request.
486 static int UbusParentHandler(struct ubus_context * aContext,
487 struct ubus_object * aObj,
488 struct ubus_request_data *aRequest,
489 const char * aMethod,
490 struct blob_attr * aMsg);
493 * This method handle ubus get neighbor function request.
495 * @param[in] aContext A pointer to the ubus context.
496 * @param[in] aObj A pointer to the ubus object.
497 * @param[in] aRequest A pointer to the ubus request.
498 * @param[in] aMethod A pointer to the ubus method.
499 * @param[in] aMsg A pointer to the ubus message.
501 * @retval 0 Successfully handler the request.
504 static int UbusNeighborHandler(struct ubus_context * aContext,
505 struct ubus_object * aObj,
506 struct ubus_request_data *aRequest,
507 const char * aMethod,
508 struct blob_attr * aMsg);
511 * This method handle ubus start thread function request.
513 * @param[in] aContext A pointer to the ubus context.
514 * @param[in] aObj A pointer to the ubus object.
515 * @param[in] aRequest A pointer to the ubus request.
516 * @param[in] aMethod A pointer to the ubus method.
517 * @param[in] aMsg A pointer to the ubus message.
519 * @retval 0 Successfully handler the request.
522 static int UbusThreadStartHandler(struct ubus_context * aContext,
523 struct ubus_object * aObj,
524 struct ubus_request_data *aRequest,
525 const char * aMethod,
526 struct blob_attr * aMsg);
529 * This method handle ubus stop thread function request.
531 * @param[in] aContext A pointer to the ubus context.
532 * @param[in] aObj A pointer to the ubus object.
533 * @param[in] aRequest A pointer to the ubus request.
534 * @param[in] aMethod A pointer to the ubus method.
535 * @param[in] aMsg A pointer to the ubus message.
537 * @retval 0 Successfully handler the request.
540 static int UbusThreadStopHandler(struct ubus_context * aContext,
541 struct ubus_object * aObj,
542 struct ubus_request_data *aRequest,
543 const char * aMethod,
544 struct blob_attr * aMsg);
547 * This method handle ubus leave function request.
549 * @param[in] aContext A pointer to the ubus context.
550 * @param[in] aObj A pointer to the ubus object.
551 * @param[in] aRequest A pointer to the ubus request.
552 * @param[in] aMethod A pointer to the ubus method.
553 * @param[in] aMsg A pointer to the ubus message.
555 * @retval 0 Successfully handler the request.
558 static int UbusLeaveHandler(struct ubus_context * aContext,
559 struct ubus_object * aObj,
560 struct ubus_request_data *aRequest,
561 const char * aMethod,
562 struct blob_attr * aMsg);
565 * This method handle ubus get macfilter address function request.
567 * @param[in] aContext A pointer to the ubus context.
568 * @param[in] aObj A pointer to the ubus object.
569 * @param[in] aRequest A pointer to the ubus request.
570 * @param[in] aMethod A pointer to the ubus method.
571 * @param[in] aMsg A pointer to the ubus message.
573 * @retval 0 Successfully handler the request.
576 static int UbusMacfilterAddrHandler(struct ubus_context * aContext,
577 struct ubus_object * aObj,
578 struct ubus_request_data *aRequest,
579 const char * aMethod,
580 struct blob_attr * aMsg);
583 * This method handle ubus get macfilter state function request.
585 * @param[in] aContext A pointer to the ubus context.
586 * @param[in] aObj A pointer to the ubus object.
587 * @param[in] aRequest A pointer to the ubus request.
588 * @param[in] aMethod A pointer to the ubus method.
589 * @param[in] aMsg A pointer to the ubus message.
591 * @retval 0 Successfully handler the request.
594 static int UbusMacfilterStateHandler(struct ubus_context * aContext,
595 struct ubus_object * aObj,
596 struct ubus_request_data *aRequest,
597 const char * aMethod,
598 struct blob_attr * aMsg);
601 * This method handle ubus macfilter address add function request.
603 * @param[in] aContext A pointer to the ubus context.
604 * @param[in] aObj A pointer to the ubus object.
605 * @param[in] aRequest A pointer to the ubus request.
606 * @param[in] aMethod A pointer to the ubus method.
607 * @param[in] aMsg A pointer to the ubus message.
609 * @retval 0 Successfully handler the request.
612 static int UbusMacfilterAddHandler(struct ubus_context * aContext,
613 struct ubus_object * aObj,
614 struct ubus_request_data *aRequest,
615 const char * aMethod,
616 struct blob_attr * aMsg);
619 * This method handle ubus macfilter address clear function request.
621 * @param[in] aContext A pointer to the ubus context.
622 * @param[in] aObj A pointer to the ubus object.
623 * @param[in] aRequest A pointer to the ubus request.
624 * @param[in] aMethod A pointer to the ubus method.
625 * @param[in] aMsg A pointer to the ubus message.
627 * @retval 0 Successfully handler the request.
630 static int UbusMacfilterClearHandler(struct ubus_context * aContext,
631 struct ubus_object * aObj,
632 struct ubus_request_data *aRequest,
633 const char * aMethod,
634 struct blob_attr * aMsg);
637 * This method handle ubus macfilter address remove function request.
639 * @param[in] aContext A pointer to the ubus context.
640 * @param[in] aObj A pointer to the ubus object.
641 * @param[in] aRequest A pointer to the ubus request.
642 * @param[in] aMethod A pointer to the ubus method.
643 * @param[in] aMsg A pointer to the ubus message.
645 * @retval 0 Successfully handler the request.
648 static int UbusMacfilterRemoveHandler(struct ubus_context * aContext,
649 struct ubus_object * aObj,
650 struct ubus_request_data *aRequest,
651 const char * aMethod,
652 struct blob_attr * aMsg);
655 * This method handle ubus start commissioner function request.
657 * @param[in] aContext A pointer to the ubus context.
658 * @param[in] aObj A pointer to the ubus object.
659 * @param[in] aRequest A pointer to the ubus request.
660 * @param[in] aMethod A pointer to the ubus method.
661 * @param[in] aMsg A pointer to the ubus message.
663 * @retval 0 Successfully handler the request.
666 static int UbusCommissionerStartHandler(struct ubus_context * aContext,
667 struct ubus_object * aObj,
668 struct ubus_request_data *aRequest,
669 const char * aMethod,
670 struct blob_attr * aMsg);
673 * This method handle ubus add joiner function request.
675 * @param[in] aContext A pointer to the ubus context.
676 * @param[in] aObj A pointer to the ubus object.
677 * @param[in] aRequest A pointer to the ubus request.
678 * @param[in] aMethod A pointer to the ubus method.
679 * @param[in] aMsg A pointer to the ubus message.
681 * @retval 0 Successfully handler the request.
684 static int UbusJoinerAddHandler(struct ubus_context * aContext,
685 struct ubus_object * aObj,
686 struct ubus_request_data *aRequest,
687 const char * aMethod,
688 struct blob_attr * aMsg);
691 * This method handle ubus remove joiner function request.
693 * @param[in] aContext A pointer to the ubus context.
694 * @param[in] aObj A pointer to the ubus object.
695 * @param[in] aRequest A pointer to the ubus request.
696 * @param[in] aMethod A pointer to the ubus method.
697 * @param[in] aMsg A pointer to the ubus message.
699 * @retval 0 Successfully handler the request.
702 static int UbusJoinerRemoveHandler(struct ubus_context * aContext,
703 struct ubus_object * aObj,
704 struct ubus_request_data *aRequest,
705 const char * aMethod,
706 struct blob_attr * aMsg);
709 * This method handle ubus get joiner information function request.
711 * @param[in] aContext A pointer to the ubus context.
712 * @param[in] aObj A pointer to the ubus object.
713 * @param[in] aRequest A pointer to the ubus request.
714 * @param[in] aMethod A pointer to the ubus method.
715 * @param[in] aMsg A pointer to the ubus message.
717 * @retval 0 Successfully handler the request.
720 static int UbusJoinerNumHandler(struct ubus_context * aContext,
721 struct ubus_object * aObj,
722 struct ubus_request_data *aRequest,
723 const char * aMethod,
724 struct blob_attr * aMsg);
727 * This method handle ubus mgmtset function request.
729 * @param[in] aContext A pointer to the ubus context.
730 * @param[in] aObj A pointer to the ubus object.
731 * @param[in] aRequest A pointer to the ubus request.
732 * @param[in] aMethod A pointer to the ubus method.
733 * @param[in] aMsg A pointer to the ubus message.
735 * @retval 0 Successfully handler the request.
738 static int UbusMgmtsetHandler(struct ubus_context * aContext,
739 struct ubus_object * aObj,
740 struct ubus_request_data *aRequest,
741 const char * aMethod,
742 struct blob_attr * aMsg);
745 * This method handle initial diagnostic get response.
747 * @param[in] aError A error of receiving the diagnostic response.
748 * @param[in] aMessage A pointer to the message.
749 * @param[in] aMessageInfo A pointer to the message information.
750 * @param[in] aContext A pointer to the context.
753 static void HandleDiagnosticGetResponse(otError aError,
754 otMessage * aMessage,
755 const otMessageInfo *aMessageInfo,
759 * This method handle diagnosticget response.
761 * @param[in] aError A error of receiving the diagnostic response.
762 * @param[in] aMessage A pointer to the message.
763 * @param[in] aMessageInfo A pointer to the message information.
766 void HandleDiagnosticGetResponse(otError aError, otMessage *aMessage, const otMessageInfo *aMessageInfo);
770 struct ubus_context * mContext;
771 const char * mSockPath;
772 struct blob_buf mBuf;
773 struct blob_buf mNetworkdataBuf;
774 Ncp::ControllerOpenThread *mController;
778 kDefaultJoinerTimeout = 120,
784 * @param[in] aController The pointer to OpenThread Controller structure.
786 UbusServer(Ncp::ControllerOpenThread *aController);
789 * This method start scan.
792 void ProcessScan(void);
795 * This method detailly start scan.
797 * @param[in] aContext A pointer to the ubus context.
798 * @param[in] aObj A pointer to the ubus object.
799 * @param[in] aRequest A pointer to the ubus request.
800 * @param[in] aMethod A pointer to the ubus method.
801 * @param[in] aMsg A pointer to the ubus message.
803 * @retval 0 Successfully handler the request.
806 int UbusScanHandlerDetail(struct ubus_context * aContext,
807 struct ubus_object * aObj,
808 struct ubus_request_data *aRequest,
809 const char * aMethod,
810 struct blob_attr * aMsg);
813 * This method handle scan result (callback function).
815 * @param[in] aResult A pointer to result.
816 * @param[in] aContext A pointer to context.
819 static void HandleActiveScanResult(otActiveScanResult *aResult, void *aContext);
822 * This method detailly handler the scan result, called by HandleActiveScanResult.
824 * @param[in] aResult A pointer to result.
827 void HandleActiveScanResultDetail(otActiveScanResult *aResult);
830 * This method detailly handler get neighbor information.
832 * @param[in] aContext A pointer to the ubus context.
833 * @param[in] aObj A pointer to the ubus object.
834 * @param[in] aRequest A pointer to the ubus request.
835 * @param[in] aMethod A pointer to the ubus method.
836 * @param[in] aMsg A pointer to the ubus message.
838 * @retval 0 Successfully handler the request.
841 int UbusNeighborHandlerDetail(struct ubus_context * aContext,
842 struct ubus_object * aObj,
843 struct ubus_request_data *aRequest,
844 const char * aMethod,
845 struct blob_attr * aMsg);
848 * This method detailly handler get parent information.
850 * @param[in] aContext A pointer to the ubus context.
851 * @param[in] aObj A pointer to the ubus object.
852 * @param[in] aRequest A pointer to the ubus request.
853 * @param[in] aMethod A pointer to the ubus method.
854 * @param[in] aMsg A pointer to the ubus message.
856 * @retval 0 Successfully handler the request.
859 int UbusParentHandlerDetail(struct ubus_context * aContext,
860 struct ubus_object * aObj,
861 struct ubus_request_data *aRequest,
862 const char * aMethod,
863 struct blob_attr * aMsg);
866 * This method handle mgmtset request.
868 * @param[in] aContext A pointer to the ubus context.
869 * @param[in] aObj A pointer to the ubus object.
870 * @param[in] aRequest A pointer to the ubus request.
871 * @param[in] aMethod A pointer to the ubus method.
872 * @param[in] aMsg A pointer to the ubus message.
874 * @retval 0 Successfully handler the request.
877 int UbusMgmtset(struct ubus_context * aContext,
878 struct ubus_object * aObj,
879 struct ubus_request_data *aRequest,
880 const char * aMethod,
881 struct blob_attr * aMsg);
884 * This method handle leave request.
886 * @param[in] aContext A pointer to the ubus context.
887 * @param[in] aObj A pointer to the ubus object.
888 * @param[in] aRequest A pointer to the ubus request.
889 * @param[in] aMethod A pointer to the ubus method.
890 * @param[in] aMsg A pointer to the ubus message.
892 * @retval 0 Successfully handler the request.
895 int UbusLeaveHandlerDetail(struct ubus_context * aContext,
896 struct ubus_object * aObj,
897 struct ubus_request_data *aRequest,
898 const char * aMethod,
899 struct blob_attr * aMsg);
902 * This method handle thread related request.
904 * @param[in] aContext A pointer to the ubus context.
905 * @param[in] aObj A pointer to the ubus object.
906 * @param[in] aRequest A pointer to the ubus request.
907 * @param[in] aMethod A pointer to the ubus method.
908 * @param[in] aMsg A pointer to the ubus message.
909 * @param[in] aAction A pointer to the action needed.
911 * @retval 0 Successfully handler the request.
914 int UbusThreadHandler(struct ubus_context * aContext,
915 struct ubus_object * aObj,
916 struct ubus_request_data *aRequest,
917 const char * aMethod,
918 struct blob_attr * aMsg,
919 const char * aAction);
922 * This method handle get information request.
924 * @param[in] aContext A pointer to the ubus context.
925 * @param[in] aObj A pointer to the ubus object.
926 * @param[in] aRequest A pointer to the ubus request.
927 * @param[in] aMethod A pointer to the ubus method.
928 * @param[in] aMsg A pointer to the ubus message.
929 * @param[in] aAction A pointer to the action needed.
931 * @retval 0 Successfully handler the request.
934 int UbusGetInformation(struct ubus_context * aContext,
935 struct ubus_object * aObj,
936 struct ubus_request_data *aRequest,
937 const char * aMethod,
938 struct blob_attr * aMsg,
939 const char * action);
942 * This method handle set information request.
944 * @param[in] aContext A pointer to the ubus context.
945 * @param[in] aObj A pointer to the ubus object.
946 * @param[in] aRequest A pointer to the ubus request.
947 * @param[in] aMethod A pointer to the ubus method.
948 * @param[in] aMsg A pointer to the ubus message.
949 * @param[in] aAction A pointer to the action needed.
951 * @retval 0 Successfully handler the request.
954 int UbusSetInformation(struct ubus_context * aContext,
955 struct ubus_object * aObj,
956 struct ubus_request_data *aRequest,
957 const char * aMethod,
958 struct blob_attr * aMsg,
959 const char * aAction);
962 * This method handle conmmissioner related request.
964 * @param[in] aContext A pointer to the ubus context.
965 * @param[in] aObj A pointer to the ubus object.
966 * @param[in] aRequest A pointer to the ubus request.
967 * @param[in] aMethod A pointer to the ubus method.
968 * @param[in] aMsg A pointer to the ubus message.
969 * @param[in] aAction A pointer to the action needed.
971 * @retval 0 Successfully handler the request.
974 int UbusCommissioner(struct ubus_context * aContext,
975 struct ubus_object * aObj,
976 struct ubus_request_data *aRequest,
977 const char * aMethod,
978 struct blob_attr * aMsg,
979 const char * aAction);
982 * This method handle conmmissione state change (callback function).
984 * @param[in] aState The state of commissioner.
985 * @param[in] aContext A pointer to the ubus context.
988 static void HandleStateChanged(otCommissionerState aState, void *aContext);
991 * This method handle conmmissione state change.
993 * @param[in] aState The state of commissioner.
996 void HandleStateChanged(otCommissionerState aState);
999 * This method handle joiner event (callback function).
1001 * @param[in] aEvent The joiner event type.
1002 * @param[in] aJoinerInfo A pointer to the Joiner Info.
1003 * @param[in] aJoinerId A pointer to the Joiner ID (if not known, it will be NULL).
1004 * @param[in] aContext A pointer to application-specific context.
1007 static void HandleJoinerEvent(otCommissionerJoinerEvent aEvent,
1008 const otJoinerInfo * aJoinerInfo,
1009 const otExtAddress * aJoinerId,
1013 * This method handle joiner event.
1015 * @param[in] aEvent The joiner event type.
1016 * @param[in] aJoinerInfo A pointer to the Joiner Info.
1017 * @param[in] aJoinerId A pointer to the Joiner ID (if not known, it will be NULL).
1020 void HandleJoinerEvent(otCommissionerJoinerEvent aEvent,
1021 const otJoinerInfo * aJoinerInfo,
1022 const otExtAddress * aJoinerId);
1025 * This method convert thread network state to string.
1027 * @param[in] aInstance A pointer to the instance.
1028 * @param[out] aState A pointer to the string address.
1031 void GetState(otInstance *aInstance, char *aState);
1034 * This method add fd of ubus object.
1037 void UbusAddFd(void);
1040 * This method set ubus reconnect time.
1042 * @param[in] aTimeout A pointer to the timeout.
1045 static void UbusReconnTimer(struct uloop_timeout *aTimeout);
1048 * This method detailly handle ubus reconnect time.
1050 * @param[in] aTimeout A pointer to the timeout.
1053 void UbusReconnTimerDetail(struct uloop_timeout *aTimeout);
1056 * This method handle ubus connection lost.
1058 * @param[in] aContext A pointer to the context.
1061 static void UbusConnectionLost(struct ubus_context *aContext);
1064 * This method connect and display ubus.
1066 * @param[in] aPath A pointer to the ubus server path(default is nullptr).
1068 * @retval 0 Successfully handler the request.
1071 int DisplayUbusInit(const char *aPath);
1074 * This method disconnect and display ubus.
1077 void DisplayUbusDone(void);
1080 * This method parses an ASCII string as a long.
1082 * @param[in] aString A pointer to the ASCII string.
1083 * @param[out] aLong A reference to where the parsed long is placed.
1085 * @retval OT_ERROR_NONE Successfully parsed the ASCII string.
1086 * @retval OT_ERROR_PARSE Could not parse the ASCII string.
1089 otError ParseLong(char *aString, long &aLong);
1092 * This method converts a hex string to binary.
1094 * @param[in] aHex A pointer to the hex string.
1095 * @param[out] aBin A pointer to where the binary representation is placed.
1096 * @param[in] aBinLength Maximum length of the binary representation.
1098 * @returns The number of bytes in the binary representation.
1100 int Hex2Bin(const char *aHex, uint8_t *aBin, uint16_t aBinLength);
1103 * This method output bytes into char*.
1105 * @param[in] aBytes A pointer to the bytes need to be convert.
1106 * @param[in] aLength The length of the bytes.
1107 * @param[out] aOutput A pointer to the char* string.
1110 void OutputBytes(const uint8_t *aBytes, uint8_t aLength, char *aOutput);
1113 * This method append result in message passed to ubus.
1115 * @param[in] aError The error type of the message.
1116 * @param[in] aContext A pointer to the context.
1117 * @param[in] aRequest A pointer to the request.
1120 void AppendResult(otError aError, struct ubus_context *aContext, struct ubus_request_data *aRequest);
1125 #endif // OTBR_AGENT_OTUBUS_HPP_