* [PATCH 0/3] tftp: prepare for picotcp
@ 2015-06-28 16:19 Antony Pavlov
2015-06-28 16:19 ` [PATCH 1/3] fs/tftp: handle incoming packets in the separate tftp_recv() function Antony Pavlov
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Antony Pavlov @ 2015-06-28 16:19 UTC (permalink / raw)
To: barebox
This patchseries makes it much easier to run barebox tftp client
on top of picotcp network stack in the future.
Antony Pavlov (3):
fs/tftp: handle incoming packets in the separate tftp_recv() function
tftp_recv(): according to RFC1350 minimal tftp packet length is 4
bytes
tftp_recv(): handle opcode field in a more natural way
fs/tftp.c | 47 ++++++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 21 deletions(-)
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] fs/tftp: handle incoming packets in the separate tftp_recv() function
2015-06-28 16:19 [PATCH 0/3] tftp: prepare for picotcp Antony Pavlov
@ 2015-06-28 16:19 ` Antony Pavlov
2015-06-28 16:19 ` [PATCH 2/3] tftp_recv(): according to RFC1350 minimal tftp packet length is 4 bytes Antony Pavlov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Antony Pavlov @ 2015-06-28 16:19 UTC (permalink / raw)
To: barebox
The separation of incoming packets handling makes it much easier
to run barebox tftp client on top of picotcp network stack in the future.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
fs/tftp.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/fs/tftp.c b/fs/tftp.c
index 72e4983..d970c60 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -253,15 +253,12 @@ static void tftp_timer_reset(struct file_priv *priv)
priv->progress_timeout = priv->resend_timeout = get_time_ns();
}
-static void tftp_handler(void *ctx, char *packet, unsigned len)
+static void tftp_recv(struct file_priv *priv,
+ uint8_t *pkt, unsigned len, uint16_t uh_sport)
{
- struct file_priv *priv = ctx;
uint16_t proto;
uint16_t *s;
- char *pkt = net_eth_to_udp_payload(packet);
- struct udphdr *udp = net_eth_to_udphdr(packet);
- len = net_eth_to_udplen(packet);
if (len < 2)
return;
@@ -296,14 +293,14 @@ static void tftp_handler(void *ctx, char *packet, unsigned len)
priv->state = STATE_DONE;
break;
}
- priv->tftp_con->udp->uh_dport = udp->uh_sport;
+ priv->tftp_con->udp->uh_dport = uh_sport;
priv->state = STATE_WDATA;
break;
case TFTP_OACK:
tftp_parse_oack(priv, pkt, len);
- priv->server_port = ntohs(udp->uh_sport);
- priv->tftp_con->udp->uh_dport = udp->uh_sport;
+ priv->server_port = ntohs(uh_sport);
+ priv->tftp_con->udp->uh_dport = uh_sport;
if (priv->push) {
/* send first block */
@@ -326,8 +323,8 @@ static void tftp_handler(void *ctx, char *packet, unsigned len)
if (priv->state == STATE_RRQ || priv->state == STATE_OACK) {
/* first block received */
priv->state = STATE_RDATA;
- priv->tftp_con->udp->uh_dport = udp->uh_sport;
- priv->server_port = ntohs(udp->uh_sport);
+ priv->tftp_con->udp->uh_dport = uh_sport;
+ priv->server_port = ntohs(uh_sport);
priv->last_block = 0;
if (priv->block != 1) { /* Assertion */
@@ -376,6 +373,16 @@ static void tftp_handler(void *ctx, char *packet, unsigned len)
}
}
+static void tftp_handler(void *ctx, char *packet, unsigned len)
+{
+ struct file_priv *priv = ctx;
+ char *pkt = net_eth_to_udp_payload(packet);
+ struct udphdr *udp = net_eth_to_udphdr(packet);
+
+ (void)len;
+ tftp_recv(priv, pkt, net_eth_to_udplen(packet), udp->uh_sport);
+}
+
static struct file_priv *tftp_do_open(struct device_d *dev,
int accmode, const char *filename)
{
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] tftp_recv(): according to RFC1350 minimal tftp packet length is 4 bytes
2015-06-28 16:19 [PATCH 0/3] tftp: prepare for picotcp Antony Pavlov
2015-06-28 16:19 ` [PATCH 1/3] fs/tftp: handle incoming packets in the separate tftp_recv() function Antony Pavlov
@ 2015-06-28 16:19 ` Antony Pavlov
2015-06-28 16:19 ` [PATCH 3/3] tftp_recv(): handle opcode field in a more natural way Antony Pavlov
2015-06-29 5:25 ` [PATCH 0/3] tftp: prepare for picotcp Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Antony Pavlov @ 2015-06-28 16:19 UTC (permalink / raw)
To: barebox
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
fs/tftp.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/tftp.c b/fs/tftp.c
index d970c60..e36c1c8 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -259,7 +259,8 @@ static void tftp_recv(struct file_priv *priv,
uint16_t proto;
uint16_t *s;
- if (len < 2)
+ /* according to RFC1350 minimal tftp packet length is 4 bytes */
+ if (len < 4)
return;
len -= 2;
@@ -315,8 +316,6 @@ static void tftp_recv(struct file_priv *priv,
break;
case TFTP_DATA:
- if (len < 2)
- return;
len -= 2;
priv->block = ntohs(*(uint16_t *)pkt);
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] tftp_recv(): handle opcode field in a more natural way
2015-06-28 16:19 [PATCH 0/3] tftp: prepare for picotcp Antony Pavlov
2015-06-28 16:19 ` [PATCH 1/3] fs/tftp: handle incoming packets in the separate tftp_recv() function Antony Pavlov
2015-06-28 16:19 ` [PATCH 2/3] tftp_recv(): according to RFC1350 minimal tftp packet length is 4 bytes Antony Pavlov
@ 2015-06-28 16:19 ` Antony Pavlov
2015-06-29 5:25 ` [PATCH 0/3] tftp: prepare for picotcp Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Antony Pavlov @ 2015-06-28 16:19 UTC (permalink / raw)
To: barebox
RFC1350 uses the 'opcode' term for the first 2-bytes field
of TFTP packet. But the U-boot tftp code uses the 'proto' term
for the same thing.
The patch takes back original term and makes opcode calculation
more clear.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
fs/tftp.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/fs/tftp.c b/fs/tftp.c
index e36c1c8..0de215e 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -256,22 +256,21 @@ static void tftp_timer_reset(struct file_priv *priv)
static void tftp_recv(struct file_priv *priv,
uint8_t *pkt, unsigned len, uint16_t uh_sport)
{
- uint16_t proto;
- uint16_t *s;
+ uint16_t opcode;
/* according to RFC1350 minimal tftp packet length is 4 bytes */
if (len < 4)
return;
- len -= 2;
+ opcode = ntohs(*(uint16_t *)pkt);
- s = (uint16_t *)pkt;
- proto = *s++;
- pkt = (unsigned char *)s;
+ /* skip tftp opcode 2-byte field */
+ len -= 2;
+ pkt += 2;
- debug("%s: proto 0x%04x\n", __func__, proto);
+ debug("%s: opcode 0x%04x\n", __func__, opcode);
- switch (ntohs(proto)) {
+ switch (opcode) {
case TFTP_RRQ:
case TFTP_WRQ:
default:
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] tftp: prepare for picotcp
2015-06-28 16:19 [PATCH 0/3] tftp: prepare for picotcp Antony Pavlov
` (2 preceding siblings ...)
2015-06-28 16:19 ` [PATCH 3/3] tftp_recv(): handle opcode field in a more natural way Antony Pavlov
@ 2015-06-29 5:25 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2015-06-29 5:25 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Sun, Jun 28, 2015 at 07:19:37PM +0300, Antony Pavlov wrote:
> This patchseries makes it much easier to run barebox tftp client
> on top of picotcp network stack in the future.
>
> Antony Pavlov (3):
> fs/tftp: handle incoming packets in the separate tftp_recv() function
> tftp_recv(): according to RFC1350 minimal tftp packet length is 4
> bytes
> tftp_recv(): handle opcode field in a more natural way
>
> fs/tftp.c | 47 ++++++++++++++++++++++++++---------------------
> 1 file changed, 26 insertions(+), 21 deletions(-)
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-06-29 5:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-28 16:19 [PATCH 0/3] tftp: prepare for picotcp Antony Pavlov
2015-06-28 16:19 ` [PATCH 1/3] fs/tftp: handle incoming packets in the separate tftp_recv() function Antony Pavlov
2015-06-28 16:19 ` [PATCH 2/3] tftp_recv(): according to RFC1350 minimal tftp packet length is 4 bytes Antony Pavlov
2015-06-28 16:19 ` [PATCH 3/3] tftp_recv(): handle opcode field in a more natural way Antony Pavlov
2015-06-29 5:25 ` [PATCH 0/3] tftp: prepare for picotcp Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox