From patchwork Wed May 10 16:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitrii Merkurev X-Patchwork-Id: 1779641 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20221208 header.b=AcQVCDDV; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QGhB21Kqkz214S for ; Thu, 11 May 2023 03:00:58 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AECDA86076; Wed, 10 May 2023 19:00:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="AcQVCDDV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DF5E386068; Wed, 10 May 2023 19:00:18 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 87C6B86073 for ; Wed, 10 May 2023 19:00:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3m81bZAkKBs4x268B277I08805y.w86E-v88D52CDC.xy7H.xy@flex--dimorinny.bounces.google.com Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9a6f15287eso11417037276.1 for ; Wed, 10 May 2023 10:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683738011; x=1686330011; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=Boef0/kyv44xsg3XWmymCHfksKtwWOUURw9sPooLL+c=; b=AcQVCDDV7MN1fPbR/jyu5P6mHLMAIeq1SOPM38zSKdL3IAY31Kp1u2EiCz2U5kSakq xqShloFL0hA6x13gBkIPYcllOXpPVBNvZa6PzN/cSi8Iasr/lxJCh2dVenETe/evZF2V ShFYYXBcbrdsw+pPKkdkpygolPw9a/Vi0B/nCTxaQr0CJIwicOEY9ydBYEzoX54rTAT+ fWipJ0O3QiEf5M5eBQmeMBnhFYz6wRQy3VUe9sXqFPTvYOxZ13KV+JCS3/XX3SXTo+y2 dOM443xPEsRtTbi9URmnwRwXnVhSAx76zAhlW3pGC4zenJzHPA/Aw/Vvs0XSiT2fkLQ8 9PxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683738011; x=1686330011; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=Boef0/kyv44xsg3XWmymCHfksKtwWOUURw9sPooLL+c=; b=kfkODIUlskluiNrijFe22kCBgUpkXUhsA+xBOEtnnquCNddqm3eMaJ0vvscBQssbIU W6vy2gD28asMNKfJnuzxYvlUTyE/BIF0mjN9gSfLHWsiPlc2zjAvEHVtwKThcs5r1NUM dOX/5Bfl+sx0BGMbAnFqooLzrvmDhXfV//QN9AzmuDreHdYVJWGJMCXmdc/N/GcOY/hF pZflBJGgYsVHb8G1DQ/qTgtaH9AxdqRBR8pKqtVO6JxGueuF95KQnG+MexMT1338EKaG 3pupGn1NIP9brpiQBWXzwf/l86FD+LCZlIrJ01rAX2huFqgrAkdaSRbZ9pBSb+AJZHq1 9Lyg== X-Gm-Message-State: AC+VfDzyfXgXfVAXUvS7OYnW4RRHAgPSGkmVIpv3pyOENuFdm9vxE9R0 q6UAbi2Q6OKXE+ZMWBCqMPR0pEnSw4a5ib4toYdYDohru0hwdpZIh8k7k0uIa4GvWRvnY1XVAn1 4Lj0zrgcFVkFRSWJAOLeUy7uPWMVUWSNdcn8htHdgdn62XZdmho/SRBe8vm767mNiLa4= X-Google-Smtp-Source: ACHHUZ7fAwCeSxTZjYlLf4uIO5La0uK6mnVq1CRPel6mxlj8O57gTjmK7NVU7GpzlpmI9T7SGgXUSDOQa3rhFQY= X-Received: from dimorinny0.lon.corp.google.com ([2a00:79e0:d:209:8054:7d60:263c:94b9]) (user=dimorinny job=sendgmr) by 2002:a25:1283:0:b0:b9a:672d:23c9 with SMTP id 125-20020a251283000000b00b9a672d23c9mr11088810ybs.0.1683738011070; Wed, 10 May 2023 10:00:11 -0700 (PDT) Date: Wed, 10 May 2023 17:59:57 +0100 In-Reply-To: <20230510165959.2228978-1-dimorinny@google.com> Mime-Version: 1.0 References: <20230510165959.2228978-1-dimorinny@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230510165959.2228978-4-dimorinny@google.com> Subject: [PATCH v2 4/6] net: add fastboot TCP6 support From: Dmitrii Merkurev To: u-boot@lists.denx.de Cc: rammuthiah@google.com, rfried.dev@gmail.com, Dmitrii Merkurev , Ying-Chun Liu , Simon Glass X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean fastboot tcp command remains the same, but started listening IP6 in case it's enabled. Signed-off-by: Dmitrii Merkurev Cc: Ying-Chun Liu (PaulLiu) Cc: Simon Glass Сс: Joe Hershberger Сс: Ramon Fried Reviewed-by: Ying-Chun Liu (PaulLiu) --- include/net/fastboot_tcp.h | 2 +- net/fastboot_tcp.c | 72 ++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/include/net/fastboot_tcp.h b/include/net/fastboot_tcp.h index 6cf29d52e9..98986fa10a 100644 --- a/include/net/fastboot_tcp.h +++ b/include/net/fastboot_tcp.h @@ -7,7 +7,7 @@ #define __NET_FASTBOOT_TCP_H__ /** - * Wait for incoming tcp fastboot comands. + * Wait for incoming TCP fastboot comands. */ void fastboot_tcp_start_server(void); diff --git a/net/fastboot_tcp.c b/net/fastboot_tcp.c index 2eb52ea256..d93b52ede5 100644 --- a/net/fastboot_tcp.c +++ b/net/fastboot_tcp.c @@ -6,8 +6,10 @@ #include #include #include +#include #include #include +#include static char command[FASTBOOT_COMMAND_LEN] = {0}; static char response[FASTBOOT_RESPONSE_LEN] = {0}; @@ -20,18 +22,30 @@ static u16 curr_dport; static u32 curr_tcp_seq_num; static u32 curr_tcp_ack_num; static unsigned int curr_request_len; +static bool is_ipv6; +static size_t ip_header_size; static enum fastboot_tcp_state { FASTBOOT_CLOSED, FASTBOOT_CONNECTED, FASTBOOT_DISCONNECTING } state = FASTBOOT_CLOSED; +static int command_handled_id; +static bool command_handled_success; + static void fastboot_tcp_answer(u8 action, unsigned int len) { const u32 response_seq_num = curr_tcp_ack_num; const u32 response_ack_num = curr_tcp_seq_num + (curr_request_len > 0 ? curr_request_len : 1); +#if defined(CONFIG_IPV6) + if (is_ipv6) { + net_send_tcp_packet6(len, htons(curr_sport), htons(curr_dport), + action, response_seq_num, response_ack_num); + return; + } +#endif net_send_tcp_packet(len, htons(curr_sport), htons(curr_dport), action, response_seq_num, response_ack_num); } @@ -47,7 +61,7 @@ static void fastboot_tcp_send_packet(u8 action, const uchar *data, unsigned int uchar *pkt = net_get_async_tx_pkt_buf(); memset(pkt, '\0', PKTSIZE); - pkt += net_eth_hdr_size() + IP_TCP_HDR_SIZE + TCP_TSOPT_SIZE + 2; + pkt += net_eth_hdr_size() + ip_header_size + TCP_HDR_SIZE + TCP_TSOPT_SIZE + 2; memcpy(pkt, data, len); fastboot_tcp_answer(action, len); memset(pkt, '\0', PKTSIZE); @@ -59,7 +73,7 @@ static void fastboot_tcp_send_message(const char *message, unsigned int len) uchar *pkt = net_get_async_tx_pkt_buf(); memset(pkt, '\0', PKTSIZE); - pkt += net_eth_hdr_size() + IP_TCP_HDR_SIZE + TCP_TSOPT_SIZE + 2; + pkt += net_eth_hdr_size() + ip_header_size + TCP_HDR_SIZE + TCP_TSOPT_SIZE + 2; // Put first 8 bytes as a big endian message length memcpy(pkt, &len_be, 8); pkt += 8; @@ -68,10 +82,9 @@ static void fastboot_tcp_send_message(const char *message, unsigned int len) memset(pkt, '\0', PKTSIZE); } -static void fastboot_tcp_handler_ipv4(uchar *pkt, u16 dport, - struct in_addr sip, u16 sport, - u32 tcp_seq_num, u32 tcp_ack_num, - u8 action, unsigned int len) +static void fastboot_tcp_handler(uchar *pkt, u16 dport, u16 sport, + u32 tcp_seq_num, u32 tcp_ack_num, + u8 action, unsigned int len) { int fastboot_command_id; u64 command_size; @@ -88,7 +101,6 @@ static void fastboot_tcp_handler_ipv4(uchar *pkt, u16 dport, case FASTBOOT_CLOSED: if (tcp_push) { if (len != handshake_length || - strlen(pkt) != handshake_length || memcmp(pkt, handshake, handshake_length) != 0) { fastboot_tcp_reset(); break; @@ -111,18 +123,25 @@ static void fastboot_tcp_handler_ipv4(uchar *pkt, u16 dport, pkt += 8; // Only single packet messages are supported ATM - if (strlen(pkt) != command_size) { + if (len != command_size) { fastboot_tcp_reset(); break; } strlcpy(command, pkt, len + 1); fastboot_command_id = fastboot_handle_command(command, response); fastboot_tcp_send_message(response, strlen(response)); - fastboot_handle_boot(fastboot_command_id, - strncmp("OKAY", response, 4) == 0); + + command_handled_id = fastboot_command_id; + command_handled_success = strncmp("OKAY", response, 4) == 0; } break; case FASTBOOT_DISCONNECTING: + if (command_handled_success) { + fastboot_handle_boot(command_handled_id, command_handled_success); + command_handled_id = 0; + command_handled_success = false; + } + if (tcp_push) state = FASTBOOT_CLOSED; break; @@ -137,10 +156,41 @@ static void fastboot_tcp_handler_ipv4(uchar *pkt, u16 dport, curr_request_len = 0; } +static void fastboot_tcp_handler_ipv4(uchar *pkt, u16 dport, + struct in_addr sip, u16 sport, + u32 tcp_seq_num, u32 tcp_ack_num, + u8 action, unsigned int len) +{ + is_ipv6 = false; + ip_header_size = IP_HDR_SIZE; + fastboot_tcp_handler(pkt, dport, sport, + tcp_seq_num, tcp_ack_num, + action, len); +} + +#if defined(CONFIG_IPV6) +static void fastboot_tcp_handler_ipv6(uchar *pkt, u16 dport, + struct in6_addr sip, u16 sport, + u32 tcp_seq_num, u32 tcp_ack_num, + u8 action, unsigned int len) +{ + is_ipv6 = true; + ip_header_size = IP6_HDR_SIZE; + fastboot_tcp_handler(pkt, dport, sport, + tcp_seq_num, tcp_ack_num, + action, len); +} +#endif + void fastboot_tcp_start_server(void) { printf("Using %s device\n", eth_get_name()); - printf("Listening for fastboot command on tcp %pI4\n", &net_ip); + printf("Listening for fastboot command on tcp %pI4\n", &net_ip); tcp_set_tcp_handler(fastboot_tcp_handler_ipv4); + +#if defined(CONFIG_IPV6) + printf("Listening for fastboot command on %pI6\n", &net_ip6); + net_set_tcp_handler6(fastboot_tcp_handler_ipv6); +#endif }