Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / OpenThread / GenericThreadStackManagerImpl_OpenThread_LwIP.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2019 Nest Labs, Inc.
5  *    All rights reserved.
6  *
7  *    Licensed under the Apache License, Version 2.0 (the "License");
8  *    you may not use this file except in compliance with the License.
9  *    You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *    Unless required by applicable law or agreed to in writing, software
14  *    distributed under the License is distributed on an "AS IS" BASIS,
15  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *    See the License for the specific language governing permissions and
17  *    limitations under the License.
18  */
19
20 /**
21  *    @file
22  *          Provides a generic implementation of ThreadStackManager features
23  *          for use on platforms that use OpenThread with LwIP.
24  */
25
26 #pragma once
27
28 #include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
29
30 #include <lwip/netif.h>
31 #include <lwip/tcpip.h>
32
33 #include <openthread/message.h>
34
35 namespace chip {
36 namespace DeviceLayer {
37
38 class ThreadStackManagerImpl;
39
40 namespace Internal {
41
42 /**
43  * Provides a generic implementation of ThreadStackManager features that works in conjunction
44  * with OpenThread and LwIP.
45  *
46  * This template contains implementations of select features from the ThreadStackManager abstract
47  * interface that are suitable for use on devices that employ OpenThread and LwIP together.  It is
48  * intended to be inherited, directly or indirectly, by the ThreadStackManagerImpl class, which
49  * also appears as the template's ImplClass parameter.
50  */
51 template <class ImplClass>
52 class GenericThreadStackManagerImpl_OpenThread_LwIP : public GenericThreadStackManagerImpl_OpenThread<ImplClass>
53 {
54 public:
55     // ===== Platform-specific methods directly callable by the application.
56
57     struct netif * ThreadNetIf() const;
58
59 protected:
60     // ===== Methods that implement the ThreadStackManager abstract interface.
61
62     void _OnPlatformEvent(const ChipDeviceEvent * event);
63
64     // ===== Members available to the implementation subclass.
65
66     CHIP_ERROR DoInit(otInstance * otInst);
67     void UpdateThreadInterface(bool addrChange);
68
69 private:
70     // ===== Private members for use by this class only.
71
72     struct netif * mNetIf;
73     bool mAddrAssigned[LWIP_IPV6_NUM_ADDRESSES];
74
75     static err_t DoInitThreadNetIf(struct netif * netif);
76 #if LWIP_VERSION_MAJOR < 2
77     static err_t SendPacket(struct netif * netif, struct pbuf * pkt, struct ip6_addr * ipaddr);
78 #else
79     static err_t SendPacket(struct netif * netif, struct pbuf * pkt, const struct ip6_addr * ipaddr);
80 #endif
81     static void ReceivePacket(otMessage * pkt, void * context);
82
83     inline ImplClass * Impl() { return static_cast<ImplClass *>(this); }
84 };
85
86 // Instruct the compiler to instantiate the template only when explicitly told to do so.
87 extern template class GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>;
88
89 template <class ImplClass>
90 inline struct netif * GenericThreadStackManagerImpl_OpenThread_LwIP<ImplClass>::ThreadNetIf() const
91 {
92     return mNetIf;
93 }
94
95 } // namespace Internal
96 } // namespace DeviceLayer
97 } // namespace chip