Remove dependency of net module on rtl module
This commit is contained in:
parent
3447ffcb03
commit
19c5b581ab
@ -1,6 +1,23 @@
|
||||
#ifndef KERNEL_MOD_NET_H
|
||||
#define KERNEL_MOD_NET_H
|
||||
|
||||
typedef uint8_t* (*get_mac_func)(void);
|
||||
typedef struct ethernet_packet* (*get_packet_func)(void);
|
||||
typedef void* (*send_packet_func)(uint8_t*, size_t);
|
||||
|
||||
struct netif {
|
||||
void *extra;
|
||||
// void (*write_packet)(struct sized_blob * payload);
|
||||
get_mac_func get_mac;
|
||||
// struct ethernet_packet* (*get_packet)(uint8_t* payload, size_t payload_size);
|
||||
get_packet_func get_packet;
|
||||
// void (*send_packet)(uint8_t* payload, size_t payload_size);
|
||||
send_packet_func send_packet;
|
||||
uint8_t hwaddr[6];
|
||||
uint32_t source;
|
||||
};
|
||||
|
||||
extern void init_netif_funcs(get_mac_func mac_func, get_packet_func get_func, send_packet_func send_func);
|
||||
extern void net_handler(void * data, char * name);
|
||||
extern size_t write_dhcp_packet(uint8_t * buffer);
|
||||
|
||||
|
@ -1,9 +1,4 @@
|
||||
#ifndef KERNEL_MOD_RTL_H
|
||||
#define KERNEL_MOD_RTL_H
|
||||
|
||||
extern uint8_t* rtl_get_mac();
|
||||
extern rtl_send_packet(uint8_t* payload, size_t payload_size);
|
||||
extern void* rtl_dequeue();
|
||||
extern void rtl_enqueue(void* buffer);
|
||||
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <hashmap.h>
|
||||
#include <ipv4.h>
|
||||
#include <printf.h>
|
||||
#include <mod/rtl.h>
|
||||
#include <mod/net.h>
|
||||
|
||||
static hashmap_t * dns_cache;
|
||||
|
||||
@ -22,15 +22,19 @@ static uint8_t mac[6];
|
||||
static hashmap_t *_tcp_sockets = NULL;
|
||||
static hashmap_t *_udp_sockets = NULL;
|
||||
|
||||
struct netif {
|
||||
void *extra;
|
||||
void (*write_packet)(struct sized_blob * payload);
|
||||
uint8_t hwaddr[6];
|
||||
uint32_t source;
|
||||
};
|
||||
static list_t * net_init_wait;
|
||||
|
||||
static struct netif _netif;
|
||||
|
||||
void init_netif_funcs(get_mac_func mac_func, get_packet_func get_func, send_packet_func send_func) {
|
||||
_netif.get_mac = mac_func;
|
||||
_netif.get_packet = get_func;
|
||||
_netif.send_packet = send_func;
|
||||
memcpy(_netif.hwaddr, _netif.get_mac(), sizeof(_netif.hwaddr));
|
||||
|
||||
wakeup_queue(net_init_wait);
|
||||
}
|
||||
|
||||
uint32_t ip_aton(const char * in) {
|
||||
char ip[16];
|
||||
char * c = ip;
|
||||
@ -577,7 +581,7 @@ static int net_send_ether(struct tcp_socket *socket, struct netif* netif, uint16
|
||||
memcpy(eth->payload, payload, payload_size);
|
||||
}
|
||||
|
||||
rtl_enqueue(eth);
|
||||
netif->send_packet((uint8_t*)eth, sizeof(struct ethernet_packet) + payload_size);
|
||||
|
||||
return 1; // yolo
|
||||
}
|
||||
@ -708,7 +712,7 @@ static void net_handle_tcp(struct tcp_header * tcp, size_t length) {
|
||||
{
|
||||
/* Send ACK */
|
||||
uint8_t payload[] = { 0 };
|
||||
rtl_send_packet(payload, 0);
|
||||
_netif.send_packet(payload, 0); // Super wrong
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -744,7 +748,7 @@ static void net_handle_ipv4(struct ipv4_packet * ipv4) {
|
||||
}
|
||||
|
||||
static struct ethernet_packet * net_receive(void) {
|
||||
struct ethernet_packet * eth = (struct ethernet_packet *)rtl_dequeue();
|
||||
struct ethernet_packet * eth = _netif.get_packet();
|
||||
|
||||
return eth;
|
||||
}
|
||||
@ -753,11 +757,17 @@ void net_handler(void * data, char * name) {
|
||||
/* Network Packet Handler*/
|
||||
|
||||
_netif.extra = NULL;
|
||||
_netif.write_packet = NULL;
|
||||
memcpy(_netif.hwaddr, rtl_get_mac(), sizeof(_netif.hwaddr));
|
||||
_netif.get_mac = NULL;
|
||||
_netif.get_packet = NULL;
|
||||
_netif.send_packet = NULL;
|
||||
|
||||
// TODO: THIS MUST BE CHANGED
|
||||
_netif.source = 0x0a0a0a0a; // "10.10.10.10"
|
||||
|
||||
net_init_wait = list_create();
|
||||
|
||||
sleep_on(net_init_wait);
|
||||
|
||||
_tcp_sockets = hashmap_create_int(0xFF);
|
||||
_udp_sockets = hashmap_create_int(0xFF);
|
||||
|
||||
@ -779,10 +789,10 @@ void net_handler(void * data, char * name) {
|
||||
}
|
||||
}
|
||||
|
||||
static void net_handler_enqueue(void * buffer) {
|
||||
/* XXX size? source? */
|
||||
rtl_enqueue(buffer);
|
||||
}
|
||||
// static void net_handler_enqueue(void * buffer) {
|
||||
// /* XXX size? source? */
|
||||
// rtl_enqueue(buffer);
|
||||
// }
|
||||
|
||||
static void parse_dns_response(fs_node_t * tty, void * last_packet) {
|
||||
struct ethernet_packet * eth = (struct ethernet_packet *)last_packet;
|
||||
|
@ -226,14 +226,6 @@ static void rtl_ircd(void * data, char * name) {
|
||||
}
|
||||
}
|
||||
|
||||
void rtl_send_packet(uint8_t* payload, size_t payload_size) {
|
||||
int my_tx = next_tx_buf();
|
||||
memcpy(rtl_tx_buffer[my_tx], payload, payload_size);
|
||||
|
||||
outportl(rtl_iobase + RTL_PORT_TXBUF + 4 * my_tx, rtl_tx_phys[my_tx]);
|
||||
outportl(rtl_iobase + RTL_PORT_TXSTAT + 4 * my_tx, payload_size);
|
||||
}
|
||||
|
||||
void* rtl_dequeue() {
|
||||
while (!net_queue->length) {
|
||||
sleep_on(rx_wait);
|
||||
@ -255,6 +247,22 @@ void rtl_enqueue(void * buffer) {
|
||||
spin_unlock(net_queue_lock);
|
||||
}
|
||||
|
||||
uint8_t* rtl_get_mac() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
void rtl_send_packet(uint8_t* payload, size_t payload_size) {
|
||||
int my_tx = next_tx_buf();
|
||||
memcpy(rtl_tx_buffer[my_tx], payload, payload_size);
|
||||
|
||||
outportl(rtl_iobase + RTL_PORT_TXBUF + 4 * my_tx, rtl_tx_phys[my_tx]);
|
||||
outportl(rtl_iobase + RTL_PORT_TXSTAT + 4 * my_tx, payload_size);
|
||||
}
|
||||
|
||||
struct ethernet_header* rtl_get_packet(void) {
|
||||
return (struct ethernet_header*)rtl_dequeue();
|
||||
}
|
||||
|
||||
static int rtl_irq_handler(struct regs *r) {
|
||||
uint16_t status = inports(rtl_iobase + RTL_PORT_ISR);
|
||||
if (!status) {
|
||||
@ -314,10 +322,6 @@ static int rtl_irq_handler(struct regs *r) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t* rtl_get_mac() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
static void rtl_netd(void * data, char * name) {
|
||||
fs_node_t * tty = data;
|
||||
|
||||
@ -454,6 +458,7 @@ static void rtl_netd(void * data, char * name) {
|
||||
_atty = tty;
|
||||
|
||||
create_kernel_tasklet(net_handler, "[eth]", tty);
|
||||
init_netif_funcs(rtl_get_mac, rtl_get_packet, rtl_send_packet);
|
||||
}
|
||||
|
||||
static int tty_readline(fs_node_t * dev, char * linebuf, int max) {
|
||||
@ -908,7 +913,6 @@ DEFINE_SHELL_FUNCTION(rtl, "rtl8139 experiments") {
|
||||
fprintf(tty, "Card is configured, going to start worker thread now.\n");
|
||||
|
||||
create_kernel_tasklet(rtl_netd, "[netd]", tty);
|
||||
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user