Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 561B1C7EE22 for ; Mon, 8 May 2023 17:16:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 598DD85F7F; Mon, 8 May 2023 19:16:09 +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="q2IX6/Hb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5885585F3D; Mon, 8 May 2023 19:16:06 +0200 (CEST) Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) (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 947998472A for ; Mon, 8 May 2023 19:16:03 +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=3US5ZZAkKBjwbgkmpgllwemmejc.amks-Zmmrjgqrq.bclv.bc@flex--dimorinny.bounces.google.com Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-559d35837bbso91287817b3.3 for ; Mon, 08 May 2023 10:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683566161; x=1686158161; 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=jE/yD2GXrl1fTZwM4VoEfyvlaBj4jxtqyzrp5oD8vQk=; b=q2IX6/Hb0AnDKvACuq3dFpuZFKmtQYe3P7bVuMakOY06jfchPtYIJxhVHS6Ubsi93i r2l1u9lev4cAqBVMiW4RUtPuSuXgkQb1HxQEyYFnvDbobXMawqSC2zIEiSwBTVVF+RZd uSiqUQjZxJHbao9f77XmQ4RVvdpa9NOXta3J3Chi3WtrJWsT3+JNB4S3ccaEhQwC3bO4 sy5dP2Ymav2pavqyxoPEYtGHWKdSOZvJZF1mSw1JXnbn5fzIIIsy6gDrB5uzV3LNf/OI /yJpRNeOSfsVTVztTOn2/uA7+cFpiUb3O3u0NUwOStz/I6Hf1Na8R+RaODwmZm/S5vj1 kohw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683566161; x=1686158161; 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=jE/yD2GXrl1fTZwM4VoEfyvlaBj4jxtqyzrp5oD8vQk=; b=C03NzuQzoKi+Qmcr2B3ttXjUOMH/Tgo79UiCDa2MX4VbJgxHFvyQZA7R5fBt1ViTEY f/OSKZOSFpSexpKO7xMgJulFlbMdUdhqtdi667gKQepUxOpYBKtIGriq2SHaBx7l+FZe j0KpcRB04X9crs8/dNK7HT1OOi4ohfVHsewBRtWAXYXZWvv+GPgaXdkyMzB8/c6rr6Oe NISF0pvPwZU68crVpBNCTyg8TSlInoX2LHra9Qtx2tBxvnAxqfa/63yz3DtAyRcwiMym fjJI8W9N0+S6hTvTjB2TdVVY8at6iRDJsaN6dwCVYFPBNSgDMreHE9Qqhe7Y6c6aT/w9 aM0Q== X-Gm-Message-State: AC+VfDwh1OqOldG1x/KxMjRNGwz34AV+/2ky5BsGV/OZaRDiLNSrjFN4 k8ZwxxvWXN79AL71D7Mg83/948Sdsn+NVAQ5IIh+P5fMqMOTowOdNr+H616gIOIjgrR/VimcACz qyYMYSHmnXRkiwSv6pTeshA7tqLePR9rWLIUK+X4esHBc528VkgQvnGeBMZRPVXKrzUY= X-Google-Smtp-Source: ACHHUZ5+tKskY0ilqgcfS8K8+YpoQ4Awufd0UftsSSk1JoC5KGPFmGm04b7AfWaH3U41bAo94YvlG7jnmcNlKkY= X-Received: from dimorinny0.lon.corp.google.com ([2a00:79e0:d:209:f357:b9b:9cec:e681]) (user=dimorinny job=sendgmr) by 2002:a81:ae54:0:b0:559:f89f:bc81 with SMTP id g20-20020a81ae54000000b00559f89fbc81mr6732832ywk.6.1683566161331; Mon, 08 May 2023 10:16:01 -0700 (PDT) Date: Mon, 8 May 2023 18:15:23 +0100 In-Reply-To: <20230508171525.1082432-1-dimorinny@google.com> Mime-Version: 1.0 References: <20230508171525.1082432-1-dimorinny@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230508171525.1082432-4-dimorinny@google.com> Subject: [PATCH 4/6] net: add fastboot TCP6 support From: Dmitrii Merkurev To: u-boot@lists.denx.de Cc: rammuthiah@google.com, Dmitrii Merkurev , Ying-Chun Liu , Simon Glass Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 =D0=A1=D1=81: Joe Hershberger =D0=A1=D1=81: Ramon Fried --- 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__ =20 /** - * Wait for incoming tcp fastboot comands. + * Wait for incoming TCP fastboot comands. */ void fastboot_tcp_start_server(void); =20 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 =20 static char command[FASTBOOT_COMMAND_LEN] =3D {0}; static char response[FASTBOOT_RESPONSE_LEN] =3D {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 =3D FASTBOOT_CLOSED; =20 +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 =3D curr_tcp_ack_num; const u32 response_ack_num =3D curr_tcp_seq_num + (curr_request_len > 0 ? curr_request_len : 1); =20 +#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 uch= ar *data, unsigned int uchar *pkt =3D net_get_async_tx_pkt_buf(); =20 memset(pkt, '\0', PKTSIZE); - pkt +=3D net_eth_hdr_size() + IP_TCP_HDR_SIZE + TCP_TSOPT_SIZE + 2; + pkt +=3D net_eth_hdr_size() + ip_header_size + TCP_HDR_SIZE + TCP_TSOPT_S= IZE + 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 =3D net_get_async_tx_pkt_buf(); =20 memset(pkt, '\0', PKTSIZE); - pkt +=3D net_eth_hdr_size() + IP_TCP_HDR_SIZE + TCP_TSOPT_SIZE + 2; + pkt +=3D net_eth_hdr_size() + ip_header_size + TCP_HDR_SIZE + TCP_TSOPT_S= IZE + 2; // Put first 8 bytes as a big endian message length memcpy(pkt, &len_be, 8); pkt +=3D 8; @@ -68,10 +82,9 @@ static void fastboot_tcp_send_message(const char *messag= e, unsigned int len) memset(pkt, '\0', PKTSIZE); } =20 -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 dp= ort, case FASTBOOT_CLOSED: if (tcp_push) { if (len !=3D handshake_length || - strlen(pkt) !=3D handshake_length || memcmp(pkt, handshake, handshake_length) !=3D 0) { fastboot_tcp_reset(); break; @@ -111,18 +123,25 @@ static void fastboot_tcp_handler_ipv4(uchar *pkt, u16= dport, pkt +=3D 8; =20 // Only single packet messages are supported ATM - if (strlen(pkt) !=3D command_size) { + if (len !=3D command_size) { fastboot_tcp_reset(); break; } strlcpy(command, pkt, len + 1); fastboot_command_id =3D fastboot_handle_command(command, response); fastboot_tcp_send_message(response, strlen(response)); - fastboot_handle_boot(fastboot_command_id, - strncmp("OKAY", response, 4) =3D=3D 0); + + command_handled_id =3D fastboot_command_id; + command_handled_success =3D strncmp("OKAY", response, 4) =3D=3D 0; } break; case FASTBOOT_DISCONNECTING: + if (command_handled_success) { + fastboot_handle_boot(command_handled_id, command_handled_success); + command_handled_id =3D 0; + command_handled_success =3D false; + } + if (tcp_push) state =3D FASTBOOT_CLOSED; break; @@ -137,10 +156,41 @@ static void fastboot_tcp_handler_ipv4(uchar *pkt, u16= dport, curr_request_len =3D 0; } =20 +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 =3D false; + ip_header_size =3D 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 =3D true; + ip_header_size =3D 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); =20 + 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 } --=20 2.40.1.521.gf1e218fcd8-goog