3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2015-2017 Nest Labs, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file contains the basis class for all the various transport
22 * endpoint classes in the Inet layer, i.e. TCP, UDP, Raw and Tun.
27 #include <inet/InetConfig.h>
29 #include "inet/IANAConstants.h"
30 #include "inet/InetLayerBasis.h"
31 #include <inet/InetError.h>
32 #include <inet/InetInterface.h>
33 #include <inet/InetLayerEvents.h>
35 #include <support/DLLUtil.h>
37 #if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
38 #include <Network/Network.h>
39 #endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
41 //--- Declaration of LWIP protocol control buffer structure names
42 #if CHIP_SYSTEM_CONFIG_USE_LWIP
43 #if INET_CONFIG_ENABLE_RAW_ENDPOINT
45 #endif // INET_CONFIG_ENABLE_RAW_ENDPOINT
46 #if INET_CONFIG_ENABLE_UDP_ENDPOINT
48 #endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
49 #if INET_CONFIG_ENABLE_TCP_ENDPOINT
51 #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
52 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP
58 * @class EndPointBasis
60 * @brief Basis of internet transport endpoint classes
62 class DLL_EXPORT EndPointBasis : public InetLayerBasis
65 /** Common state codes */
68 kBasisState_Closed = 0 /**< Encapsulated descriptor is not valid. */
71 #if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
72 /** Test whether endpoint is a Network.framework endpoint */
73 bool IsNetworkFrameworkEndPoint(void) const;
76 #if CHIP_SYSTEM_CONFIG_USE_SOCKETS
77 /** Test whether endpoint is a POSIX socket */
78 bool IsSocketsEndPoint() const;
81 #if CHIP_SYSTEM_CONFIG_USE_LWIP
82 /** Test whether endpoint is a LwIP protocol control buffer */
83 bool IsLWIPEndPoint(void) const;
86 /** Test whether endpoint has a valid descriptor. */
87 bool IsOpenEndPoint() const;
90 #if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
91 nw_parameters_t mParameters;
92 IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
95 #if CHIP_SYSTEM_CONFIG_USE_SOCKETS
96 int mSocket; /**< Encapsulated socket descriptor. */
97 IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
98 SocketEvents mPendingIO; /**< Socket event masks */
99 #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS
101 #if CHIP_SYSTEM_CONFIG_USE_LWIP
102 /** Encapsulated LwIP protocol control block */
105 const void * mVoid; /**< An untyped protocol control buffer reference */
106 #if INET_CONFIG_ENABLE_RAW_ENDPOINT
107 raw_pcb * mRaw; /**< Raw network interface protocol control */
108 #endif // INET_CONFIG_ENABLE_RAW_ENDPOINT
109 #if INET_CONFIG_ENABLE_UDP_ENDPOINT
110 udp_pcb * mUDP; /**< User datagram protocol (UDP) control */
111 #endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
112 #if INET_CONFIG_ENABLE_TCP_ENDPOINT
113 tcp_pcb * mTCP; /**< Transmission control protocol (TCP) control */
114 #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
119 kLwIPEndPointType_Unknown = 0,
121 kLwIPEndPointType_Raw = 1,
122 kLwIPEndPointType_UDP = 2,
123 kLwIPEndPointType_UCP = 3,
124 kLwIPEndPointType_TCP = 4
127 uint8_t mLwIPEndPointType;
129 void DeferredFree(chip::System::Object::ReleaseDeferralErrorTactic aTactic);
130 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP
132 void InitEndPointBasis(InetLayer & aInetLayer, void * aAppState = nullptr);
135 #if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
136 inline bool EndPointBasis::IsNetworkFrameworkEndPoint(void) const
138 return mParameters != NULL;
140 #endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
142 #if CHIP_SYSTEM_CONFIG_USE_SOCKETS
143 inline bool EndPointBasis::IsSocketsEndPoint() const
147 #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS
149 #if CHIP_SYSTEM_CONFIG_USE_LWIP
150 inline bool EndPointBasis::IsLWIPEndPoint(void) const
152 return mVoid != NULL;
154 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP
156 inline bool EndPointBasis::IsOpenEndPoint() const
158 bool lResult = false;
160 #if CHIP_SYSTEM_CONFIG_USE_LWIP
161 lResult = (lResult || IsLWIPEndPoint());
162 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP
164 #if CHIP_SYSTEM_CONFIG_USE_SOCKETS
165 lResult = (lResult || IsSocketsEndPoint());
166 #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS
168 #if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
169 lResult = (lResult || IsNetworkFrameworkEndPoint());
170 #endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
175 #if CHIP_SYSTEM_CONFIG_USE_LWIP
176 inline void EndPointBasis::DeferredFree(chip::System::Object::ReleaseDeferralErrorTactic aTactic)
178 if (!CHIP_SYSTEM_CONFIG_USE_SOCKETS || IsLWIPEndPoint())
180 DeferredRelease(aTactic);
187 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP