• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2021, 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 /**
30  * @file
31  *   This file includes definitions for TCP/IPv6 sockets.
32  */
33 
34 #ifndef TCP6_HPP_
35 #define TCP6_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <openthread/tcp.h>
40 
41 #include "common/as_core_type.hpp"
42 #include "common/clearable.hpp"
43 #include "common/linked_list.hpp"
44 #include "common/locator.hpp"
45 #include "common/non_copyable.hpp"
46 #include "common/timer.hpp"
47 #include "net/ip6_headers.hpp"
48 #include "net/socket.hpp"
49 
50 /*
51  * These structures and functions are forward-declared here to avoid
52  * #includ'ing third_party/tcplp/tcplp.h in this header file.
53  */
54 extern "C" {
55 struct tcpcb;
56 struct tcpcb_listen;
57 struct tcplp_signals;
58 void tcplp_sys_set_timer(struct tcpcb *aTcb, uint8_t aTimerFlag, uint32_t aDelay);
59 void tcplp_sys_stop_timer(struct tcpcb *aTcb, uint8_t aTimerFlag);
60 }
61 
62 namespace ot {
63 namespace Ip6 {
64 
65 /**
66  * @addtogroup core-tcp
67  *
68  * @brief
69  *   This module includes definitions for TCP/IPv6 sockets.
70  *
71  * @{
72  *
73  */
74 
75 /**
76  * This class implements TCP message handling.
77  *
78  */
79 class Tcp : public InstanceLocator, private NonCopyable
80 {
81 public:
82     /**
83      * This class represents an endpoint of a TCP/IPv6 connection.
84      *
85      */
86     class Endpoint : public otTcpEndpoint, public LinkedListEntry<Endpoint>, public GetProvider<Endpoint>
87     {
88         friend class Tcp;
89         friend class LinkedList<Endpoint>;
90 
91     public:
92         /**
93          * Initializes a TCP endpoint.
94          *
95          * Calling this function causes OpenThread to keep track of this Endpoint
96          * and store and retrieve TCP data inside of it. The application
97          * should refrain from directly accessing or modifying the fields in
98          * this Endpoint. If the application needs to reclaim the memory backing
99          * this Endpoint, it should call otTcpEndpointDeinitialize().
100          *
101          * @sa otTcpEndpointInitialize in include/openthread/tcp.h.
102          *
103          * @param[in]  aInstance  A pointer to an OpenThread instance.
104          * @param[in]  aArgs      A pointer to a structure of arguments.
105          *
106          * @retval kErrorNone    Successfully opened the TCP endpoint.
107          * @retval kErrorFailed  Failed to open the TCP endpoint.
108          *
109          */
110         Error Initialize(Instance &aInstance, const otTcpEndpointInitializeArgs &aArgs);
111 
112         /**
113          * Obtains the Instance that was associated with this Endpoint upon
114          * initialization.
115          *
116          * @sa otTcpEndpointGetInstance
117          *
118          * @returns  The Instance pointer associated with this Endpoint.
119          *
120          */
121         Instance &GetInstance(void) const;
122 
123         /**
124          * Obtains the context pointer that was associated this Endpoint upon
125          * initialization.
126          *
127          * @sa otTcpEndpointGetContext
128          *
129          * @returns  The context pointer associated with this Endpoint.
130          *
131          */
GetContext(void)132         void *GetContext(void) { return mContext; }
133 
134         /**
135          * Obtains a pointer to a TCP endpoint's local host and port.
136          *
137          * The contents of the host and port may be stale if this socket is not in a
138          * connected state and has not been bound after it was last disconnected.
139          *
140          * @sa otTcpGetLocalAddress
141          *
142          * @returns  The local host and port of this Endpoint.
143          *
144          */
145         const SockAddr &GetLocalAddress(void) const;
146 
147         /**
148          * Obtains a pointer to a TCP endpoint's peer's host and port.
149          *
150          * The contents of the host and port may be stale if this socket is not in a
151          * connected state.
152          *
153          * @sa otTcpGetPeerAddress
154          *
155          * @returns  The host and port of the connection peer of this Endpoint.
156          *
157          */
158         const SockAddr &GetPeerAddress(void) const;
159 
160         /**
161          * Binds the TCP endpoint to an IP address and port.
162          *
163          * @sa otTcpBind
164          *
165          * @param[in]  aSockName   The address and port to which to bind this TCP endpoint.
166          *
167          * @retval kErrorNone    Successfully bound the TCP endpoint.
168          * @retval kErrorFailed  Failed to bind the TCP endpoint.
169          *
170          */
171         Error Bind(const SockAddr &aSockName);
172 
173         /**
174          * Records the remote host and port for this connection.
175          *
176          * By default TCP Fast Open is used. This means that this function merely
177          * records the remote host and port, and that the TCP connection establishment
178          * handshake only happens on the first call to otTcpSendByReference(). TCP Fast
179          * Open can be explicitly disabled using @p aFlags, in which case the TCP
180          * connection establishment handshake is initiated immediately.
181          *
182          * @sa otTcpConnect
183          *
184          * @param[in]  aSockName  The IP address and port of the host to which to connect.
185          * @param[in]  aFlags     Flags specifying options for this operation (see enumeration above).
186          *
187          * @retval kErrorNone    Successfully completed the operation.
188          * @retval kErrorFailed  Failed to complete the operation.
189          *
190          */
191         Error Connect(const SockAddr &aSockName, uint32_t aFlags);
192 
193         /**
194          * Adds data referenced by the linked buffer pointed to by @p aBuffer to the
195          * send buffer.
196          *
197          * Upon a successful call to this function, the linked buffer and data it
198          * references are owned by the TCP stack; they should not be modified by the
199          * application until a "send done" callback returns ownership of those objects
200          * to the application. It is acceptable to call this function to add another
201          * linked buffer to the send queue, even if the "send done" callback for a
202          * previous invocation of this function has not yet fired.
203          *
204          * Note that @p aBuffer should not be chained; its mNext field should be
205          * NULL. If additional data will be added right after this call, then the
206          * OT_TCP_SEND_MORE_TO_COME flag should be used as a hint to the TCP
207          * implementation.
208          *
209          * @sa otTcpSendByReference
210          *
211          * @param[in]  aBuffer    A pointer to the linked buffer chain referencing data to add to the send buffer.
212          * @param[in]  aFlags     Flags specifying options for this operation (see enumeration above).
213          *
214          * @retval kErrorNone    Successfully added data to the send buffer.
215          * @retval kErrorFailed  Failed to add data to the send buffer.
216          *
217          */
218         Error SendByReference(otLinkedBuffer &aBuffer, uint32_t aFlags);
219 
220         /**
221          * Adds data to the send buffer by extending the length of the final
222          * otLinkedBuffer in the send buffer by the specified amount.
223          *
224          * If the send buffer is empty, then the operation fails.
225          *
226          * @sa otTcpSendByExtension
227          *
228          * @param[in]  aNumBytes  The number of bytes by which to extend the length of the final linked buffer.
229          * @param[in]  aFlags     Flags specifying options for this operation (see enumeration above).
230          *
231          * @retval kErrorNone    Successfully added data to the send buffer.
232          * @retval kErrorFailed  Failed to add data to the send buffer.
233          *
234          */
235         Error SendByExtension(size_t aNumBytes, uint32_t aFlags);
236 
237         /**
238          * Provides the application with a linked buffer chain referencing data
239          * currently in the TCP receive buffer.
240          *
241          * The linked buffer chain is valid until the "receive ready" callback is next
242          * invoked, or until the next call to otTcpReceiveContiguify() or
243          * otTcpCommitReceive().
244          *
245          * @sa otTcpReceiveByReference
246          *
247          * @param[out]  aBuffer    A pointer to the linked buffer chain referencing data currently in the receive
248          * buffer.
249          *
250          * @retval kErrorNone    Successfully completed the operation.
251          * @retval kErrorFailed  Failed to complete the operation.
252          */
253         Error ReceiveByReference(const otLinkedBuffer *&aBuffer);
254 
255         /**
256          * Reorganizes the receive buffer to be entirely contiguous in memory.
257          *
258          * This is optional; an application can simply traverse the linked buffer
259          * chain obtained by calling @p otTcpReceiveByReference. Some
260          * applications may wish to call this function to make the receive buffer
261          * contiguous to simplify their data processing, but this comes at the expense
262          * of CPU time to reorganize the data in the receive buffer.
263          *
264          * @sa otTcpReceiveContiguify
265          *
266          * @retval kErrorNone    Successfully completed the operation.
267          * @retval kErrorFailed  Failed to complete the operation.
268          *
269          */
270         Error ReceiveContiguify(void);
271 
272         /**
273          * Informs the TCP stack that the application has finished processing
274          * @p aNumBytes bytes of data at the start of the receive buffer and that the
275          * TCP stack need not continue maintaining those bytes in the receive buffer.
276          *
277          * @sa otTcpCommitReceive
278          *
279          * @param[in]  aNumBytes  The number of bytes consumed.
280          * @param[in]  aFlags     Flags specifying options for this operation (none yet).
281          *
282          * @retval kErrorNone    Successfully completed the receive operation.
283          * @retval kErrorFailed  Failed to complete the receive operation.
284          *
285          */
286         Error CommitReceive(size_t aNumBytes, uint32_t aFlags);
287 
288         /**
289          * Informs the connection peer that this TCP endpoint will not send more data.
290          *
291          * This should be used when the application has no more data to send to the
292          * connection peer. For this connection, future reads on the connection peer
293          * will result in the "end of stream" condition, and future writes on this
294          * connection endpoint will fail.
295          *
296          * The "end of stream" condition only applies after any data previously
297          * provided to the TCP stack to send out has been received by the connection
298          * peer.
299          *
300          * @sa otTcpSendEndOfStream
301          *
302          * @retval kErrorNone    Successfully queued the "end of stream" condition for transmission.
303          * @retval kErrorFailed  Failed to queue the "end of stream" condition for transmission.
304          *
305          */
306         Error SendEndOfStream(void);
307 
308         /**
309          * Forcibly ends the TCP connection associated with this TCP endpoint.
310          *
311          * This immediately makes the TCP endpoint free for use for another connection
312          * and empties the send and receive buffers, transferring ownership of any data
313          * provided by the application in otTcpSendByReference() calls back to
314          * the application. The TCP endpoint's callbacks and memory for the receive
315          * buffer remain associated with the TCP endpoint.
316          *
317          * @sa otTcpAbort
318          *
319          * @retval kErrorNone    Successfully aborted the TCP endpoint's connection.
320          * @retval kErrorFailed  Failed to abort the TCP endpoint's connection.
321          *
322          */
323         Error Abort(void);
324 
325         /**
326          * Deinitializes this TCP endpoint.
327          *
328          * This means that OpenThread no longer keeps track of this TCP endpoint and
329          * deallocates all resources it has internally allocated for this TCP endpoint.
330          * The application can reuse the memory backing the TCP endpoint as it sees fit.
331          *
332          * If it corresponds to a live TCP connection, the connection is terminated
333          * unceremoniously (as in otTcpAbort()). All resources the application has
334          * provided for this TCP endpoint (linked buffers for the send buffer, memory
335          * for the receive buffer, this Endpoint structure itself, etc.) are
336          * immediately returned to the application.
337          *
338          * @sa otTcpEndpointDeinitialize
339          *
340          * @retval kErrorNone    Successfully deinitialized the TCP endpoint.
341          * @retval kErrorFailed  Failed to deinitialize the TCP endpoint.
342          *
343          */
344         Error Deinitialize(void);
345 
346         /**
347          * Converts a reference to a struct tcpcb to a reference to its
348          * enclosing Endpoint.
349          */
FromTcb(struct tcpcb & aTcb)350         static Endpoint &FromTcb(struct tcpcb &aTcb) { return *reinterpret_cast<Endpoint *>(&aTcb); }
351 
352         /**
353          * Obtains a reference to this Endpoint's struct tcpcb.
354          */
GetTcb(void)355         struct tcpcb &GetTcb(void) { return *reinterpret_cast<struct tcpcb *>(&mTcb); }
356 
357         /**
358          * Obtains a const reference to this Endpoint's struct tcpcb.
359          */
GetTcb(void) const360         const struct tcpcb &GetTcb(void) const { return *reinterpret_cast<const struct tcpcb *>(&mTcb); }
361 
362         /**
363          * Checks if this Endpoint is in the closed state.
364          */
365         bool IsClosed(void) const;
366 
367     private:
368         friend void ::tcplp_sys_set_timer(struct tcpcb *aTcb, uint8_t aTimerFlag, uint32_t aDelay);
369         friend void ::tcplp_sys_stop_timer(struct tcpcb *aTcb, uint8_t aTimerFlag);
370 
371         enum : uint8_t
372         {
373             kTimerDelack       = 0,
374             kTimerRexmtPersist = 1,
375             kTimerKeep         = 2,
376             kTimer2Msl         = 3,
377             kNumTimers         = 4,
378         };
379 
380         static uint8_t TimerFlagToIndex(uint8_t aTimerFlag);
381 
382         bool IsTimerActive(uint8_t aTimerIndex);
383         void SetTimer(uint8_t aTimerFlag, uint32_t aDelay);
384         void CancelTimer(uint8_t aTimerFlag);
385         bool FirePendingTimers(TimeMilli aNow, bool &aHasFutureTimer, TimeMilli &aEarliestFutureExpiry);
386 
387         void PostCallbacksAfterSend(size_t aSent, size_t aBacklogBefore);
388         bool FirePendingCallbacks(void);
389 
390         size_t GetSendBufferBytes(void) const;
391         size_t GetInFlightBytes(void) const;
392         size_t GetBacklogBytes(void) const;
393 
394         Address &      GetLocalIp6Address(void);
395         const Address &GetLocalIp6Address(void) const;
396         Address &      GetForeignIp6Address(void);
397         const Address &GetForeignIp6Address(void) const;
398         bool           Matches(const MessageInfo &aMessageInfo) const;
399     };
400 
401     /**
402      * This class represents a TCP/IPv6 listener.
403      *
404      */
405     class Listener : public otTcpListener, public LinkedListEntry<Listener>, public GetProvider<Listener>
406     {
407         friend class LinkedList<Listener>;
408 
409     public:
410         /**
411          * Initializes a TCP listener.
412          *
413          * Calling this function causes OpenThread to keep track of the TCP listener
414          * and store and retrieve TCP data inside this Listener. The application should
415          * refrain from directly accessing or modifying the fields in this Listener. If
416          * the application needs to reclaim the memory backing this Listener, it should
417          * call otTcpListenerDeinitialize().
418          *
419          * @sa otTcpListenerInitialize
420          *
421          * @param[in]  aInstance  A pointer to an OpenThread instance.
422          * @param[in]  aArgs      A pointer to a structure of arguments.
423          *
424          * @retval kErrorNone    Successfully opened the TCP listener.
425          * @retval kErrorFailed  Failed to open the TCP listener.
426          *
427          */
428         Error Initialize(Instance &aInstance, const otTcpListenerInitializeArgs &aArgs);
429 
430         /**
431          * Obtains the otInstance that was associated with this Listener upon
432          * initialization.
433          *
434          * @sa otTcpListenerGetInstance
435          *
436          * @returns  The otInstance pointer associated with this Listener.
437          *
438          */
439         Instance &GetInstance(void) const;
440 
441         /**
442          * Obtains the context pointer that was associated with this Listener upon
443          * initialization.
444          *
445          * @sa otTcpListenerGetContext
446          *
447          * @returns  The context pointer associated with this Listener.
448          *
449          */
GetContext(void)450         void *GetContext(void) { return mContext; }
451 
452         /**
453          * Causes incoming TCP connections that match the specified IP address and port
454          * to trigger this TCP listener's callbacks.
455          *
456          * @sa otTcpListen
457          *
458          * @param[in]  aSockName  The address and port on which to listen for incoming connections.
459          *
460          * @retval kErrorNone    Successfully initiated listening on the TCP listener.
461          * @retval kErrorFailed  Failed to initiate listening on the TCP listener.
462          *
463          */
464         Error Listen(const SockAddr &aSockName);
465 
466         /**
467          * Causes this TCP listener to stop listening for incoming connections.
468          *
469          * @sa otTcpStopListening
470          *
471          * @retval kErrorNone    Successfully stopped listening on the TCP listener.
472          * @retval kErrorFailed  Failed to stop listening on the TCP listener.
473          *
474          */
475         Error StopListening(void);
476 
477         /**
478          * Deinitializes this TCP listener.
479          *
480          * This means that OpenThread no longer keeps track of this TCP listener and
481          * deallocates all resources it has internally allocated for this TCP endpoint.
482          * The application can reuse the memory backing the TCP listener as it sees
483          * fit.
484          *
485          * If the TCP listener is currently listening, it stops listening.
486          *
487          * @sa otTcpListenerDeinitialize
488          *
489          * @retval kErrorNone    Successfully deinitialized the TCP listener.
490          * @retval kErrorFailed  Failed to deinitialize the TCP listener.
491          *
492          */
493         Error Deinitialize(void);
494 
495         /**
496          * Converts a reference to a struct tcpcb_listen to a reference to its
497          * enclosing Listener.
498          */
FromTcbListen(struct tcpcb_listen & aTcbListen)499         static Listener &FromTcbListen(struct tcpcb_listen &aTcbListen)
500         {
501             return *reinterpret_cast<Listener *>(&aTcbListen);
502         }
503 
504         /**
505          * Obtains a reference to this Listener's struct tcpcb_listen.
506          */
GetTcbListen(void)507         struct tcpcb_listen &GetTcbListen(void) { return *reinterpret_cast<struct tcpcb_listen *>(&mTcbListen); }
508 
509         /**
510          * Obtains a const reference to this Listener's struct tcpcb_listen.
511          */
GetTcbListen(void) const512         const struct tcpcb_listen &GetTcbListen(void) const
513         {
514             return *reinterpret_cast<const struct tcpcb_listen *>(&mTcbListen);
515         }
516 
517         /**
518          * Checks if this Listener is in the closed state.
519          */
520         bool IsClosed(void) const;
521 
522     private:
523         Address &      GetLocalIp6Address(void);
524         const Address &GetLocalIp6Address(void) const;
525         bool           Matches(const MessageInfo &aMessageInfo) const;
526     };
527 
528     /**
529      * This class implements TCP header parsing.
530      *
531      */
532     OT_TOOL_PACKED_BEGIN
533     class Header : public Clearable<Header>
534     {
535     public:
536         static constexpr uint8_t kChecksumFieldOffset = 16; ///< Byte offset of the Checksum field in the TCP header.
537 
538         /**
539          * This method returns the TCP Source Port.
540          *
541          * @returns The TCP Source Port.
542          *
543          */
GetSourcePort(void) const544         uint16_t GetSourcePort(void) const { return HostSwap16(mSource); }
545 
546         /**
547          * This method returns the TCP Destination Port.
548          *
549          * @returns The TCP Destination Port.
550          *
551          */
GetDestinationPort(void) const552         uint16_t GetDestinationPort(void) const { return HostSwap16(mDestination); }
553 
554         /**
555          * This method returns the TCP Sequence Number.
556          *
557          * @returns The TCP Sequence Number.
558          *
559          */
GetSequenceNumber(void) const560         uint32_t GetSequenceNumber(void) const { return HostSwap32(mSequenceNumber); }
561 
562         /**
563          * This method returns the TCP Acknowledgment Sequence Number.
564          *
565          * @returns The TCP Acknowledgment Sequence Number.
566          *
567          */
GetAcknowledgmentNumber(void) const568         uint32_t GetAcknowledgmentNumber(void) const { return HostSwap32(mAckNumber); }
569 
570         /**
571          * This method returns the TCP Flags.
572          *
573          * @returns The TCP Flags.
574          *
575          */
GetFlags(void) const576         uint16_t GetFlags(void) const { return HostSwap16(mFlags); }
577 
578         /**
579          * This method returns the TCP Window.
580          *
581          * @returns The TCP Window.
582          *
583          */
GetWindow(void) const584         uint16_t GetWindow(void) const { return HostSwap16(mWindow); }
585 
586         /**
587          * This method returns the TCP Checksum.
588          *
589          * @returns The TCP Checksum.
590          *
591          */
GetChecksum(void) const592         uint16_t GetChecksum(void) const { return HostSwap16(mChecksum); }
593 
594         /**
595          * This method returns the TCP Urgent Pointer.
596          *
597          * @returns The TCP Urgent Pointer.
598          *
599          */
GetUrgentPointer(void) const600         uint16_t GetUrgentPointer(void) const { return HostSwap16(mUrgentPointer); }
601 
602     private:
603         uint16_t mSource;
604         uint16_t mDestination;
605         uint32_t mSequenceNumber;
606         uint32_t mAckNumber;
607         uint16_t mFlags;
608         uint16_t mWindow;
609         uint16_t mChecksum;
610         uint16_t mUrgentPointer;
611     } OT_TOOL_PACKED_END;
612 
613     /**
614      * This constructor initializes the object.
615      *
616      * @param[in] aInstance  A reference to the OpenThread instance.
617      *
618      */
619     explicit Tcp(Instance &aInstance);
620 
621     /**
622      * Processes a received TCP segment.
623      *
624      * @param[in]  aIp6Header    A reference to a structure containing the segment's IPv6 header.
625      * @param[in]  aMessage      A reference to the message containing the TCP segment.
626      * @param[in]  aMessageInfo  A reference to the message info associated with @p aMessage.
627      *
628      * @retval kErrorNone  Successfully processed the TCP segment.
629      * @retval kErrorDrop  Dropped the TCP segment due to an invalid checksum.
630      *
631      */
632     Error HandleMessage(ot::Ip6::Header &aIp6Header, Message &aMessage, MessageInfo &aMessageInfo);
633 
634     /**
635      * Automatically selects a local address and/or port for communication with the specified peer.
636      *
637      * @param[in] aPeer         The peer's address and port.
638      * @param[in,out] aToBind   The SockAddr into which to store the selected address and/or port.
639      * @param[in] aBindAddress  If true, the local address is selected; if not, the current address
640      *                          in @p aToBind is treated as a given.
641      * @param[in] aBindPort     If true, the local port is selected; if not, the current port in
642      *                          @p aToBind is treated as a given.
643      *
644      * @returns  True if successful, false otherwise.
645      *
646      */
647     bool AutoBind(const SockAddr &aPeer, SockAddr &aToBind, bool aBindAddress, bool aBindPort);
648 
649     /**
650      * Checks if an Endpoint is in the list of initialized endpoints.
651      */
IsInitialized(const Endpoint & aEndpoint) const652     bool IsInitialized(const Endpoint &aEndpoint) const { return mEndpoints.Contains(aEndpoint); }
653 
654     /**
655      * Checks if a Listener is in the list of initialized Listeners.
656      */
IsInitialized(const Listener & aListener) const657     bool IsInitialized(const Listener &aListener) const { return mListeners.Contains(aListener); }
658 
659 private:
660     enum
661     {
662         kDynamicPortMin = 49152, ///< Service Name and Transport Protocol Port Number Registry
663         kDynamicPortMax = 65535, ///< Service Name and Transport Protocol Port Number Registry
664     };
665 
666     static constexpr uint8_t kEstablishedCallbackFlag      = (1 << 0);
667     static constexpr uint8_t kSendDoneCallbackFlag         = (1 << 1);
668     static constexpr uint8_t kForwardProgressCallbackFlag  = (1 << 2);
669     static constexpr uint8_t kReceiveAvailableCallbackFlag = (1 << 3);
670     static constexpr uint8_t kDisconnectedCallbackFlag     = (1 << 4);
671 
672     void ProcessSignals(Endpoint &            aEndpoint,
673                         otLinkedBuffer *      aPriorHead,
674                         size_t                aPriorBacklog,
675                         struct tcplp_signals &aSignals);
676 
677     static Error BsdErrorToOtError(int aBsdError);
678     bool         CanBind(const SockAddr &aSockName);
679 
680     static void HandleTimer(Timer &aTimer);
681     void        ProcessTimers(void);
682 
683     static void HandleTasklet(Tasklet &aTasklet);
684     void        ProcessCallbacks(void);
685 
686     TimerMilli mTimer;
687     Tasklet    mTasklet;
688 
689     LinkedList<Endpoint> mEndpoints;
690     LinkedList<Listener> mListeners;
691     uint16_t             mEphemeralPort;
692 };
693 
694 } // namespace Ip6
695 
696 DefineCoreType(otTcpEndpoint, Ip6::Tcp::Endpoint);
697 DefineCoreType(otTcpListener, Ip6::Tcp::Listener);
698 
699 } // namespace ot
700 
701 #endif // TCP6_HPP_
702