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 4C84BEB64DD for ; Tue, 25 Jul 2023 21:57:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C596B867FC; Tue, 25 Jul 2023 23:57:25 +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="6WCBCM2r"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0049B86785; Tue, 25 Jul 2023 23:57:18 +0200 (CEST) Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) (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 1AB02867F1 for ; Tue, 25 Jul 2023 23:57:15 +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=3OkXAZAkKBvEWbfhkbggrZhhZeX.Vhfn-Uhhmeblml.WXgq.WX@flex--dimorinny.bounces.google.com Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-314275b653eso2868431f8f.1 for ; Tue, 25 Jul 2023 14:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690322234; x=1690927034; 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=cER4JhGQxIila+xlRiZtejLNmYSTJYqM6ENdXUgl7xU=; b=6WCBCM2rgJJYhcwSbYOlu4pDClYn/ewniziZEz3NV5LaEHoZsgcovzr61sHiekK4qq aHrkrIUflpUXBAlhXzLLeZacGOKd5D4DOimDrPWzgyRvL0/B8mK6oKQlKMA8JbHyAOnW LSrUDWPk3Ao3wDheLqUIhqu46ZYSb3NRziZmVOWj1KfBTYML4t+COryyyvivLJB+0UHy Ra81xCCJS52XNUp66gTGvLwl+adzxji0BMcHs28lczAK7LeZmKVp7cVKJ8IxTD93W92y IE0qkHgsmvPFv4WzILj3iJZ6quGG6CroK01ByJNlgIOiaopDPY5B0BzuJ9mdNvPYPQ0w 8vDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690322234; x=1690927034; 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=cER4JhGQxIila+xlRiZtejLNmYSTJYqM6ENdXUgl7xU=; b=d6jGzhnxJThmkxl1Bimv+T7Npby4w7KrFyT3wOGVlRXfOc1ZbpU8W8kvwp7zLIT+q1 B6jwSwhF1R+k+Z/SGTmd0H9X4819mAcZ1ZRYodi33Sn5qmnz3Pkj+G+EQy1ddRJ+cGEF klgo33IKI5I8ksmU8EzPjerWkQDc+XcLq0n1M8b+eJR2pXfsL2+M1Yr0KIFGaRFfae98 M6LJWoAdm45SdyeZm+F5EYOM8jBw138jaOK4YTeS+TiG2G+/hHThAa3RcVHys0eQco9I IN/AT9ujcgb1B9xnJJHPxtyE/YczEP8hVtErF5oEFN0PZVjV/HMHm8+aNxBLa8MinQ9b iP6w== X-Gm-Message-State: ABy/qLaT1IZ8MExHch94HHdoqV8W7x1KBkAgl6xE124j+uUPlo62Le8i pFne8pukvM636lAsrIiMwncNaCBMsJH5NpK3tCN2MfYHyTWilw/HDUg0BjxNd/Jz16l9lNDl1HN rY57AQ4ZaiYhP33s0wio7cCcXipXkkPo+ky3UhnZ33itwU/yxPOH7NMMjCEPyh3D+uXU= X-Google-Smtp-Source: APBJJlGNRHYIkJKwy4na3jQn63juLsFWLpdaLQ8a58KE6b5CY1ArY9JB5deSHBfblpgQPEOc/IS8aY/D2SzlylM= X-Received: from dimorinny0.lon.corp.google.com ([2a00:79e0:d:209:3ee0:2483:5af7:8f8e]) (user=dimorinny job=sendgmr) by 2002:a5d:54c5:0:b0:314:3678:6479 with SMTP id x5-20020a5d54c5000000b0031436786479mr495wrv.5.1690322234437; Tue, 25 Jul 2023 14:57:14 -0700 (PDT) Date: Tue, 25 Jul 2023 22:56:55 +0100 In-Reply-To: <20230725215658.2118831-1-dimorinny@google.com> Mime-Version: 1.0 References: <20230725215658.2118831-1-dimorinny@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230725215658.2118831-4-dimorinny@google.com> Subject: [PATCH v3 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 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 Reviewed-by: Ying-Chun Liu (PaulLiu) Reviewed-by: Simon Glass --- include/net/fastboot_tcp.h | 2 +- net/fastboot_tcp.c | 69 ++++++++++++++++++++++++++++++++------ 2 files changed, 59 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..8d6d3270f6 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,29 @@ 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 (is_ipv6) { + net_send_tcp_packet6(len, htons(curr_sport), htons(curr_dport), + action, response_seq_num, response_ack_num); + return; + } + net_send_tcp_packet(len, htons(curr_sport), htons(curr_dport), action, response_seq_num, response_ack_num); } @@ -47,7 +60,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 +72,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 +81,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 +100,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 +122,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 +155,39 @@ 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); +} + +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); +} + 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 (IS_ENABLED(CONFIG_IPV6)) { + printf("Listening for fastboot command on %pI6\n", &net_ip6); + net_set_tcp_handler6(fastboot_tcp_handler_ipv6); + } } --=20 2.41.0.487.g6d72f3e995-goog