1*cfb92d14SAndroid Build Coastguard Worker /* 2*cfb92d14SAndroid Build Coastguard Worker * Copyright (c) 2021, The OpenThread Authors. 3*cfb92d14SAndroid Build Coastguard Worker * All rights reserved. 4*cfb92d14SAndroid Build Coastguard Worker * 5*cfb92d14SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 6*cfb92d14SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met: 7*cfb92d14SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 8*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 9*cfb92d14SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 10*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 11*cfb92d14SAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 12*cfb92d14SAndroid Build Coastguard Worker * 3. Neither the name of the copyright holder nor the 13*cfb92d14SAndroid Build Coastguard Worker * names of its contributors may be used to endorse or promote products 14*cfb92d14SAndroid Build Coastguard Worker * derived from this software without specific prior written permission. 15*cfb92d14SAndroid Build Coastguard Worker * 16*cfb92d14SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17*cfb92d14SAndroid Build Coastguard Worker * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*cfb92d14SAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*cfb92d14SAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20*cfb92d14SAndroid Build Coastguard Worker * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21*cfb92d14SAndroid Build Coastguard Worker * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22*cfb92d14SAndroid Build Coastguard Worker * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23*cfb92d14SAndroid Build Coastguard Worker * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24*cfb92d14SAndroid Build Coastguard Worker * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25*cfb92d14SAndroid Build Coastguard Worker * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26*cfb92d14SAndroid Build Coastguard Worker * POSSIBILITY OF SUCH DAMAGE. 27*cfb92d14SAndroid Build Coastguard Worker */ 28*cfb92d14SAndroid Build Coastguard Worker 29*cfb92d14SAndroid Build Coastguard Worker #ifndef OT_POSIX_PLATFORM_RADIO_HPP_ 30*cfb92d14SAndroid Build Coastguard Worker #define OT_POSIX_PLATFORM_RADIO_HPP_ 31*cfb92d14SAndroid Build Coastguard Worker 32*cfb92d14SAndroid Build Coastguard Worker #include "hdlc_interface.hpp" 33*cfb92d14SAndroid Build Coastguard Worker #include "logger.hpp" 34*cfb92d14SAndroid Build Coastguard Worker #include "radio_url.hpp" 35*cfb92d14SAndroid Build Coastguard Worker #include "rcp_caps_diag.hpp" 36*cfb92d14SAndroid Build Coastguard Worker #include "spi_interface.hpp" 37*cfb92d14SAndroid Build Coastguard Worker #include "spinel_manager.hpp" 38*cfb92d14SAndroid Build Coastguard Worker #include "vendor_interface.hpp" 39*cfb92d14SAndroid Build Coastguard Worker #include "common/code_utils.hpp" 40*cfb92d14SAndroid Build Coastguard Worker #include "lib/spinel/radio_spinel.hpp" 41*cfb92d14SAndroid Build Coastguard Worker #include "lib/spinel/spinel_driver.hpp" 42*cfb92d14SAndroid Build Coastguard Worker #if OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE 43*cfb92d14SAndroid Build Coastguard Worker #ifdef OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_HEADER 44*cfb92d14SAndroid Build Coastguard Worker #include OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_HEADER 45*cfb92d14SAndroid Build Coastguard Worker #endif 46*cfb92d14SAndroid Build Coastguard Worker #endif 47*cfb92d14SAndroid Build Coastguard Worker 48*cfb92d14SAndroid Build Coastguard Worker namespace ot { 49*cfb92d14SAndroid Build Coastguard Worker namespace Posix { 50*cfb92d14SAndroid Build Coastguard Worker 51*cfb92d14SAndroid Build Coastguard Worker /** 52*cfb92d14SAndroid Build Coastguard Worker * Manages Thread radio. 53*cfb92d14SAndroid Build Coastguard Worker * 54*cfb92d14SAndroid Build Coastguard Worker */ 55*cfb92d14SAndroid Build Coastguard Worker class Radio : public Logger<Radio> 56*cfb92d14SAndroid Build Coastguard Worker { 57*cfb92d14SAndroid Build Coastguard Worker public: 58*cfb92d14SAndroid Build Coastguard Worker static const char kLogModuleName[]; ///< Module name used for logging. 59*cfb92d14SAndroid Build Coastguard Worker 60*cfb92d14SAndroid Build Coastguard Worker /** 61*cfb92d14SAndroid Build Coastguard Worker * Creates the radio manager. 62*cfb92d14SAndroid Build Coastguard Worker * 63*cfb92d14SAndroid Build Coastguard Worker */ 64*cfb92d14SAndroid Build Coastguard Worker Radio(void); 65*cfb92d14SAndroid Build Coastguard Worker 66*cfb92d14SAndroid Build Coastguard Worker /** 67*cfb92d14SAndroid Build Coastguard Worker * Initialize the Thread radio. 68*cfb92d14SAndroid Build Coastguard Worker * 69*cfb92d14SAndroid Build Coastguard Worker * @param[in] aUrl A pointer to the null-terminated URL. 70*cfb92d14SAndroid Build Coastguard Worker * 71*cfb92d14SAndroid Build Coastguard Worker */ 72*cfb92d14SAndroid Build Coastguard Worker void Init(const char *aUrl); 73*cfb92d14SAndroid Build Coastguard Worker 74*cfb92d14SAndroid Build Coastguard Worker /** 75*cfb92d14SAndroid Build Coastguard Worker * Acts as an accessor to the spinel interface instance used by the radio. 76*cfb92d14SAndroid Build Coastguard Worker * 77*cfb92d14SAndroid Build Coastguard Worker * @returns A reference to the radio's spinel interface instance. 78*cfb92d14SAndroid Build Coastguard Worker * 79*cfb92d14SAndroid Build Coastguard Worker */ GetSpinelInterface(void)80*cfb92d14SAndroid Build Coastguard Worker Spinel::SpinelInterface &GetSpinelInterface(void) { return SpinelManager::GetSpinelManager().GetSpinelInterface(); } 81*cfb92d14SAndroid Build Coastguard Worker 82*cfb92d14SAndroid Build Coastguard Worker /** 83*cfb92d14SAndroid Build Coastguard Worker * Acts as an accessor to the radio spinel instance used by the radio. 84*cfb92d14SAndroid Build Coastguard Worker * 85*cfb92d14SAndroid Build Coastguard Worker * @returns A reference to the radio spinel instance. 86*cfb92d14SAndroid Build Coastguard Worker * 87*cfb92d14SAndroid Build Coastguard Worker */ GetRadioSpinel(void)88*cfb92d14SAndroid Build Coastguard Worker Spinel::RadioSpinel &GetRadioSpinel(void) { return mRadioSpinel; } 89*cfb92d14SAndroid Build Coastguard Worker 90*cfb92d14SAndroid Build Coastguard Worker /** 91*cfb92d14SAndroid Build Coastguard Worker * Acts as an accessor to the RCP capability diagnostic instance used by the radio. 92*cfb92d14SAndroid Build Coastguard Worker * 93*cfb92d14SAndroid Build Coastguard Worker * @returns A reference to the RCP capability diagnostic instance. 94*cfb92d14SAndroid Build Coastguard Worker * 95*cfb92d14SAndroid Build Coastguard Worker */ 96*cfb92d14SAndroid Build Coastguard Worker #if OPENTHREAD_POSIX_CONFIG_RCP_CAPS_DIAG_ENABLE GetRcpCapsDiag(void)97*cfb92d14SAndroid Build Coastguard Worker RcpCapsDiag &GetRcpCapsDiag(void) { return mRcpCapsDiag; } 98*cfb92d14SAndroid Build Coastguard Worker #endif 99*cfb92d14SAndroid Build Coastguard Worker 100*cfb92d14SAndroid Build Coastguard Worker private: 101*cfb92d14SAndroid Build Coastguard Worker void ProcessRadioUrl(const RadioUrl &aRadioUrl); 102*cfb92d14SAndroid Build Coastguard Worker void ProcessMaxPowerTable(const RadioUrl &aRadioUrl); 103*cfb92d14SAndroid Build Coastguard Worker 104*cfb92d14SAndroid Build Coastguard Worker #if OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE && OPENTHREAD_POSIX_CONFIG_SPINEL_SPI_INTERFACE_ENABLE 105*cfb92d14SAndroid Build Coastguard Worker static constexpr size_t kSpinelInterfaceRawSize = sizeof(ot::Posix::SpiInterface) > sizeof(ot::Posix::HdlcInterface) 106*cfb92d14SAndroid Build Coastguard Worker ? sizeof(ot::Posix::SpiInterface) 107*cfb92d14SAndroid Build Coastguard Worker : sizeof(ot::Posix::HdlcInterface); 108*cfb92d14SAndroid Build Coastguard Worker #elif OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE 109*cfb92d14SAndroid Build Coastguard Worker static constexpr size_t kSpinelInterfaceRawSize = sizeof(ot::Posix::HdlcInterface); 110*cfb92d14SAndroid Build Coastguard Worker #elif OPENTHREAD_POSIX_CONFIG_SPINEL_SPI_INTERFACE_ENABLE 111*cfb92d14SAndroid Build Coastguard Worker static constexpr size_t kSpinelInterfaceRawSize = sizeof(ot::Posix::SpiInterface); 112*cfb92d14SAndroid Build Coastguard Worker #elif OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_ENABLE 113*cfb92d14SAndroid Build Coastguard Worker static constexpr size_t kSpinelInterfaceRawSize = sizeof(ot::Posix::VendorInterface); 114*cfb92d14SAndroid Build Coastguard Worker #else 115*cfb92d14SAndroid Build Coastguard Worker #error "No Spinel interface is specified!" 116*cfb92d14SAndroid Build Coastguard Worker #endif 117*cfb92d14SAndroid Build Coastguard Worker 118*cfb92d14SAndroid Build Coastguard Worker static constexpr otRadioCaps kRequiredRadioCaps = 119*cfb92d14SAndroid Build Coastguard Worker #if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2 120*cfb92d14SAndroid Build Coastguard Worker OT_RADIO_CAPS_TRANSMIT_SEC | OT_RADIO_CAPS_TRANSMIT_TIMING | 121*cfb92d14SAndroid Build Coastguard Worker #endif 122*cfb92d14SAndroid Build Coastguard Worker OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_TRANSMIT_RETRIES | OT_RADIO_CAPS_CSMA_BACKOFF; 123*cfb92d14SAndroid Build Coastguard Worker 124*cfb92d14SAndroid Build Coastguard Worker RadioUrl mRadioUrl; 125*cfb92d14SAndroid Build Coastguard Worker #if OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE 126*cfb92d14SAndroid Build Coastguard Worker Spinel::VendorRadioSpinel mRadioSpinel; 127*cfb92d14SAndroid Build Coastguard Worker #else 128*cfb92d14SAndroid Build Coastguard Worker Spinel::RadioSpinel mRadioSpinel; 129*cfb92d14SAndroid Build Coastguard Worker #endif 130*cfb92d14SAndroid Build Coastguard Worker 131*cfb92d14SAndroid Build Coastguard Worker #if OPENTHREAD_POSIX_CONFIG_RCP_CAPS_DIAG_ENABLE 132*cfb92d14SAndroid Build Coastguard Worker RcpCapsDiag mRcpCapsDiag; 133*cfb92d14SAndroid Build Coastguard Worker #endif 134*cfb92d14SAndroid Build Coastguard Worker }; 135*cfb92d14SAndroid Build Coastguard Worker 136*cfb92d14SAndroid Build Coastguard Worker } // namespace Posix 137*cfb92d14SAndroid Build Coastguard Worker } // namespace ot 138*cfb92d14SAndroid Build Coastguard Worker 139*cfb92d14SAndroid Build Coastguard Worker #endif // OT_POSIX_PLATFORM_RADIO_HPP_ 140