[PATCH v2 4/6] net: add fastboot TCP6 support
Dmitrii Merkurev
dimorinny at google.com
Wed Jul 26 00:06:09 CEST 2023
>
> Can you use if() here?
Yes, fixed
On Sun, Jul 23, 2023 at 4:48 AM Simon Glass <sjg at chromium.org> wrote:
> Hi Dmitrii,
>
> On Wed, 10 May 2023 at 11:00, Dmitrii Merkurev <dimorinny at google.com>
> wrote:
> >
> > fastboot tcp command remains the same, but started
> > listening IP6 in case it's enabled.
> >
> > Signed-off-by: Dmitrii Merkurev <dimorinny at google.com>
> > Cc: Ying-Chun Liu (PaulLiu) <paul.liu at linaro.org>
> > Cc: Simon Glass <sjg at chromium.org>
> > Сс: Joe Hershberger <joe.hershberger at ni.com>
> > Сс: Ramon Fried <rfried.dev at gmail.com>
> > ---
> > 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 <common.h>
> > #include <fastboot.h>
> > #include <net.h>
> > +#include <net6.h>
> > #include <net/fastboot_tcp.h>
> > #include <net/tcp.h>
> > +#include <net/tcp6.h>
> >
> > 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)
>
> Can you use if() here?
>
> > + 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);
> > }
> >
>
> [..]
> +
> > 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
>
> and here. This needs some thought as we don't want to add #if to C
> code where possible.
>
> Regards,
> Simon
>
More information about the U-Boot
mailing list