aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2020-11-21 13:13:00 +0100
committerMarvin Borner2020-11-21 13:13:00 +0100
commit5c0ab661d3af07186c1fb1c8a8b22d3a894b1be1 (patch)
tree2cc01ae6c1ba47b77bb49a7d403fbb0c8dd9b957 /kernel
parentad5f905cd32af320fcf6e1bb2db0f18959e924e5 (diff)
Added net_installed check
Diffstat (limited to 'kernel')
-rw-r--r--kernel/drivers/rtl8139.c13
-rw-r--r--kernel/features/net.c19
-rw-r--r--kernel/inc/net.h1
-rw-r--r--kernel/inc/rtl8139.h1
4 files changed, 26 insertions, 8 deletions
diff --git a/kernel/drivers/rtl8139.c b/kernel/drivers/rtl8139.c
index fb60865..9317d7b 100644
--- a/kernel/drivers/rtl8139.c
+++ b/kernel/drivers/rtl8139.c
@@ -19,7 +19,7 @@ static u32 rtl_device_pci = 0;
static u32 rtl_iobase = 0;
static u32 cur_rx = 0;
-u8 *rtl8139_get_mac()
+u8 *rtl8139_get_mac(void)
{
if (!rtl_device_pci)
return NULL;
@@ -27,7 +27,7 @@ u8 *rtl8139_get_mac()
return mac;
}
-void rtl8139_receive_packet()
+void rtl8139_receive_packet(void)
{
while ((inb(rtl_iobase + RTL_PORT_CMD) & 0x01) == 0) {
int offset = cur_rx % 0x2000;
@@ -93,7 +93,7 @@ void rtl8139_irq_handler()
rtl8139_receive_packet();
}
-void rtl8139_init()
+void rtl8139_init(void)
{
if (!rtl_device_pci)
return;
@@ -160,7 +160,12 @@ void rtl8139_init()
outl(rtl_iobase + RTL_PORT_RXMISS, 0);
}
-int rtl8139_install()
+int rtl8139_installed(void)
+{
+ return rtl_device_pci != 0;
+}
+
+int rtl8139_install(void)
{
pci_scan(&rtl8139_find, -1, &rtl_device_pci);
diff --git a/kernel/features/net.c b/kernel/features/net.c
index 2e4f6cf..edad1a9 100644
--- a/kernel/features/net.c
+++ b/kernel/features/net.c
@@ -713,6 +713,9 @@ static int arp_lookup(u8 *ret_hardware_addr, u32 ip_addr)
struct socket *net_open(enum socket_type type)
{
+ if (!net_installed())
+ return NULL;
+
struct socket *socket = socket_new(type);
if (!socket)
return NULL;
@@ -726,12 +729,15 @@ struct socket *net_open(enum socket_type type)
int net_close(struct socket *socket)
{
+ if (!net_installed())
+ return 1;
+
return socket_close(socket);
}
int net_connect(struct socket *socket, u32 ip_addr, u16 dst_port)
{
- if (!socket || socket->state != S_OPEN || !ip_addr || !dst_port)
+ if (!net_installed() || !socket || socket->state != S_OPEN || !ip_addr || !dst_port)
return 0;
socket->ip_addr = ip_addr;
@@ -770,7 +776,7 @@ int net_connect(struct socket *socket, u32 ip_addr, u16 dst_port)
void net_send(struct socket *socket, void *data, u32 len)
{
- if (!socket || socket->state != S_CONNECTED)
+ if (!net_installed() || !socket || socket->state != S_CONNECTED)
return;
if (socket->type == S_TCP) {
@@ -785,7 +791,7 @@ void net_send(struct socket *socket, void *data, u32 len)
int net_data_available(struct socket *socket)
{
- if (socket && socket->packets && socket->packets->head &&
+ if (net_installed() && socket && socket->packets && socket->packets->head &&
((struct socket_data *)socket->packets->head->data)->length > 0)
return 1;
else
@@ -794,7 +800,7 @@ int net_data_available(struct socket *socket)
int net_receive(struct socket *socket, void *buf, u32 len)
{
- if (!socket || !socket->packets)
+ if (!net_installed() || !socket || !socket->packets)
return 0;
u32 offset = 0;
@@ -819,6 +825,11 @@ int net_receive(struct socket *socket, void *buf, u32 len)
* Install
*/
+int net_installed()
+{
+ return rtl8139_installed() != 0;
+}
+
void net_install(void)
{
if (!rtl8139_install())
diff --git a/kernel/inc/net.h b/kernel/inc/net.h
index ddc2405..9a305a1 100644
--- a/kernel/inc/net.h
+++ b/kernel/inc/net.h
@@ -163,6 +163,7 @@ void net_send(struct socket *socket, void *data, u32 len);
int net_receive(struct socket *socket, void *buf, u32 len);
int net_data_available(struct socket *socket);
+int net_installed(void);
void net_install(void);
#endif
diff --git a/kernel/inc/rtl8139.h b/kernel/inc/rtl8139.h
index faeb3f6..bbb904e 100644
--- a/kernel/inc/rtl8139.h
+++ b/kernel/inc/rtl8139.h
@@ -29,6 +29,7 @@
#define RTL_PORT_CONFIG 0x52
int rtl8139_install(void);
+int rtl8139_installed(void);
void rtl8139_send_packet(void *data, u32 len);
u8 *rtl8139_get_mac(void);