From 8f3c73740a30ad02a594e21a52d47aa4ae9efe91 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 5 Jan 2018 20:52:57 +0100 Subject: some preliminary work on an UDP netconsole --- src/kernel/console.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/kernel/console.c') diff --git a/src/kernel/console.c b/src/kernel/console.c index 04fb44f..bf83fec 100644 --- a/src/kernel/console.c +++ b/src/kernel/console.c @@ -9,6 +9,7 @@ void console_init( console_t *console ) console->vga_text = NULL; console->serial = NULL; + console->network = NULL; } void console_add_vga_text_output( console_t *console, vga_text_t *vga_text ) @@ -21,6 +22,37 @@ void console_add_serial_output( console_t *console, serial_t *serial ) console->serial = serial; } +void console_add_network_output( console_t *console, network_t *network ) +{ + console->network = network; +} + +static void send_via_udp( network_t *network, const char *s, size_t n ) +{ + //~ network_ethernet_packet_t *packet = (network_ethernet_packet_t *)event->buf.data; + + //~ network_mac_address_t dst_addr; + //~ network_mac_address_t src_addr; + //~ network_ether_type_t type; +//~ } __attribute__( ( packed ) ) network_ethernet_packet_header_t; +//~ typedef struct { + //~ network_ethernet_packet_header_t header; + //~ uint8_t *data; +//~ } __attribute__( ( packed ) ) network_ethernet_packet_t; + + //~ packet->header.dst_addr = arp->source_hardware_address; + //~ packet->header.src_addr = global_context.network->mac_address; + //~ arp->operation = ARP_OPERATION_ANSWER; + //~ arp->destination_hardware_address = arp->source_hardware_address; + //~ arp->source_hardware_address = global_context.network->mac_address; + //~ network_ipv4_address_t tmp = arp->destination_protocol_address; + //~ arp->destination_protocol_address = arp->source_protocol_address; + //~ arp->source_protocol_address = tmp; + //~ event->buf.length = sizeof( network_ethernet_packet_header_t ) + sizeof( network_arp_packet_t ); + + //~ ((network_vtable_t *)( global_context.network->base.vtable ))->send( global_context.network, event->buf ); +} + void console_put_char( console_t *console, const char c ) { if( console->vga_text != NULL ) { @@ -30,6 +62,10 @@ void console_put_char( console_t *console, const char c ) if( console->serial != NULL ) { serial_put_char( console->serial, c ); } + + if( console->network != NULL ) { + send_via_udp( console->network, &c, 1 ); + } } void console_put_string( console_t *console, const char *s ) @@ -41,6 +77,10 @@ void console_put_string( console_t *console, const char *s ) if( console->serial != NULL ) { serial_put_string( console->serial, s ); } + + if( console->network != NULL ) { + send_via_udp( console->network, s, strlen( s ) ); + } } void console_put_newline( console_t *console ) @@ -58,4 +98,9 @@ void console_put_newline( console_t *console ) if( console->serial != NULL ) { serial_put_newline( console->serial ); } + + if( console->network != NULL ) { + char c = '\n'; + send_via_udp( console->network, &c, 1 ); + } } -- cgit v1.2.3-54-g00ecf