]> git.llucax.com Git - z.facultad/66.09/etherled.git/blobdiff - src/main.c
Agrego ejemplo de los leds andando escrito en ASM para sdcc. Falta hacer el .h
[z.facultad/66.09/etherled.git] / src / main.c
index 18df51295b9c65c96089325ecd27930d43a5250c..60ed5db0cec78cba5e4b71922ef001982b569842 100644 (file)
@@ -32,8 +32,10 @@ void main(void)
     {
         byte buf[64]; //XXX
         byte i; //XXX
     {
         byte buf[64]; //XXX
         byte i; //XXX
+        byte len;
 
 
-        if (!netdev_recv_start()) // no recibimos nada (válido)
+        len = netdev_recv_start();
+        if (!len) // no recibimos nada (válido)
             continue; // Probamos de nuevo
 
         // Tenemos algo!
             continue; // Probamos de nuevo
 
         // Tenemos algo!
@@ -72,21 +74,27 @@ void main(void)
                         //printb(udp_dgram_len, 0x40);
                         // TODO
                         // Nuestro protocolo, por ahora un simple echo!
                         //printb(udp_dgram_len, 0x40);
                         // TODO
                         // Nuestro protocolo, por ahora un simple echo!
-                        netdev_read_start(udp_dgram_len-UDP_HEADER_SIZE);
-                        for (i = 0; i < udp_dgram_len-UDP_HEADER_SIZE; ++i)
-                            buf[i] = netdev_read_byte();
+                        len = udp_dgram_len - UDP_HEADER_SIZE;
+                        netdev_read_start(len);
+                        for (i = 0; i < len; ++i)
+                            buf[i] = udp_read_byte();
                         netdev_read_end();
                         netdev_read_end();
+                        if (!udp_checksum_ok())
+                            goto drop;
                         netdev_recv_end();
 
                         // Respuesta
                         netdev_send_start();
                         eth_write_frame_header();
                         netdev_recv_end();
 
                         // Respuesta
                         netdev_send_start();
                         eth_write_frame_header();
+                        //udp_dgram_len = UDP_HEADER_SIZE+len;
+                        //ip_packet_len = IP_HEADER_SIZE+udp_dgram_len;
                         ip_write_packet_header();
                         udp_write_dgram_header();
                         ip_write_packet_header();
                         udp_write_dgram_header();
-                        netdev_write_start(udp_dgram_len-UDP_HEADER_SIZE);
-                        for (i = 0; i < udp_dgram_len-UDP_HEADER_SIZE; ++i)
-                            netdev_write_byte(buf[i]);
+                        netdev_write_start(len);
+                        for (i = 0; i < len; ++i)
+                            udp_write_byte(buf[i]);
                         netdev_write_end();
                         netdev_write_end();
+                        udp_write_checksum(ETH_HEADER_SIZE+IP_HEADER_SIZE);
                         netdev_send_end(ETH_HEADER_SIZE+IP_HEADER_SIZE+udp_dgram_len);
                 }
         }
                         netdev_send_end(ETH_HEADER_SIZE+IP_HEADER_SIZE+udp_dgram_len);
                 }
         }