mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
net: implement netdev flags
This commit is contained in:
@@ -19,16 +19,28 @@ typedef struct {
|
|||||||
size_t size;
|
size_t size;
|
||||||
} netdesc_t;
|
} netdesc_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t port;
|
||||||
|
uint32_t addr;
|
||||||
|
} ipv4addr_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t address[6];
|
uint8_t address[6];
|
||||||
} __attribute__((packed)) mac_t;
|
} __attribute__((packed)) mac_t;
|
||||||
|
|
||||||
|
#define NETDEV_FLAGS_UP 0x1
|
||||||
|
#define NETDEV_FLAGS_BROADCAST 0x2
|
||||||
|
#define NETDEV_FLAGS_DEBUG 0x4
|
||||||
|
#define NETDEV_FLAGS_LOOPBACK 0x8
|
||||||
|
#define NETDEV_FLAGS_RUNNING 0x40
|
||||||
|
|
||||||
typedef struct netdev_t {
|
typedef struct netdev_t {
|
||||||
mac_t mac;
|
mac_t mac;
|
||||||
size_t mtu;
|
size_t mtu;
|
||||||
uint32_t ip;
|
uint32_t ip;
|
||||||
int ipcurrid; // XXX This is defined as something per peer. However, having only one of these *should* work for most cases
|
int ipcurrid; // XXX This is defined as something per peer. However, having only one of these *should* work for most cases
|
||||||
hashtable_t arpcache;
|
hashtable_t arpcache;
|
||||||
|
short flags;
|
||||||
int (*allocdesc)(struct netdev_t *netdev, size_t requestedsize, netdesc_t *desc);
|
int (*allocdesc)(struct netdev_t *netdev, size_t requestedsize, netdesc_t *desc);
|
||||||
int (*freedesc)(struct netdev_t *netdev, netdesc_t *desc);
|
int (*freedesc)(struct netdev_t *netdev, netdesc_t *desc);
|
||||||
int (*sendpacket)(struct netdev_t *_internal, netdesc_t desc, mac_t targetmac, int proto);
|
int (*sendpacket)(struct netdev_t *_internal, netdesc_t desc, mac_t targetmac, int proto);
|
||||||
@@ -54,11 +66,6 @@ typedef struct {
|
|||||||
uint16_t checksum;
|
uint16_t checksum;
|
||||||
} __attribute__((packed)) udpframe_t;
|
} __attribute__((packed)) udpframe_t;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint16_t port;
|
|
||||||
uint32_t addr;
|
|
||||||
} ipv4addr_t;
|
|
||||||
|
|
||||||
#define NET_BROADCAST_MAC (mac_t){.address = {0xff,0xff,0xff,0xff,0xff,0xff}}
|
#define NET_BROADCAST_MAC (mac_t){.address = {0xff,0xff,0xff,0xff,0xff,0xff}}
|
||||||
|
|
||||||
#define MAC_EQUAL(m1,m2) (memcmp(m1, m2, sizeof(mac_t)) == 0)
|
#define MAC_EQUAL(m1,m2) (memcmp(m1, m2, sizeof(mac_t)) == 0)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ typedef struct {
|
|||||||
pollheader_t pollheader;
|
pollheader_t pollheader;
|
||||||
int type;
|
int type;
|
||||||
int shutdown;
|
int shutdown;
|
||||||
|
int error;
|
||||||
} socket_t;
|
} socket_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ void loopback_init() {
|
|||||||
loopbacknetdev.allocdesc = loopback_allocdesc;
|
loopbacknetdev.allocdesc = loopback_allocdesc;
|
||||||
loopbacknetdev.freedesc = loopback_freedesc;
|
loopbacknetdev.freedesc = loopback_freedesc;
|
||||||
loopbacknetdev.ip = 0x7f000001;
|
loopbacknetdev.ip = 0x7f000001;
|
||||||
|
loopbacknetdev.flags = NETDEV_FLAGS_UP | NETDEV_FLAGS_LOOPBACK | NETDEV_FLAGS_RUNNING;
|
||||||
__assert(hashtable_init(&loopbacknetdev.arpcache, 30) == 0);
|
__assert(hashtable_init(&loopbacknetdev.arpcache, 30) == 0);
|
||||||
|
|
||||||
for (int i = 0; i < 6; ++i)
|
for (int i = 0; i < 6; ++i)
|
||||||
|
|||||||
@@ -404,6 +404,8 @@ static void init_controller(pcienum_t *pci_enum) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
netdev->netdev.flags = NETDEV_FLAGS_UP | NETDEV_FLAGS_BROADCAST | NETDEV_FLAGS_RUNNING;
|
||||||
|
|
||||||
// enable rx/tx
|
// enable rx/tx
|
||||||
outb(pci_bar.address + REGISTER_COMMAND, REGISTER_COMMAND_TX_ENABLE | REGISTER_COMMAND_RX_ENABLE);
|
outb(pci_bar.address + REGISTER_COMMAND, REGISTER_COMMAND_TX_ENABLE | REGISTER_COMMAND_RX_ENABLE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user