Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add network stack #12

Merged
merged 68 commits into from
Feb 2, 2020
Merged

Add network stack #12

merged 68 commits into from
Feb 2, 2020

Conversation

vinc
Copy link
Owner

@vinc vinc commented Jan 25, 2020

  • Add RTL8139 driver
  • Add smoltcp crate
  • Add net command
  • Add ip command
  • Add route command
  • Add dhcp command
  • Add host command
  • Add http command

Driver:
https://wiki.osdev.org/RTL8139
https://www.cs.usfca.edu/~cruse/cs326f04/RTL8139D_DataSheet.pdf
https://docs.rs/smoltcp/0.6.0/smoltcp

DNS:
https://tools.ietf.org/html/rfc1035

@vinc
Copy link
Owner Author

vinc commented Jan 26, 2020

First raw data received:

00000000: 0100 7200 3333 0000 0001 5256 0000 0002 ..r.33....RV....
00000010: 86DD 6000 0000 0038 3AFF FE80 0000 0000 ..`....8:.......
00000020: 0000 0000 0000 0000 0002 FF02 0000 0000 ................
00000030: 0000 0000 0000 0000 0001 8600 155E 4000 .............^@.
00000040: 0708 0000 0000 0000 0000 0101 5256 0000 ............RV..
00000050: 0002 0304 40C0 0001 5180 0000 3840 0000 ....@...Q...8@..
00000060: 0000 FEC0 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 8CF2 6C74 0000 0000 0000 0000 0000 ....lt..........
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000100: 0000 0000 0000 0000 0000 0000 0000 0000 ................

@vinc
Copy link
Owner Author

vinc commented Jan 26, 2020

By taking the packet header and length into account:

[389.970348] Polling ethernet interface...
`-> RTL8139 received data (cmd=0x0C, header=0x0001, length=114)

00000000: 3333 0000 0001 5256 0000 0002 86DD 6000 33....RV......`.
00000010: 0000 0038 3AFF FE80 0000 0000 0000 0000 ...8:...........
00000020: 0000 0000 0002 FF02 0000 0000 0000 0000 ................
00000030: 0000 0000 0001 8600 155E 4000 0708 0000 .........^@.....
00000040: 0000 0000 0000 0101 5256 0000 0002 0304 ........RV......
00000050: 40C0 0001 5180 0000 3840 0000 0000 FEC0 @...Q...8@......
00000060: 0000 0000 0000 0000 0000 0000 0000
`-> Err(unrecognized packet)

@vinc
Copy link
Owner Author

vinc commented Jan 27, 2020

And now by taking CRC at the end into account:

[319.995387] Polling ethernet interface...
`-> RTL8139 received data:

cmd: 0x0C
header: 0x0001
length: 110
crc: 0x746CF28C

00000000: 3333 0000 0001 5256 0000 0002 86DD 6000 33....RV......`.
00000010: 0000 0038 3AFF FE80 0000 0000 0000 0000 ...8:...........
00000020: 0000 0000 0002 FF02 0000 0000 0000 0000 ................
00000030: 0000 0000 0001 8600 155E 4000 0708 0000 .........^@.....
00000040: 0000 0000 0000 0101 5256 0000 0002 0304 ........RV......
00000050: 40C0 0001 5180 0000 3840 0000 0000 FEC0 @...Q...8@......
00000060: 0000 0000 0000 0000 0000 0000 0000      ..............
`-> Err(unrecognized packet)

Confirmed with Wireshark:

Frame 1: 110 bytes on wire (880 bits), 110 bytes captured (880 bits)
Ethernet II, Src: 52:56:00:00:00:02 (52:56:00:00:00:02), Dst: IPv6mcast_01 (33:33:00:00:00:01)
Internet Protocol Version 6, Src: fe80::2, Dst: ff02::1
Internet Control Message Protocol v6

@vinc
Copy link
Owner Author

vinc commented Jan 28, 2020

Got the packet transmission working!

------------------------------------------------------------------
[30.263896] NET RTL8139 transmitting frame:

TX Buffer: 3

00000000: FFFF FFFF FFFF 5254 0012 3456 0800 4500 ......RT..4V..E.
00000010: 011D 0000 4000 4011 2DC2 0A00 020F FFFF ....@.@.-. .....
00000020: FFFF 0044 0043 0109 AD1A 0101 0600 0000 ...D.C. ........
00000030: 0005 0000 0001 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 5254 0012 3456 0000 0000 ......RT..4V....
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000100: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000110: 0000 0000 0000 6382 5363 3501 013D 0701 ......c.Sc5..=..
00000120: 5254 0012 3456 3902 0384                RT..4V9...
------------------------------------------------------------------
[30.263896] NET RTL8139 receiving frame:

Command Register: 0x0C
Header: 0x0001
Length: 590 bytes
CRC: 0xAAD19FDE

00000000: FFFF FFFF FFFF 5255 0A00 0202 0800 4510 ......RU .....E.
00000010: 0240 0000 0000 4011 6C9C 0A00 0202 FFFF .@....@.l. .....
00000020: FFFF 0043 0044 022C BB6C 0201 0600 0000 ...C.D.,.l......
00000030: 0005 0000 0000 0000 0000 0A00 020F 0A00 .......... ... .
00000040: 0202 0000 0000 5254 0012 3456 0000 0000 ......RT..4V....
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000100: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000110: 0000 0000 0000 6382 5363 3501 0236 040A ......c.Sc5..6.
00000120: 0002 0201 04FF FFFF 0003 040A 0002 0206 ........... ....
00000130: 040A 0002 0333 0400 0151 80FF 0000 0000 . ...3...Q......
00000140: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000150: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000160: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000170: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000180: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000190: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001A0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001B0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001C0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001D0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001E0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001F0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000200: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000210: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000220: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000230: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000240: 0000 0000 0000 0000 0000 0000 0000      ..............
TX Buffer: 0
DHCP config: Config { address: Some(Cidr { address: Address([10, 0, 2, 15]), prefix_len: 24 }), router: Some(Address([10, 0, 2, 2])), dns_servers: [Some(Address([10, 0, 2, 3])), None, None] }
Assigned a new IPv4 address: 10.0.2.15/24
Default gateway: 10.0.2.2
DNS servers:
- 10.0.2.3

Used the following example for the DHCP client: https://github.com/m-labs/smoltcp/blob/master/examples/dhcp_client.rs

@vinc
Copy link
Owner Author

vinc commented Feb 1, 2020

Everything seems to be working except we'll need to update the allocator to have physical memory blocks larger than the 4iB page size. After receiving a few big (or many small) packets the card will start to write in space than has not been allocated and we can't read it back.

@vinc
Copy link
Owner Author

vinc commented Feb 2, 2020

Creating an unused array that will "push" the other one into a contiguous area in memory proved that this was indeed the issue.

@vinc vinc marked this pull request as ready for review February 2, 2020 17:54
@vinc
Copy link
Owner Author

vinc commented Feb 2, 2020

Going to merge this as it is and work on the allocator this week.

@vinc vinc merged commit 4fd7d68 into master Feb 2, 2020
@vinc vinc deleted the feature/rtl8139 branch February 2, 2020 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant