moros/src/usr/http.rs

252 lines
9.5 KiB
Rust
Raw Normal View History

2021-07-17 18:58:04 +00:00
use crate::{sys, usr};
use crate::api::console::Style;
use crate::api::clock;
use crate::api::process::ExitCode;
use crate::api::random;
use crate::api::syscall;
use alloc::string::{String, ToString};
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
use alloc::vec;
use core::str::{self, FromStr};
use smoltcp::socket::{TcpSocket, TcpSocketBuffer};
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
use smoltcp::time::Instant;
use smoltcp::wire::IpAddress;
#[derive(Debug)]
struct URL {
pub host: String,
pub port: u16,
pub path: String,
}
enum SessionState { Connect, Request, Response }
enum ResponseState { Headers, Body }
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
impl URL {
pub fn parse(url: &str) -> Option<Self> {
if !url.starts_with("http://") {
return None;
}
let url = &url[7..];
let (server, path) = match url.find('/') {
Some(i) => url.split_at(i),
None => (url, "/"),
};
let (host, port) = match server.find(':') {
Some(i) => server.split_at(i),
2020-07-06 17:15:31 +00:00
None => (server, ":80"),
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
};
2020-07-06 17:15:31 +00:00
let port = &port[1..];
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
Some(Self {
host: host.into(),
port: port.parse().unwrap_or(80),
path: path.into(),
})
}
}
pub fn main(args: &[&str]) -> Result<(), ExitCode> {
let csi_verbose = Style::color("LightBlue");
let csi_reset = Style::reset();
// Parse command line options
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
let mut is_verbose = false;
let mut host = "";
let mut path = "";
2022-08-28 15:26:13 +00:00
let mut timeout = 5.0;
let mut i = 1;
let n = args.len();
2022-08-28 15:26:13 +00:00
while i < n {
match args[i] {
"-h" | "--help" => {
return help();
}
"-v" | "--verbose" => {
is_verbose = true;
}
2022-08-28 15:26:13 +00:00
"-t" | "--timeout" => {
if i + 1 < n {
timeout = args[i + 1].parse().unwrap_or(timeout);
i += 1;
} else {
error!("Missing timeout seconds");
return Err(ExitCode::UsageError);
}
}
_ => {
if args[i].starts_with("-") {
error!("Invalid option '{}'", args[i]);
return Err(ExitCode::UsageError);
} else if host.is_empty() {
host = args[i].trim_start_matches("http://").trim_start_matches("https://");
} else if path.is_empty() {
path = args[i];
} else {
error!("Too many arguments");
return Err(ExitCode::UsageError);
}
}
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
}
2022-08-28 15:26:13 +00:00
i += 1;
}
if host.is_empty() && path.is_empty() {
error!("Missing URL");
return Err(ExitCode::UsageError);
} else if path.is_empty() {
if let Some(i) = host.find('/') {
(host, path) = host.split_at(i);
} else {
path = "/"
}
}
let url = "http://".to_string() + host + path;
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
let url = URL::parse(&url).expect("invalid URL format");
let address = if url.host.ends_with(char::is_numeric) {
IpAddress::from_str(&url.host).expect("invalid address format")
} else {
match usr::host::resolve(&url.host) {
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
Ok(ip_addr) => {
ip_addr
}
Err(e) => {
error!("Could not resolve host: {:?}", e);
return Err(ExitCode::Failure);
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
}
}
};
let tcp_rx_buffer = TcpSocketBuffer::new(vec![0; 1024]);
let tcp_tx_buffer = TcpSocketBuffer::new(vec![0; 1024]);
let tcp_socket = TcpSocket::new(tcp_rx_buffer, tcp_tx_buffer);
let mut session_state = SessionState::Connect;
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
if let Some(ref mut iface) = *sys::net::IFACE.lock() {
let tcp_handle = iface.add_socket(tcp_socket);
2022-08-28 15:26:13 +00:00
let mut last_received_at = clock::realtime();
let mut response_state = ResponseState::Headers;
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
loop {
2022-08-28 15:26:13 +00:00
if clock::realtime() - last_received_at > timeout {
error!("Timeout reached");
iface.remove_socket(tcp_handle);
return Err(ExitCode::Failure);
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
}
if sys::console::end_of_text() || sys::console::end_of_transmission() {
eprintln!();
iface.remove_socket(tcp_handle);
return Err(ExitCode::Failure);
}
let timestamp = Instant::from_micros((clock::realtime() * 1000000.0) as i64);
if let Err(e) = iface.poll(timestamp) {
error!("Network Error: {}", e);
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
}
let (socket, cx) = iface.get_socket_and_context::<TcpSocket>(tcp_handle);
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
session_state = match session_state {
SessionState::Connect if !socket.is_active() => {
let local_port = 49152 + random::get_u16() % 16384;
if is_verbose {
print!("{}", csi_verbose);
println!("* Connecting to {}:{}", address, url.port);
print!("{}", csi_reset);
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
}
if socket.connect(cx, (address, url.port), local_port).is_err() {
error!("Could not connect to {}:{}", address, url.port);
iface.remove_socket(tcp_handle);
return Err(ExitCode::Failure);
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
}
SessionState::Request
}
SessionState::Request if socket.may_send() => {
let http_get = "GET ".to_string() + &url.path + " HTTP/1.1\r\n";
let http_host = "Host: ".to_string() + &url.host + "\r\n";
let http_ua = "User-Agent: MOROS/".to_string() + env!("CARGO_PKG_VERSION") + "\r\n";
let http_connection = "Connection: close\r\n".to_string();
if is_verbose {
print!("{}", csi_verbose);
print!("> {}", http_get);
print!("> {}", http_host);
print!("> {}", http_ua);
print!("> {}", http_connection);
println!(">");
print!("{}", csi_reset);
}
socket.send_slice(http_get.as_ref()).expect("cannot send");
socket.send_slice(http_host.as_ref()).expect("cannot send");
socket.send_slice(http_ua.as_ref()).expect("cannot send");
socket.send_slice(http_connection.as_ref()).expect("cannot send");
socket.send_slice(b"\r\n").expect("cannot send");
SessionState::Response
}
SessionState::Response if socket.can_recv() => {
socket.recv(|data| {
2022-08-28 15:26:13 +00:00
last_received_at = clock::realtime();
let n = data.len();
let mut i = 0;
while i < n {
match response_state {
ResponseState::Headers => {
let mut j = i;
while j < n {
if data[j] == b'\n' {
break;
}
j += 1;
}
let line = String::from_utf8_lossy(&data[i..j]); // TODO: check i == j
if is_verbose {
if i == 0 {
print!("{}", csi_verbose);
}
println!("< {}", line);
}
if line.trim().is_empty() {
if is_verbose {
print!("{}", csi_reset);
}
response_state = ResponseState::Body;
}
i = j + 1;
}
ResponseState::Body => {
syscall::write(1, &data[i..n]);
break;
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
}
}
}
(data.len(), ())
}).unwrap();
SessionState::Response
}
SessionState::Response if !socket.may_recv() => {
break;
}
_ => session_state
};
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
if let Some(wait_duration) = iface.poll_delay(timestamp) {
syscall::sleep((wait_duration.total_micros() as f64) / 1000000.0);
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
}
}
iface.remove_socket(tcp_handle);
Ok(())
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
} else {
Err(ExitCode::Failure)
Add network stack (#12) * Display MAC address * Add kernel::pci::find_device * Mask lower bits of 16-bit Memory Space BAR * Use array instead of vector for MAC address * Split interrupts module * Use IRQ constants instead of InterruptIndex enum * Replace kernel::sleep by kernel::time * Add kernel::idt::set_irq_handler * Add interrupt handler for RTL8139 * Enable bus mastering for RTL8139 * Setup NIC * Add features for vga/serial and qwerty/dvorak * Add smoltcp crate * Use EthernetAddress from smoltcp * Add RTL8139 struct to implement smoltcp Device * Save detected device * Add kernel::mem::translate_addr * Use physical address of rx_buffer * Add command to read raw network data * Parse packet header and length * Fix missing ascii on last line * Take CRC into account for packet length * Fix compilation error * Move buffer pointers after packet received * Use buffer slice instead of clone in RxToken * Add packet transmission and dhcp client * Configure network interface with DHCP client * Add debug mode to network interface * Clean dhcp command output * Add ip command * Clean up commands output * Count number of packets transmitted and received * Add route command * Add kernel::random::rand16 * Handle carriage return char * Add HTTP client * Improve http command output * Add DNS resolver command * Parse DNS responses to A IN queries * Resolve http host * Check if interface is ready before operations * Add timeout to polling loops * Fix sleep during polling * Add verbose arg to http command * Add State struct to Device struct * Add subcommand config and dump to net command * Add MTU to RX_BUFFER_LEN when using WRAP * Fix first transmission index * Refactor TxToken implementation * Add user agent to http requests * Add more comments to code * Add llvm-tools-preview component to readme * Add method to translate IRQ into system interrupt * Clear IRQ mask in set_irq_handler * Refactor driver code * Sleep less rather than more * Add rand32 * Disable RTL8139 interrupts * Use arrays instead of vectors for buffers * Add minimum sleep duration * Add phy_addr to dry init * Use CAPR and CBR to compute rx buffer offset * Add debug for alloc issue with continuous physical memory * Fix timeout in loops * Add unused buffer to push the rx buffer into contiguous memory * Add doc about network * Update readme * Add read /net/<proto>/<host>/<path> subcommand
2020-02-02 17:55:20 +00:00
}
}
fn help() -> Result<(), ExitCode> {
let csi_option = Style::color("LightCyan");
let csi_title = Style::color("Yellow");
let csi_reset = Style::reset();
println!("{}Usage:{} http {}<options> <url>{1}", csi_title, csi_reset, csi_option);
println!();
println!("{}Options:{}", csi_title, csi_reset);
2022-08-28 15:26:13 +00:00
println!(" {0}-v{1}, {0}--verbose{1} Increase verbosity", csi_option, csi_reset);
println!(" {0}-t{1}, {0}--timeout <seconds>{1} Request timeout", csi_option, csi_reset);
Ok(())
}