1
10
13
14
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
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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
198
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
298
299
300
301
302
303
304
305
306
307
308
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
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
452
453
454
455
456
457
458
462
463
464
468
469
470
474
478
479
480
484
485
486
487
488
489
490
491
492
493
494
500
501
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
528
529
530
531
532
533
539
545
546
547
553
554
555
556
557
558
559
563
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
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
625
626
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
656
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
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
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
786
787
788
793
794
795
796
797
804
805
810
811
812
813
814
815
816
817
818
821
822
823
824
828
829
830
831
832
833
834
836
837
838
839
840
844
845
846
847
848
849
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
963
964
965
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#ifdef FEATURE_NX_IPV6
#include "nx_ipv6.h"
#endif
#include "nx_packet.h"
#include "nx_tcp.h"
#include "tx_thread.h"
#ifdef NX_IPSEC_ENABLE
#include "nx_ipsec.h"
#endif
#ifdef NX_ENABLE_TCPIP_OFFLOAD...
...
static UINT _nx_tcp_socket_driver_send(NX_TCP_SOCKET *socket_ptr, NX_PACKET *packet_ptr, ULONG wait_option)
{
UINT status;
NX_IP *ip_ptr;
NX_INTERFACE *interface_ptr = socket_ptr -> nx_tcp_socket_connect_interface;
#ifdef NX_ENABLE_IP_PACKET_FILTER
UCHAR *original_ptr = packet_ptr -> nx_packet_prepend_ptr;
ULONG original_length = packet_ptr -> nx_packet_length;
NX_TCP_HEADER *header_ptr;/* ... */
#endif
ip_ptr = socket_ptr -> nx_tcp_socket_ip_ptr;
#ifdef NX_ENABLE_IP_PACKET_FILTER
if (ip_ptr -> nx_ip_packet_filter || ip_ptr -> nx_ip_packet_filter_extended)
{
packet_ptr -> nx_packet_prepend_ptr = packet_ptr -> nx_packet_prepend_ptr - sizeof(NX_TCP_HEADER);
packet_ptr -> nx_packet_length = packet_ptr -> nx_packet_length + (ULONG)sizeof(NX_TCP_HEADER);
header_ptr = (NX_TCP_HEADER *)packet_ptr -> nx_packet_prepend_ptr;
header_ptr -> nx_tcp_header_word_0 = (((ULONG)(socket_ptr -> nx_tcp_socket_port)) << NX_SHIFT_BY_16) |
(ULONG)socket_ptr -> nx_tcp_socket_connect_port;
header_ptr -> nx_tcp_acknowledgment_number = 0;
header_ptr -> nx_tcp_sequence_number = 0;
header_ptr -> nx_tcp_header_word_3 = NX_TCP_HEADER_SIZE | NX_TCP_ACK_BIT | NX_TCP_PSH_BIT;
header_ptr -> nx_tcp_header_word_4 = 0;
/* ... */
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_0);
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_3);
#ifndef NX_DISABLE_IPV4
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4)
{
_nx_ip_header_add(ip_ptr, packet_ptr,
socket_ptr -> nx_tcp_socket_connect_interface -> nx_interface_ip_address,
socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v4,
socket_ptr -> nx_tcp_socket_type_of_service,
socket_ptr -> nx_tcp_socket_time_to_live,
NX_IP_TCP,
socket_ptr -> nx_tcp_socket_fragment_enable);
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6)
{
if (_nx_ipv6_header_add(ip_ptr, &packet_ptr,
NX_PROTOCOL_TCP,
packet_ptr -> nx_packet_length,
ip_ptr -> nx_ipv6_hop_limit,
socket_ptr -> nx_tcp_socket_ipv6_addr -> nxd_ipv6_address,
socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v6,
NX_NULL))
{
return(NX_SUCCESS);
}if (_nx_ipv6_header_add(ip_ptr, &packet_ptr, NX_PROTOCOL_TCP, packet_ptr -> nx_packet_length, ip_ptr -> nx_ipv6_hop_limit, socket_ptr -> nx_tcp_socket_ipv6_addr -> nxd_ipv6_address, socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v6, NX_NULL)) { ... }
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
if (ip_ptr -> nx_ip_packet_filter)
{
if (ip_ptr -> nx_ip_packet_filter((VOID *)(packet_ptr -> nx_packet_prepend_ptr),
NX_IP_PACKET_OUT) != NX_SUCCESS)
{
_nx_packet_transmit_release(packet_ptr);
return(NX_SUCCESS);
}if (ip_ptr -> nx_ip_packet_filter((VOID *)(packet_ptr -> nx_packet_prepend_ptr), NX_IP_PACKET_OUT) != NX_SUCCESS) { ... }
}if (ip_ptr -> nx_ip_packet_filter) { ... }
if (ip_ptr -> nx_ip_packet_filter_extended)
{
if (ip_ptr -> nx_ip_packet_filter_extended(ip_ptr, packet_ptr, NX_IP_PACKET_OUT) != NX_SUCCESS)
{
_nx_packet_transmit_release(packet_ptr);
return(NX_SUCCESS);
}if (ip_ptr -> nx_ip_packet_filter_extended(ip_ptr, packet_ptr, NX_IP_PACKET_OUT) != NX_SUCCESS) { ... }
}if (ip_ptr -> nx_ip_packet_filter_extended) { ... }
packet_ptr -> nx_packet_prepend_ptr = original_ptr;
packet_ptr -> nx_packet_length = original_length;
}if (ip_ptr -> nx_ip_packet_filter || ip_ptr -> nx_ip_packet_filter_extended) { ... }
/* ... */#endif
status = interface_ptr -> nx_interface_tcpip_offload_handler(ip_ptr, interface_ptr, socket_ptr,
NX_TCPIP_OFFLOAD_TCP_SOCKET_SEND,
packet_ptr, NX_NULL, NX_NULL, 0, NX_NULL,
wait_option);
if (status)
{
return(NX_TCPIP_OFFLOAD_ERROR);
}if (status) { ... }
else
{
return(NX_SUCCESS);
}else { ... }
}_nx_tcp_socket_driver_send (NX_TCP_SOCKET *socket_ptr, NX_PACKET *packet_ptr, ULONG wait_option) { ... }
/* ... */#endif
...
UINT _nx_tcp_socket_send_internal(NX_TCP_SOCKET *socket_ptr, NX_PACKET *packet_ptr, ULONG wait_option)
{
TX_INTERRUPT_SAVE_AREA
NX_IP *ip_ptr;
NX_PACKET_POOL *pool_ptr;
NX_TCP_HEADER *header_ptr;
ULONG checksum = 0;
ULONG sequence_number;
ULONG tx_window_current;
ULONG remaining_bytes;
ULONG *source_ip = NX_NULL, *dest_ip = NX_NULL;
ULONG send_mss;
NX_PACKET *send_packet = packet_ptr;
NX_PACKET *current_packet;
UCHAR *current_ptr;
ULONG data_offset = 0;
ULONG source_data_size;
ULONG copy_size;
UINT data_left;
UINT ret;
UCHAR preempted = NX_FALSE;
UCHAR adjust_packet;
UINT old_threshold = 0;
ULONG window_size;
#ifdef NX_ENABLE_TCPIP_OFFLOAD
UINT status;
NX_INTERFACE *interface_ptr;/* ... */
#endif
#if defined(NX_DISABLE_TCP_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
UINT compute_checksum = 1;
#endif
#ifdef NX_DISABLE_TCP_TX_CHECKSUM
compute_checksum = 0;
#endif
if (packet_ptr -> nx_packet_length == 0)
{
return(NX_INVALID_PACKET);
}if (packet_ptr -> nx_packet_length == 0) { ... }
TX_DISABLE
if (!socket_ptr -> nx_tcp_socket_bound_next)
{
TX_RESTORE
return(NX_NOT_BOUND);
}if (!socket_ptr -> nx_tcp_socket_bound_next) { ... }
ip_ptr = socket_ptr -> nx_tcp_socket_ip_ptr;
TX_RESTORE
if ((socket_ptr -> nx_tcp_socket_state == NX_TCP_SYN_SENT) || (socket_ptr -> nx_tcp_socket_state == NX_TCP_SYN_RECEIVED))
{
_nx_tcp_socket_state_wait(socket_ptr, NX_TCP_ESTABLISHED, wait_option);
}if ((socket_ptr -> nx_tcp_socket_state == NX_TCP_SYN_SENT) || (socket_ptr -> nx_tcp_socket_state == NX_TCP_SYN_RECEIVED)) { ... }
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
if ((socket_ptr -> nx_tcp_socket_state != NX_TCP_ESTABLISHED) && (socket_ptr -> nx_tcp_socket_state != NX_TCP_CLOSE_WAIT))
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_NOT_CONNECTED);
}if ((socket_ptr -> nx_tcp_socket_state != NX_TCP_ESTABLISHED) && (socket_ptr -> nx_tcp_socket_state != NX_TCP_CLOSE_WAIT)) { ... }
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
#ifndef NX_DISABLE_IPV4
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4)
{
source_ip = &socket_ptr -> nx_tcp_socket_connect_interface -> nx_interface_ip_address;
dest_ip = &socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v4;
packet_ptr -> nx_packet_address.nx_packet_interface_ptr = socket_ptr -> nx_tcp_socket_connect_interface;
data_offset = NX_PHYSICAL_HEADER + sizeof(NX_IPV4_HEADER) + sizeof(NX_TCP_HEADER);
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6)
{
if (socket_ptr -> nx_tcp_socket_ipv6_addr -> nxd_ipv6_address_state != NX_IPV6_ADDR_STATE_VALID)
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
return(NX_NO_INTERFACE_ADDRESS);
}if (socket_ptr -> nx_tcp_socket_ipv6_addr -> nxd_ipv6_address_state != NX_IPV6_ADDR_STATE_VALID) { ... }
source_ip = socket_ptr -> nx_tcp_socket_ipv6_addr -> nxd_ipv6_address;
dest_ip = socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v6;
packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr = socket_ptr -> nx_tcp_socket_ipv6_addr;
data_offset = NX_PHYSICAL_HEADER + sizeof(NX_IPV6_HEADER) + sizeof(NX_TCP_HEADER);
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
#ifdef NX_ENABLE_TCPIP_OFFLOAD
interface_ptr = socket_ptr -> nx_tcp_socket_connect_interface;
if ((interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCPIP_OFFLOAD) &&
(interface_ptr -> nx_interface_tcpip_offload_handler))
{
status = _nx_tcp_socket_driver_send(socket_ptr, packet_ptr, wait_option);
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(status);
}if ((interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCPIP_OFFLOAD) && (interface_ptr -> nx_interface_tcpip_offload_handler)) { ... }
/* ... */#endif
#ifdef NX_IPSEC_ENABLE
data_offset += socket_ptr -> nx_tcp_socket_egress_sa_data_offset;/* ... */
#endif
NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_SOCKET_SEND, socket_ptr, packet_ptr, packet_ptr -> nx_packet_length, socket_ptr -> nx_tcp_socket_tx_sequence, NX_TRACE_TCP_EVENTS, 0, 0);
send_mss = socket_ptr -> nx_tcp_socket_connect_mss;
pool_ptr = packet_ptr -> nx_packet_pool_owner;
for (;;)
{
if (socket_ptr -> nx_tcp_socket_tx_window_advertised > socket_ptr -> nx_tcp_socket_tx_window_congestion)
{
tx_window_current = socket_ptr -> nx_tcp_socket_tx_window_congestion;
/* ... */
if ((socket_ptr -> nx_tcp_socket_duplicated_ack_received == 1) ||
(socket_ptr -> nx_tcp_socket_duplicated_ack_received == 2))
{
tx_window_current += (socket_ptr -> nx_tcp_socket_connect_mss << 1);
if (tx_window_current > socket_ptr -> nx_tcp_socket_tx_window_advertised)
{
tx_window_current = socket_ptr -> nx_tcp_socket_tx_window_advertised;
}if (tx_window_current > socket_ptr -> nx_tcp_socket_tx_window_advertised) { ... }
}if ((socket_ptr -> nx_tcp_socket_duplicated_ack_received == 1) || (socket_ptr -> nx_tcp_socket_duplicated_ack_received == 2)) { ... }
}if (socket_ptr -> nx_tcp_socket_tx_window_advertised > socket_ptr -> nx_tcp_socket_tx_window_congestion) { ... }
else
{
tx_window_current = socket_ptr -> nx_tcp_socket_tx_window_advertised;
}else { ... }
if (tx_window_current > socket_ptr -> nx_tcp_socket_tx_outstanding_bytes)
{
tx_window_current -= socket_ptr -> nx_tcp_socket_tx_outstanding_bytes;
}if (tx_window_current > socket_ptr -> nx_tcp_socket_tx_outstanding_bytes) { ... }
else
{
tx_window_current = 0;
}else { ... }
if (tx_window_current > send_mss)
{
tx_window_current = send_mss;
}if (tx_window_current > send_mss) { ... }
data_left = packet_ptr -> nx_packet_length;
if ((tx_window_current != 0) && (socket_ptr -> nx_tcp_socket_transmit_sent_count < socket_ptr -> nx_tcp_socket_transmit_queue_maximum))
{
if (packet_ptr -> nx_packet_length > tx_window_current)
{
adjust_packet = NX_TRUE;
}if (packet_ptr -> nx_packet_length > tx_window_current) { ... }
else if (((ALIGN_TYPE)packet_ptr -> nx_packet_prepend_ptr) & 3)
{
adjust_packet = NX_TRUE;
}else if (((ALIGN_TYPE)packet_ptr -> nx_packet_prepend_ptr) & 3) { ... }
#ifndef NX_DISABLE_PACKET_CHAIN
else if ((packet_ptr -> nx_packet_next != NX_NULL) &&
((packet_ptr -> nx_packet_length + data_offset) < pool_ptr -> nx_packet_pool_payload_size) &&
(pool_ptr -> nx_packet_pool_available > 0))
{
adjust_packet = NX_TRUE;
}else if ((packet_ptr -> nx_packet_next != NX_NULL) && ((packet_ptr -> nx_packet_length + data_offset) < pool_ptr -> nx_packet_pool_payload_size) && (pool_ptr -> nx_packet_pool_available > 0)) { ... }
else if (packet_ptr -> nx_packet_prepend_ptr == packet_ptr -> nx_packet_append_ptr)
{
current_packet = packet_ptr -> nx_packet_next;
while ((current_packet != NX_NULL) && (current_packet -> nx_packet_prepend_ptr == current_packet -> nx_packet_append_ptr))
{
current_packet = current_packet -> nx_packet_next;
}while ((current_packet != NX_NULL) && (current_packet -> nx_packet_prepend_ptr == current_packet -> nx_packet_append_ptr)) { ... }
NX_ASSERT(current_packet != NX_NULL);
if (((ALIGN_TYPE)current_packet -> nx_packet_prepend_ptr) & 3)
{
adjust_packet = NX_TRUE;
}if (((ALIGN_TYPE)current_packet -> nx_packet_prepend_ptr) & 3) { ... }
else
{
adjust_packet = NX_FALSE;
}else { ... }
}else if (packet_ptr -> nx_packet_prepend_ptr == packet_ptr -> nx_packet_append_ptr) { ... }
/* ... */#endif
else
{
adjust_packet = NX_FALSE;
}else { ... }
if (adjust_packet)
{
if (packet_ptr -> nx_packet_length > tx_window_current)
{
remaining_bytes = tx_window_current;
}if (packet_ptr -> nx_packet_length > tx_window_current) { ... }
else
{
remaining_bytes = packet_ptr -> nx_packet_length;
}else { ... }
current_packet = packet_ptr;
current_ptr = packet_ptr -> nx_packet_prepend_ptr;
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
ret = _nx_packet_allocate(pool_ptr, &send_packet,
data_offset, wait_option);
if (ret != NX_SUCCESS)
{
if (preempted == NX_TRUE)
{
tx_thread_preemption_change(_tx_thread_current_ptr, old_threshold, &old_threshold);
}if (preempted == NX_TRUE) { ... }
return(ret);
}if (ret != NX_SUCCESS) { ... }
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
NX_PACKET_DEBUG(__FILE__, __LINE__, send_packet);
while (remaining_bytes)
{
source_data_size = (ULONG)(current_packet -> nx_packet_append_ptr - current_ptr);
while (source_data_size == 0)
{
#ifndef NX_DISABLE_PACKET_CHAIN
current_packet = current_packet -> nx_packet_next;
if (current_packet == NX_NULL)
{
#endif
if (preempted == NX_TRUE)
{
tx_thread_preemption_change(_tx_thread_current_ptr, old_threshold, &old_threshold);
}if (preempted == NX_TRUE) { ... }
/* ... */
_nx_packet_release(send_packet);
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
return(NX_INVALID_PACKET);
#ifndef NX_DISABLE_PACKET_CHAIN
}if (current_packet == NX_NULL) { ... }
current_ptr = current_packet -> nx_packet_prepend_ptr;
source_data_size = (ULONG)(current_packet -> nx_packet_append_ptr - current_ptr);
#endif
}while (source_data_size == 0) { ... }
if (remaining_bytes > source_data_size)
{
copy_size = source_data_size;
}if (remaining_bytes > source_data_size) { ... }
else
{
copy_size = remaining_bytes;
}else { ... }
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
ret = _nx_packet_data_append(send_packet, current_ptr, copy_size,
pool_ptr, wait_option);
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
if (ret != NX_SUCCESS)
{
if (send_packet -> nx_packet_length == 0)
{
if (preempted == NX_TRUE)
{
tx_thread_preemption_change(_tx_thread_current_ptr, old_threshold, &old_threshold);
}if (preempted == NX_TRUE) { ... }
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
_nx_packet_release(send_packet);
return(ret);
}if (send_packet -> nx_packet_length == 0) { ... }
break;
}if (ret != NX_SUCCESS) { ... }
remaining_bytes -= copy_size;
current_ptr += copy_size;
}while (remaining_bytes) { ... }
send_packet -> nx_packet_address = packet_ptr -> nx_packet_address;
}if (adjust_packet) { ... }
else
{
send_packet = packet_ptr;
}else { ... }
send_packet -> nx_packet_ip_version = (UCHAR)(socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version);
#ifdef NX_IPSEC_ENABLE
send_packet -> nx_packet_ipsec_sa_ptr = socket_ptr -> nx_tcp_socket_egress_sa;
#endif
send_packet -> nx_packet_prepend_ptr = send_packet -> nx_packet_prepend_ptr - sizeof(NX_TCP_HEADER);
send_packet -> nx_packet_length = send_packet -> nx_packet_length + (ULONG)sizeof(NX_TCP_HEADER);
header_ptr = (NX_TCP_HEADER *)send_packet -> nx_packet_prepend_ptr;
header_ptr -> nx_tcp_header_word_0 = (((ULONG)(socket_ptr -> nx_tcp_socket_port)) << NX_SHIFT_BY_16) | (ULONG)socket_ptr -> nx_tcp_socket_connect_port;
header_ptr -> nx_tcp_acknowledgment_number = socket_ptr -> nx_tcp_socket_rx_sequence;
#ifdef NX_ENABLE_TCP_WINDOW_SCALING
window_size = socket_ptr -> nx_tcp_socket_rx_window_current >> socket_ptr -> nx_tcp_rcv_win_scale_value;
if (window_size > 0xFFFF)
{
window_size = 0xFFFF;
}if (window_size > 0xFFFF) { ... }
/* ... */#else
window_size = socket_ptr -> nx_tcp_socket_rx_window_current;
#endif
header_ptr -> nx_tcp_header_word_3 = NX_TCP_HEADER_SIZE | NX_TCP_ACK_BIT | NX_TCP_PSH_BIT | window_size;
header_ptr -> nx_tcp_header_word_4 = 0;
socket_ptr -> nx_tcp_socket_rx_sequence_acked = socket_ptr -> nx_tcp_socket_rx_sequence;
socket_ptr -> nx_tcp_socket_rx_window_last_sent = socket_ptr -> nx_tcp_socket_rx_window_current;
socket_ptr -> nx_tcp_socket_delayed_ack_timeout = _nx_tcp_ack_timer_rate;
/* ... */
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_0);
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_acknowledgment_number);
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_3);
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_4);
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
header_ptr -> nx_tcp_sequence_number = socket_ptr -> nx_tcp_socket_tx_sequence;
sequence_number = header_ptr -> nx_tcp_sequence_number;
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_sequence_number);
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (socket_ptr -> nx_tcp_socket_connect_interface -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCP_TX_CHECKSUM)
{
compute_checksum = 0;
}if (socket_ptr -> nx_tcp_socket_connect_interface -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCP_TX_CHECKSUM) { ... }
/* ... */#endif
#ifdef NX_IPSEC_ENABLE
if ((send_packet -> nx_packet_ipsec_sa_ptr != NX_NULL) && (((NX_IPSEC_SA *)(send_packet -> nx_packet_ipsec_sa_ptr)) -> nx_ipsec_sa_encryption_method != NX_CRYPTO_NONE))
{
compute_checksum = 1;
}if ((send_packet -> nx_packet_ipsec_sa_ptr != NX_NULL) && (((NX_IPSEC_SA *)(send_packet -> nx_packet_ipsec_sa_ptr)) -> nx_ipsec_sa_encryption_method != NX_CRYPTO_NONE)) { ... }
/* ... */#endif
#if defined(NX_DISABLE_TCP_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
if (compute_checksum)
#endif
{
checksum = _nx_ip_checksum_compute(send_packet, NX_PROTOCOL_TCP,
(UINT)send_packet -> nx_packet_length,
source_ip, dest_ip);
checksum = ~checksum & NX_LOWER_16_MASK;
...}
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
else
{
send_packet -> nx_packet_interface_capability_flag |= NX_INTERFACE_CAPABILITY_TCP_TX_CHECKSUM;
}else { ... }
/* ... */#endif
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
if (sequence_number != socket_ptr -> nx_tcp_socket_tx_sequence)
{
/* ... */
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
if (send_packet != packet_ptr)
{
_nx_packet_release(send_packet);
}if (send_packet != packet_ptr) { ... }
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
continue;
}if (sequence_number != socket_ptr -> nx_tcp_socket_tx_sequence) { ... }
/* ... */
if ((socket_ptr -> nx_tcp_socket_state != NX_TCP_ESTABLISHED) && (socket_ptr -> nx_tcp_socket_state != NX_TCP_CLOSE_WAIT))
{
if (preempted == NX_TRUE)
{
tx_thread_preemption_change(_tx_thread_current_ptr, old_threshold, &old_threshold);
}if (preempted == NX_TRUE) { ... }
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
if (send_packet != packet_ptr)
{
_nx_packet_release(send_packet);
}if (send_packet != packet_ptr) { ... }
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
return(NX_NOT_CONNECTED);
}if ((socket_ptr -> nx_tcp_socket_state != NX_TCP_ESTABLISHED) && (socket_ptr -> nx_tcp_socket_state != NX_TCP_CLOSE_WAIT)) { ... }
TX_DISABLE
socket_ptr -> nx_tcp_socket_tx_sequence = socket_ptr -> nx_tcp_socket_tx_sequence +
(send_packet -> nx_packet_length - (ULONG)sizeof(NX_TCP_HEADER));
TX_RESTORE
socket_ptr -> nx_tcp_socket_zero_window_probe_has_data = NX_FALSE;
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_4);
header_ptr -> nx_tcp_header_word_4 = (checksum << NX_SHIFT_BY_16);
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_4);
data_left -= (send_packet -> nx_packet_length - (ULONG)sizeof(NX_TCP_HEADER));
if (socket_ptr -> nx_tcp_socket_transmit_sent_head)
{
(socket_ptr -> nx_tcp_socket_transmit_sent_tail) -> nx_packet_union_next.nx_packet_tcp_queue_next = send_packet;
socket_ptr -> nx_tcp_socket_transmit_sent_tail = send_packet;
}if (socket_ptr -> nx_tcp_socket_transmit_sent_head) { ... }
else
{
socket_ptr -> nx_tcp_socket_transmit_sent_head = send_packet;
socket_ptr -> nx_tcp_socket_transmit_sent_tail = send_packet;
socket_ptr -> nx_tcp_socket_timeout = socket_ptr -> nx_tcp_socket_timeout_rate;
socket_ptr -> nx_tcp_socket_timeout_retries = 0;
socket_ptr -> nx_tcp_socket_tx_outstanding_bytes = 0;
}else { ... }
send_packet -> nx_packet_union_next.nx_packet_tcp_queue_next = (NX_PACKET *)NX_PACKET_ENQUEUED;
socket_ptr -> nx_tcp_socket_transmit_sent_count++;
socket_ptr -> nx_tcp_socket_tx_outstanding_bytes +=
(send_packet -> nx_packet_length - (ULONG)sizeof(NX_TCP_HEADER));
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_packets_sent++;
ip_ptr -> nx_ip_tcp_bytes_sent += send_packet -> nx_packet_length - (ULONG)sizeof(NX_TCP_HEADER);
socket_ptr -> nx_tcp_socket_packets_sent++;
socket_ptr -> nx_tcp_socket_bytes_sent += send_packet -> nx_packet_length - (ULONG)sizeof(NX_TCP_HEADER);/* ... */
#endif
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_TCP_DATA_SEND, ip_ptr, socket_ptr, send_packet, socket_ptr -> nx_tcp_socket_tx_sequence - (send_packet -> nx_packet_length - sizeof(NX_TCP_HEADER)), NX_TRACE_INTERNAL_EVENTS, 0, 0);
#ifndef NX_DISABLE_IPV4
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4)
{
_nx_ip_packet_send(ip_ptr, send_packet,
socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v4,
socket_ptr -> nx_tcp_socket_type_of_service,
socket_ptr -> nx_tcp_socket_time_to_live,
NX_IP_TCP,
socket_ptr -> nx_tcp_socket_fragment_enable,
socket_ptr -> nx_tcp_socket_next_hop_address);
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6)
{
_nx_ipv6_packet_send(ip_ptr,
send_packet,
NX_PROTOCOL_TCP,
send_packet -> nx_packet_length,
ip_ptr -> nx_ipv6_hop_limit,
socket_ptr -> nx_tcp_socket_ipv6_addr -> nxd_ipv6_address,
socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v6);
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
if (data_left == 0)
{
if (send_packet != packet_ptr)
{
_nx_packet_release(packet_ptr);
}if (send_packet != packet_ptr) { ... }
if (preempted == NX_TRUE)
{
tx_thread_preemption_change(_tx_thread_current_ptr, old_threshold, &old_threshold);
}if (preempted == NX_TRUE) { ... }
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
return(NX_SUCCESS);
}if (data_left == 0) { ... }
else
{
current_packet = packet_ptr;
remaining_bytes = packet_ptr -> nx_packet_length - data_left;
#ifndef NX_DISABLE_PACKET_CHAIN
while (remaining_bytes >
(UINT)(current_packet -> nx_packet_append_ptr - current_packet -> nx_packet_prepend_ptr))
{
packet_ptr -> nx_packet_length -= (ULONG)((ALIGN_TYPE)current_packet -> nx_packet_append_ptr - (ALIGN_TYPE)current_packet -> nx_packet_prepend_ptr);
remaining_bytes -= (ULONG)((ALIGN_TYPE)current_packet -> nx_packet_append_ptr - (ALIGN_TYPE)current_packet -> nx_packet_prepend_ptr);
current_packet -> nx_packet_append_ptr = (UCHAR *)(((ALIGN_TYPE)current_packet -> nx_packet_append_ptr) & (ALIGN_TYPE)(~3));
current_packet -> nx_packet_prepend_ptr = current_packet -> nx_packet_append_ptr;
current_packet = current_packet -> nx_packet_next;
}while (remaining_bytes > (UINT)(current_packet -> nx_packet_append_ptr - current_packet -> nx_packet_prepend_ptr)) { ... }
/* ... */#endif
packet_ptr -> nx_packet_length -= remaining_bytes;
current_packet -> nx_packet_prepend_ptr += remaining_bytes;
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
}else { ... }
}if ((tx_window_current != 0) && (socket_ptr -> nx_tcp_socket_transmit_sent_count < socket_ptr -> nx_tcp_socket_transmit_queue_maximum)) { ... }
else if ((wait_option) && (_tx_thread_current_ptr != &(ip_ptr -> nx_ip_thread)))
{
_tx_thread_current_ptr -> tx_thread_additional_suspend_info = (VOID *)packet_ptr;
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
socket_ptr -> nx_tcp_socket_transmit_suspended_count++;
if (socket_ptr -> nx_tcp_socket_zero_window_probe_has_data == NX_FALSE)
{
socket_ptr -> nx_tcp_socket_zero_window_probe_has_data = NX_TRUE;
socket_ptr -> nx_tcp_socket_zero_window_probe_data = *(packet_ptr -> nx_packet_prepend_ptr);
socket_ptr -> nx_tcp_socket_zero_window_probe_sequence = socket_ptr -> nx_tcp_socket_tx_sequence;
socket_ptr -> nx_tcp_socket_zero_window_probe_failure = 0;
}if (socket_ptr -> nx_tcp_socket_zero_window_probe_has_data == NX_FALSE) { ... }
if (preempted == NX_FALSE)
{
UINT ip_thread_priority;
tx_thread_info_get(&ip_ptr -> nx_ip_thread, NX_NULL, NX_NULL, NX_NULL, &ip_thread_priority, NX_NULL,
NX_NULL, NX_NULL, NX_NULL);
tx_thread_preemption_change(_tx_thread_current_ptr, ip_thread_priority, &old_threshold);
preempted = NX_TRUE;
}if (preempted == NX_FALSE) { ... }
_nx_tcp_socket_thread_suspend(&(socket_ptr -> nx_tcp_socket_transmit_suspension_list), _nx_tcp_transmit_cleanup, socket_ptr, &(ip_ptr -> nx_ip_protection), wait_option);
if (_tx_thread_current_ptr -> tx_thread_suspend_status)
{
tx_thread_preemption_change(_tx_thread_current_ptr, old_threshold, &old_threshold);
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
return(_tx_thread_current_ptr -> tx_thread_suspend_status);
}if (_tx_thread_current_ptr -> tx_thread_suspend_status) { ... }
}else if ((wait_option) && (_tx_thread_current_ptr != &(ip_ptr -> nx_ip_thread))) { ... }
else
{
if (socket_ptr -> nx_tcp_socket_zero_window_probe_has_data == NX_FALSE)
{
socket_ptr -> nx_tcp_socket_zero_window_probe_has_data = NX_TRUE;
socket_ptr -> nx_tcp_socket_zero_window_probe_data = *(packet_ptr -> nx_packet_prepend_ptr);
socket_ptr -> nx_tcp_socket_zero_window_probe_sequence = socket_ptr -> nx_tcp_socket_tx_sequence;
socket_ptr -> nx_tcp_socket_zero_window_probe_failure = 0;
}if (socket_ptr -> nx_tcp_socket_zero_window_probe_has_data == NX_FALSE) { ... }
if (socket_ptr -> nx_tcp_socket_transmit_sent_count < socket_ptr -> nx_tcp_socket_transmit_queue_maximum)
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
return(NX_WINDOW_OVERFLOW);
}if (socket_ptr -> nx_tcp_socket_transmit_sent_count < socket_ptr -> nx_tcp_socket_transmit_queue_maximum) { ... }
else
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
return(NX_TX_QUEUE_DEPTH);
}else { ... }
}else { ... }
}for (;;) { ... }
}{ ... }