1 /*
2 * Copyright (c) 2020, 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 #include "posix/platform/radio_url.hpp"
30
31 #include <stdio.h>
32
33 #include <openthread/openthread-system.h>
34
35 #include "common/code_utils.hpp"
36 #include "posix/platform/platform-posix.h"
37
otSysGetRadioUrlHelpString(void)38 const char *otSysGetRadioUrlHelpString(void)
39 {
40 #define OT_RADIO_URL_HELP_BUS \
41 "Radio Url format:" \
42 " {Protocol}://${PATH_TO_DEVICE}?${Parameters}\n" \
43 "\n"
44
45 #if OPENTHREAD_POSIX_CONFIG_SPINEL_SPI_INTERFACE_ENABLE
46 #define OT_SPINEL_SPI_RADIO_URL_HELP_BUS \
47 "Protocol=[spinel+spi*] Specify the Spinel interface as the Spinel SPI interface\n" \
48 " spinel+spi://${PATH_TO_SPI_DEVICE}?${Parameters}\n" \
49 "Parameters:\n" \
50 " gpio-int-device[=gpio-device-path]\n" \
51 " Specify a path to the Linux sysfs-exported GPIO device for the\n" \
52 " `I̅N̅T̅` pin.\n" \
53 " gpio-int-line[=line-offset]\n" \
54 " The offset index of `I̅N̅T̅` pin for the associated GPIO device.\n" \
55 " gpio-reset-device[=gpio-device-path]\n" \
56 " Specify a path to the Linux sysfs-exported GPIO device for the\n" \
57 " `R̅E̅S̅` pin. If not specified, the process will direct exist when an\n" \
58 " RCP reset is required.\n" \
59 " gpio-reset-line[=line-offset]\n" \
60 " The offset index of `R̅E̅S̅` pin for the associated GPIO device. This\n" \
61 " is required if `gpio-reset-device` is specified.\n" \
62 " spi-mode[=mode] Specify the SPI mode to use (0-3).\n" \
63 " spi-speed[=hertz] Specify the SPI speed in hertz.\n" \
64 " spi-cs-delay[=usec] Specify the delay after C̅S̅ assertion, in µsec.\n" \
65 " spi-reset-delay[=ms] Specify the delay after R̅E̅S̅E̅T̅ assertion, in milliseconds.\n" \
66 " spi-align-allowance[=n] Specify the maximum number of 0xFF bytes to clip from start of\n" \
67 " MISO frame. Max value is 16.\n" \
68 " spi-small-packet=[n] Specify the smallest packet we can receive in a single transaction.\n" \
69 " (larger packets will require two transactions). Default value is 32.\n" \
70 "\n"
71 #else
72 #define OT_SPINEL_SPI_RADIO_URL_HELP_BUS
73 #endif // OPENTHREAD_POSIX_CONFIG_SPINEL_SPI_INTERFACE_ENABLE
74
75 #if OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE
76 #define OT_SPINEL_HDLC_RADIO_URL_HELP_BUS \
77 "Protocol=[spinel+hdlc*] Specify the Spinel interface as the Spinel HDLC interface\n" \
78 " forkpty-arg[=argument string] Command line arguments for subprocess, can be repeated.\n" \
79 " spinel+hdlc+uart://${PATH_TO_UART_DEVICE}?${Parameters} for real uart device\n" \
80 " spinel+hdlc+forkpty://${PATH_TO_UART_DEVICE}?${Parameters} for forking a pty subprocess.\n" \
81 "Parameters:\n" \
82 " uart-parity[=even|odd] Uart parity config, optional.\n" \
83 " uart-stop[=number-of-bits] Uart stop bit, default is 1.\n" \
84 " uart-baudrate[=baudrate] Uart baud rate, default is 115200.\n" \
85 " uart-flow-control Enable flow control, disabled by default.\n" \
86 " uart-init-deassert Deassert lines on init when flow control is disabled.\n" \
87 " uart-reset Reset connection after hard resetting RCP(USB CDC ACM).\n" \
88 "\n"
89 #else
90 #define OT_SPINEL_HDLC_RADIO_URL_HELP_BUS
91 #endif // OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE
92
93 #if OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_ENABLE
94
95 #ifndef OT_VENDOR_RADIO_URL_HELP_BUS
96 #define OT_VENDOR_RADIO_URL_HELP_BUS "\n"
97 #endif // OT_VENDOR_RADIO_URL_HELP_BUS
98
99 #define OT_SPINEL_VENDOR_RADIO_URL_HELP_BUS OT_VENDOR_RADIO_URL_HELP_BUS
100 #else
101 #define OT_SPINEL_VENDOR_RADIO_URL_HELP_BUS
102 #endif // OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_ENABLE
103
104 #if OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE
105 #define OT_RADIO_URL_HELP_MAX_POWER_TABLE \
106 " max-power-table Max power for channels in ascending order separated by commas,\n" \
107 " If the number of values is less than that of supported channels,\n" \
108 " the last value will be applied to all remaining channels.\n" \
109 " Special value 0x7f disables a channel.\n"
110 #else
111 #define OT_RADIO_URL_HELP_MAX_POWER_TABLE
112 #endif
113
114 return "RadioURL:\n" OT_RADIO_URL_HELP_BUS OT_SPINEL_SPI_RADIO_URL_HELP_BUS OT_SPINEL_HDLC_RADIO_URL_HELP_BUS
115 OT_SPINEL_VENDOR_RADIO_URL_HELP_BUS OT_RADIO_URL_HELP_MAX_POWER_TABLE
116 " region[=region-code] Set the radio's region code. The region code must be an\n"
117 " ISO 3166 alpha-2 code.\n"
118 " cca-threshold[=dbm] Set the radio's CCA ED threshold in dBm measured at antenna connector.\n"
119 " enable-coex[=1|0] If not specified, RCP coex operates with its default configuration.\n"
120 " Disable coex with 0, and enable it with other values.\n"
121 " fem-lnagain[=dbm] Set the Rx LNA gain in dBm of the external FEM.\n"
122 " no-reset Do not send Spinel reset command to RCP on initialization.\n"
123 " skip-rcp-compatibility-check Skip checking RCP API version and capabilities during initialization.\n"
124 " bus-latency[=usec] Communication latency in usec, default is 0.\n"
125 #if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
126 " iid Set the Spinel Interface ID for this process. Valid values are 0-3.\n"
127 " iid-list List of IIDs a host can subscribe to receive spinel frames other than \n"
128 " provided in 'iid' argument. If not specified, host will subscribe to \n"
129 " the interface ID provided in 'iid` argument. Valid values are 0-3. \n"
130 " Upto three IIDs can be provided with each IID separated by ',' \n"
131 " e.g. iid-list=1,2,3 \n"
132 #endif
133 ;
134 }
135
136 namespace ot {
137 namespace Posix {
138
Init(const char * aUrl)139 void RadioUrl::Init(const char *aUrl)
140 {
141 if (aUrl != nullptr)
142 {
143 VerifyOrDie(strnlen(aUrl, sizeof(mUrl)) < sizeof(mUrl), OT_EXIT_INVALID_ARGUMENTS);
144 strncpy(mUrl, aUrl, sizeof(mUrl) - 1);
145 SuccessOrDie(Url::Url::Init(mUrl));
146 }
147 }
148
149 } // namespace Posix
150 } // namespace ot
151