From 8d6b28eee55ed440c2e8ed374c955e72e2714db0 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 12 Aug 2017 17:02:56 +0200 Subject: [PATCH] Fixed sequence number of initial TCP ACK packet on tcp_connect. So far the sequence number for the first packet after the initial SYN packet was calculated directly before returning from tcp_connect. This is however far to late as the ACK packet to be send as response for the SYN,ACK packet sent by the server already needs that sequence number. Therefore it is now calculated right after a successful reception of the SYN,ACK packet is detected. --- ip65/tcp.s | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/ip65/tcp.s b/ip65/tcp.s index 89b2d5e..3b3dfa1 100644 --- a/ip65/tcp.s +++ b/ip65/tcp.s @@ -185,7 +185,20 @@ tcp_listen: cmp tcp_state beq @listen_loop - jmp tcp_connection_established +tcp_connection_established: + ; inc the sequence number to cover the SYN we have sent + ldax #tcp_connect_sequence_number + stax acc32 + ldax #$01 + jsr add_16_32 + +set_expected_ack: + ; set the expected ack number with current seq number + ldx #3 +: lda tcp_connect_sequence_number,x + sta tcp_connect_expected_ack_number,x + dex + bpl :- rts ; make outbound tcp connection @@ -278,20 +291,6 @@ tcp_connect: sec ; if we got here, then the other side sent a RST or FIN, so signal an error to the caller rts @was_accepted: -tcp_connection_established: - ; inc the sequence number to cover the SYN we have sent - ldax #tcp_connect_sequence_number - stax acc32 - ldax #$01 - jsr add_16_32 - -set_expected_ack: - ; set the expected ack number with current seq number - ldx #3 -: lda tcp_connect_sequence_number,x - sta tcp_connect_expected_ack_number,x - dex - bpl :- clc rts @@ -726,6 +725,8 @@ tcp_process: ldax #$0001 jsr add_16_32 ; increment the ACK counter by 1, for the SYN we just received + jsr tcp_connection_established + lda #tcp_cxn_state_established sta tcp_state