Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/** @file
 @brief TCP data handler

 This is not to be included by the application.
 */

/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef __TCP_INTERNAL_H
#define __TCP_INTERNAL_H

#include <zephyr/types.h>
#include <random/rand32.h>

#include <net/net_core.h>
#include <net/net_ip.h>
#include <net/net_pkt.h>
#include <net/net_context.h>

#include "connection.h"

#ifdef __cplusplus
extern "C" {
#endif

/** Is this TCP context/socket used or not */
#define NET_TCP_IN_USE BIT(0)

/* BIT(1), BIT(2) are unused and available */

/** Is the socket shutdown for read/write */
#define NET_TCP_IS_SHUTDOWN BIT(3)

/** A retransmitted packet has been sent and not yet ack'd */
#define NET_TCP_RETRYING BIT(4)

/** MSS option has been set already */
#define NET_TCP_RECV_MSS_SET BIT(5)

/*
 * TCP connection states
 */
enum net_tcp_state {
	NET_TCP_CLOSED = 0,
	NET_TCP_LISTEN,
	NET_TCP_SYN_SENT,
	NET_TCP_SYN_RCVD,
	NET_TCP_ESTABLISHED,
	NET_TCP_CLOSE_WAIT,
	NET_TCP_LAST_ACK,
	NET_TCP_FIN_WAIT_1,
	NET_TCP_FIN_WAIT_2,
	NET_TCP_TIME_WAIT,
	NET_TCP_CLOSING,
};

/* TCP packet types */
#define NET_TCP_FIN 0x01
#define NET_TCP_SYN 0x02
#define NET_TCP_RST 0x04
#define NET_TCP_PSH 0x08
#define NET_TCP_ACK 0x10
#define NET_TCP_URG 0x20
#define NET_TCP_CTL 0x3f

#define NET_TCP_FLAGS(hdr) (hdr->flags & NET_TCP_CTL)

/* Length of TCP header, including options */
/* "offset": 4-bit field in high nibble, units of dwords */
#define NET_TCP_HDR_LEN(hdr) (4 * ((hdr)->offset >> 4))

/* RFC 1122 4.2.2.6 "If an MSS option is not received at connection
 * setup, TCP MUST assume a default send MSS of 536"
 */
#define NET_TCP_DEFAULT_MSS   536

/* TCP max window size */
#define NET_TCP_MAX_WIN   (4 * 1024)

/* Maximal value of the sequence number */
#define NET_TCP_MAX_SEQ   0xffffffff

#define NET_TCP_MAX_OPT_SIZE  8

/* TCP Option codes */
#define NET_TCP_END_OPT          0
#define NET_TCP_NOP_OPT          1
#define NET_TCP_MSS_OPT          2
#define NET_TCP_WINDOW_SCALE_OPT 3

/* TCP Option sizes */
#define NET_TCP_END_SIZE          1
#define NET_TCP_NOP_SIZE          1
#define NET_TCP_MSS_SIZE          4
#define NET_TCP_WINDOW_SCALE_SIZE 3

/** Parsed TCP option values for net_tcp_parse_opts()  */
struct net_tcp_options {
	uint16_t mss;
};

/* Max received bytes to buffer internally */
#define NET_TCP_BUF_MAX_LEN 1280

/* Max segment lifetime, in seconds */
#define NET_TCP_MAX_SEG_LIFETIME 60

struct net_context;

struct net_tcp {
	/** Network context back pointer. */
	struct net_context *context;

	/** Cookie pointer passed to net_context_recv() */
	void *recv_user_data;

	/** ACK message timer */
	struct k_delayed_work ack_timer;

	/** Timer for doing active close in case the peer FIN is lost. */
	struct k_delayed_work fin_timer;

	/** Retransmit timer */
	struct k_delayed_work retry_timer;

	/** TIME_WAIT timer */
	struct k_delayed_work timewait_timer;

	/** List pointer used for TCP retransmit buffering */
	sys_slist_t sent_list;

	/** Current sequence number. */
	uint32_t send_seq;

	/** Acknowledgment number to send in next packet. */
	uint32_t send_ack;

	/** Last ACK value sent */
	uint32_t sent_ack;

	/** Accept callback to be called when the connection has been
	 * established.
	 */
	net_tcp_accept_cb_t accept_cb;

	/**
	 * Semaphore to signal TCP connection completion
	 */
	struct k_sem connect_wait;

	/**
	 * Current TCP receive window for our side
	 */
	uint16_t recv_wnd;

	/**
	 * Send MSS for the peer
	 */
	uint16_t send_mss;

	/** Current retransmit period */
	uint32_t retry_timeout_shift : 5;
	/** Flags for the TCP */
	uint32_t flags : 8;
	/** Current TCP state */
	uint32_t state : 4;
	/* An outbound FIN packet has been sent */
	uint32_t fin_sent : 1;
	/* An inbound FIN packet has been received */
	uint32_t fin_rcvd : 1;
	/** Remaining bits in this uint32_t */
	uint32_t _padding : 13;
};

typedef void (*net_tcp_cb_t)(struct net_tcp *tcp, void *user_data);

static inline bool net_tcp_is_used(struct net_tcp *tcp)
{
	NET_ASSERT(tcp);

	return tcp->flags & NET_TCP_IN_USE;
}

/**
 * @brief Register a callback to be called when TCP packet
 * is received corresponding to received packet.
 *
 * @param family Protocol family
 * @param remote_addr Remote address of the connection end point.
 * @param local_addr Local address of the connection end point.
 * @param remote_port Remote port of the connection end point.
 * @param local_port Local port of the connection end point.
 * @param cb Callback to be called
 * @param user_data User data supplied by caller.
 * @param handle TCP handle that can be used when unregistering
 *
 * @return Return 0 if the registration succeed, <0 otherwise.
 */
static inline int net_tcp_register(uint8_t family,
				   const struct sockaddr *remote_addr,
				   const struct sockaddr *local_addr,
				   uint16_t remote_port,
				   uint16_t local_port,
				   net_conn_cb_t cb,
				   void *user_data,
				   struct net_conn_handle **handle)
{
	return net_conn_register(IPPROTO_TCP, family, remote_addr, local_addr,
				 remote_port, local_port, cb, user_data,
				 handle);
}

/**
 * @brief Unregister TCP handler.
 *
 * @param handle Handle from registering.
 *
 * @return Return 0 if the unregistration succeed, <0 otherwise.
 */
static inline int net_tcp_unregister(struct net_conn_handle *handle)
{
	return net_conn_unregister(handle);
}

/*
 * @brief Generate initial TCP sequence number
 *
 * @return Return a random TCP sequence number
 */
static inline uint32_t tcp_init_isn(void)
{
	/* Randomise initial seq number */
	return sys_rand32_get();
}

const char *net_tcp_state_str(enum net_tcp_state state);

#if defined(CONFIG_NET_NATIVE_TCP)
void net_tcp_change_state(struct net_tcp *tcp, enum net_tcp_state new_state);
#else
#define net_tcp_change_state(...)
#endif

/**
 * @brief Allocate TCP connection context.
 *
 * @param context Pointer to net_context that is tied to this TCP
 * context.
 *
 * @return Pointer TCP connection context. NULL if no available
 * context can be found.
 */
#if defined(CONFIG_NET_NATIVE_TCP)
struct net_tcp *net_tcp_alloc(struct net_context *context);
#else
static inline struct net_tcp *net_tcp_alloc(struct net_context *context)
{
	ARG_UNUSED(context);
	return NULL;
}
#endif

/**
 * @brief Release TCP connection context.
 *
 * @param tcp Pointer to net_tcp context.
 *
 * @return 0 if ok, < 0 if error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_release(struct net_tcp *tcp);
#else
static inline int net_tcp_release(struct net_tcp *tcp)
{
	ARG_UNUSED(tcp);
	return 0;
}
#endif

/**
 * @brief Send a TCP segment without any data. The returned buffer
 * is a ready made packet that can be sent via net_send_data()
 * function.
 *
 * @param tcp TCP context
 * @param flags TCP flags
 * @param options Pointer TCP options, NULL if no options.
 * @param optlen Length of the options.
 * @param local Source address, or NULL to use the local address of
 *        the TCP context
 * @param remote Peer address
 * @param send_pkt Full IP + TCP header that is to be sent.
 *
 * @return 0 if ok, < 0 if error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_prepare_segment(struct net_tcp *tcp, uint8_t flags,
			    void *options, size_t optlen,
			    const struct sockaddr_ptr *local,
			    const struct sockaddr *remote,
			    struct net_pkt **send_pkt);
#else
static inline int net_tcp_prepare_segment(struct net_tcp *tcp, uint8_t flags,
					  void *options, size_t optlen,
					  const struct sockaddr_ptr *local,
					  const struct sockaddr *remote,
					  struct net_pkt **send_pkt)
{
	ARG_UNUSED(tcp);
	ARG_UNUSED(flags);
	ARG_UNUSED(options);
	ARG_UNUSED(optlen);
	ARG_UNUSED(local);
	ARG_UNUSED(remote);
	ARG_UNUSED(send_pkt);
	return 0;
}
#endif

/**
 * @brief Prepare a TCP ACK message that can be send to peer.
 *
 * @param tcp TCP context
 * @param remote Peer address
 * @param pkt Network buffer
 *
 * @return 0 if ok, < 0 if error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_prepare_ack(struct net_tcp *tcp, const struct sockaddr *remote,
			struct net_pkt **pkt);
#else
static inline int net_tcp_prepare_ack(struct net_tcp *tcp,
				      const struct sockaddr *remote,
				      struct net_pkt **pkt)
{
	ARG_UNUSED(tcp);
	ARG_UNUSED(remote);
	ARG_UNUSED(pkt);
	return 0;
}
#endif

/**
 * @brief Prepare a TCP RST message that can be send to peer.
 *
 * @param tcp TCP context
 * @param local Source address
 * @param remote Peer address
 * @param pkt Network buffer
 *
 * @return 0 if ok, < 0 if error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_prepare_reset(struct net_tcp *tcp,
			  const struct sockaddr *local,
			  const struct sockaddr *remote,
			  struct net_pkt **pkt);
#else
static inline int net_tcp_prepare_reset(struct net_tcp *tcp,
					const struct sockaddr *remote,
					struct net_pkt **pkt)
{
	ARG_UNUSED(tcp);
	ARG_UNUSED(remote);
	ARG_UNUSED(pkt);
	return 0;
}
#endif

/**
 * @brief Go through all the TCP connections and call callback
 * for each of them.
 *
 * @param cb User supplied callback function to call.
 * @param user_data User specified data.
 */
#if defined(CONFIG_NET_NATIVE_TCP)
void net_tcp_foreach(net_tcp_cb_t cb, void *user_data);
#else
static inline void net_tcp_foreach(net_tcp_cb_t cb, void *user_data)
{
	ARG_UNUSED(cb);
	ARG_UNUSED(user_data);
}
#endif

/**
 * @brief Send available queued data over TCP connection
 *
 * @param context TCP context
 * @param cb TCP callback function
 * @param user_data User specified data
 *
 * @return 0 if ok, < 0 if error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_send_data(struct net_context *context, net_context_send_cb_t cb,
		      void *user_data);
#else
static inline int net_tcp_send_data(struct net_context *context,
				    net_context_send_cb_t cb,
				    void *user_data)
{
	ARG_UNUSED(context);
	ARG_UNUSED(cb);
	ARG_UNUSED(user_data);

	return 0;
}
#endif

/**
 * @brief Enqueue a single packet for transmission
 *
 * @param context TCP context
 * @param pkt Packet
 *
 * @return 0 if ok, < 0 if error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_queue_data(struct net_context *context, struct net_pkt *pkt);
#else
static inline int net_tcp_queue_data(struct net_context *context,
				     struct net_pkt *pkt)
{
	ARG_UNUSED(context);
	ARG_UNUSED(pkt);
	return -EPROTONOSUPPORT;
}
#endif

/**
 * @brief Sends one TCP packet initialized with the _prepare_*()
 *        family of functions.
 *
 * @param pkt Packet
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_send_pkt(struct net_pkt *pkt);
#else
static inline int net_tcp_send_pkt(struct net_pkt *pkt)
{
	ARG_UNUSED(pkt);
	return 0;
}
#endif

/**
 * @brief Handle a received TCP ACK
 *
 * @param cts Context
 * @param seq Received ACK sequence number
 * @return False if ACK sequence number is invalid, true otherwise
 */
#if defined(CONFIG_NET_NATIVE_TCP)
bool net_tcp_ack_received(struct net_context *ctx, uint32_t ack);
#else
static inline bool net_tcp_ack_received(struct net_context *ctx, uint32_t ack)
{
	ARG_UNUSED(ctx);
	ARG_UNUSED(ack);
	return false;
}
#endif

/**
 * @brief Calculates and returns the MSS for a given TCP context
 *
 * @param tcp TCP context
 *
 * @return Maximum Segment Size
 */
#if defined(CONFIG_NET_NATIVE_TCP)
uint16_t net_tcp_get_recv_mss(const struct net_tcp *tcp);
#else
static inline uint16_t net_tcp_get_recv_mss(const struct net_tcp *tcp)
{
	ARG_UNUSED(tcp);
	return 0;
}
#endif

/**
 * @brief Returns the receive window for a given TCP context
 *
 * @param tcp TCP context
 *
 * @return Current TCP receive window
 */
#if defined(CONFIG_NET_NATIVE_TCP)
uint32_t net_tcp_get_recv_wnd(const struct net_tcp *tcp);
#else
static inline uint32_t net_tcp_get_recv_wnd(const struct net_tcp *tcp)
{
	ARG_UNUSED(tcp);
	return 0;
}
#endif

/**
 * @brief Obtains the state for a TCP context
 *
 * @param tcp TCP context
 */
#if defined(CONFIG_NET_NATIVE_TCP)
static inline enum net_tcp_state net_tcp_get_state(const struct net_tcp *tcp)
{
	return (enum net_tcp_state)tcp->state;
}
#else
static inline enum net_tcp_state net_tcp_get_state(const struct net_tcp *tcp)
{
	ARG_UNUSED(tcp);
	return NET_TCP_CLOSED;
}
#endif

/**
 * @brief Check if the sequence number is valid i.e., it is inside the window.
 *
 * @param tcp TCP context
 * @param tcp_hdr TCP header pointer
 *
 * @return true if network packet sequence number is valid, false otherwise
 */
#if defined(CONFIG_NET_NATIVE_TCP)
bool net_tcp_validate_seq(struct net_tcp *tcp, struct net_tcp_hdr *tcp_hdr);
#else
static inline bool net_tcp_validate_seq(struct net_tcp *tcp,
					struct net_tcp_hdr *tcp_hdr)
{
	ARG_UNUSED(tcp);
	ARG_UNUSED(tcp_hdr);
	return false;
}
#endif

/**
 * @brief Finalize TCP packet
 *
 * @param pkt Network packet
 *
 * @return 0 on success, negative errno otherwise.
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_finalize(struct net_pkt *pkt);
#else
static inline int net_tcp_finalize(struct net_pkt *pkt)
{
	ARG_UNUSED(pkt);
	return 0;
}
#endif

/**
 * @brief Parse TCP options from network packet.
 *
 * Parse TCP options, returning MSS value (as that the only one we
 * handle so far).
 *
 * @param pkt Network packet
 * @param opt_totlen Total length of options to parse
 * @param opts Pointer to TCP options structure. (Each option is updated
 * only if present, so the structure must be initialized with the default
 * values.)
 *
 * @return 0 if no error, <0 in case of error
 */
int net_tcp_parse_opts(struct net_pkt *pkt, int opt_totlen,
		       struct net_tcp_options *opts);

/**
 * @brief TCP receive function
 *
 * @param context Network context
 * @param cb TCP receive callback function
 * @param user_data TCP receive callback user data
 *
 * @return 0 if no erro, < 0 in case of error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_recv(struct net_context *context, net_context_recv_cb_t cb,
		 void *user_data);
#else
static inline int net_tcp_recv(struct net_context *context,
			       net_context_recv_cb_t cb, void *user_data)
{
	ARG_UNUSED(context);
	ARG_UNUSED(cb);
	ARG_UNUSED(user_data);

	return -EPROTOTYPE;
}
#endif

/**
 * @brief Queue a TCP FIN packet if needed to close the socket
 *
 * @param context Network context
 *
 * @return 0 on success where a TCP FIN packet has been queueed, -ENOTCONN
 *         in case the socket was not connected or listening, -EOPNOTSUPP
 *         in case it was not a TCP socket or -EPROTONOSUPPORT if TCP is not
 *         supported
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_put(struct net_context *context);
#else
static inline int net_tcp_put(struct net_context *context)
{
	ARG_UNUSED(context);

	return -EPROTONOSUPPORT;
}
#endif

/**
 * @brief Set TCP socket into listening state
 *
 * @param context Network context
 *
 * @return 0 if successful, -EOPNOTSUPP if the context was not for TCP,
 *         -EPROTONOSUPPORT if TCP is not supported
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_listen(struct net_context *context);
#else
static inline int net_tcp_listen(struct net_context *context)
{
	ARG_UNUSED(context);

	return -EPROTONOSUPPORT;
}
#endif

/**
 * @brief Update TCP receive window
 *
 * @param context Network context
 * @param delta Receive window delta
 *
 * @return 0 on success, -EPROTOTYPE if there is no TCP context, -EINVAL
 *         if the receive window delta is out of bounds, -EPROTONOSUPPORT
 *         if TCP is not supported
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_update_recv_wnd(struct net_context *context, int32_t delta);
#else
static inline int net_tcp_update_recv_wnd(struct net_context *context,
					  int32_t delta)
{
	ARG_UNUSED(context);
	ARG_UNUSED(delta);

	return -EPROTONOSUPPORT;
}
#endif

/**
 * @brief Initialize TCP parts of a context
 *
 * @param context Network context
 *
 * @return 0 if successful, < 0 on error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_get(struct net_context *context);
#else
static inline int net_tcp_get(struct net_context *context)
{
	ARG_UNUSED(context);

	return -EPROTONOSUPPORT;
}
#endif

/**
 * @brief Unref TCP parts of a context
 *
 * @param context Network context
 *
 * @return 0 if successful, < 0 on error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_unref(struct net_context *context);
#else
static inline int net_tcp_unref(struct net_context *context)
{
	ARG_UNUSED(context);

	return -EPROTONOSUPPORT;
}
#endif

/**
 * @brief Accept TCP connection
 *
 * @param context Network context
 * @param cb Accept callback
 * @param user_data Accept callback user data
 *
 * @return 0 on success, < 0 on error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_accept(struct net_context *context, net_tcp_accept_cb_t cb,
		   void *user_data);
#else
static inline int net_tcp_accept(struct net_context *context,
				 net_tcp_accept_cb_t cb, void *user_data)
{
	ARG_UNUSED(context);
	ARG_UNUSED(cb);
	ARG_UNUSED(user_data);

	return -EPROTONOSUPPORT;
}
#endif

/**
 * @brief Connect TCP connection
 *
 * @param context Network context
 * @param addr Remote address
 * @param laddr Local address
 * @param rport Remote port
 * @param lport Local port
 * @param timeout Connect timeout
 * @param cb Connect callback
 * @param user_data Connect callback user data
 *
 * @return 0 on success, < 0 on error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
int net_tcp_connect(struct net_context *context,
		    const struct sockaddr *addr,
		    struct sockaddr *laddr,
		    uint16_t rport,
		    uint16_t lport,
		    k_timeout_t timeout,
		    net_context_connect_cb_t cb,
		    void *user_data);
#else
static inline int net_tcp_connect(struct net_context *context,
				  const struct sockaddr *addr,
				  struct sockaddr *laddr,
				  uint16_t rport, uint16_t lport, k_timeout_t timeout,
				  net_context_connect_cb_t cb, void *user_data)
{
	ARG_UNUSED(context);
	ARG_UNUSED(addr);
	ARG_UNUSED(laddr);
	ARG_UNUSED(rport);
	ARG_UNUSED(lport);
	ARG_UNUSED(cb);
	ARG_UNUSED(user_data);

	return -EPROTONOSUPPORT;
}
#endif

/**
 * @brief Get pointer to TCP header in net_pkt
 *
 * @param pkt Network packet
 * @param tcp_access Helper variable for accessing TCP header
 *
 * @return TCP header on success, NULL on error
 */
#if defined(CONFIG_NET_NATIVE_TCP)
struct net_tcp_hdr *net_tcp_input(struct net_pkt *pkt,
				  struct net_pkt_data_access *tcp_access);
#else
static inline
struct net_tcp_hdr *net_tcp_input(struct net_pkt *pkt,
				  struct net_pkt_data_access *tcp_access)
{
	ARG_UNUSED(pkt);
	ARG_UNUSED(tcp_access);

	return NULL;
}
#endif

#if defined(CONFIG_NET_NATIVE_TCP)
void net_tcp_init(void);
#else
#define net_tcp_init(...)
#endif

#ifdef __cplusplus
}
#endif

#endif /* __TCP_INTERNAL_H */