Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
ethernet.c
Go to the documentation of this file.
1#include "ethernet.h"
3#include "libk/serial.h"
4#include <str.h>
5#include "net/netdev.h"
7
8// TODO: handle race condition jika dipanggil di scheduler
10 uint16_t ethertype, const uint8_t dst_mac[6]) {
11
12 struct ethernet_header* eth = (struct ethernet_header*) netbuff_push(
13 netbuff, sizeof(struct ethernet_header));
14
15 memcopy((void*) eth->dest_mac, (void*) dst_mac, 6);
16 memcopy((void*) eth->src_mac, (void*) dev->mac, 6);
17 eth->ethertype = ethertype;
18
19 if (netbuff->length < 60) {
20 // Tambahkan nol di belakang agar paket pas 60 byte
21 size_t pad_len = 60 - netbuff->length;
22 void* pad_area = netbuff_put(netbuff, pad_len);
23 memset(pad_area, 0, pad_len);
24 }
25
26 uintptr_t current_paddr =
28
29 struct data_template data[1];
30 data[0] = (struct data_template){.buffer = (void*) current_paddr,
31 .len = netbuff->length,
32 .wait_next_data = false};
33
34 // TODO di dev ada ops sendiri buat send tidak langsung ke nic
35 dev->nic->ops.send(data, 1);
36}
void ethernet_send_frame(netdev_t *dev, struct netbuff *netbuff, uint16_t ethertype, const uint8_t dst_mac[6])
Definition ethernet.c:9
struct fs_data data
Definition filesystem.h:1
uint16_t ethertype
Definition ethernet.h:2
void * netbuff_put(struct netbuff *nb, size_t len)
Definition netbuff.c:42
void * netbuff_push(struct netbuff *nb, size_t len)
Definition netbuff.c:50
struct netdev netdev_t
Definition netdev.h:19
size_t len
Definition oct2bin.h:7
void memset(void *ptr, int value, size_t num)
void memcopy(void *dest, void *src, size_t size)
uint8_t src_mac[6]
Definition ethernet.h:10
uint16_t ethertype
Definition ethernet.h:11
uint8_t dest_mac[6]
Definition ethernet.h:9
int(* send)(const struct data_template data[], size_t count)
Definition ioforge_nic.h:22
struct ioforge_nic_operation ops
Definition ioforge_nic.h:60
uint8_t * data
Definition netbuff.h:15
uintptr_t paddr
Definition netbuff.h:10
uint16_t length
Definition netbuff.h:18
uint8_t * head
Definition netbuff.h:12
uint8_t mac[6]
Definition netdev.h:35
struct ioforge_nic_service * nic
Definition netdev.h:38
unsigned short uint16_t
Definition type.h:13
unsigned long uintptr_t
Definition type.h:73
unsigned char uint8_t
Definition type.h:7