| 68 | } |
| 69 | |
| 70 | [[noreturn]] void InterfaceThread(){ |
| 71 | Log::Info("[Network] Initializing network interface layer..."); |
| 72 | |
| 73 | assert(mainAdapter); |
| 74 | |
| 75 | while(mainAdapter->GetLink() != LinkUp) Scheduler::Yield(); |
| 76 | |
| 77 | for(;;){ |
| 78 | NetworkPacket p; |
| 79 | while((p = mainAdapter->DequeueBlocking()).length){ |
| 80 | if(p.length < sizeof(EthernetFrame)){ |
| 81 | Log::Warning("[Network] Discarding packet (too short)"); |
| 82 | continue; |
| 83 | } |
| 84 | |
| 85 | EthernetFrame* etherFrame = (EthernetFrame*)p.data; |
| 86 | |
| 87 | if(etherFrame->dest != mainAdapter->mac){ |
| 88 | Log::Warning("[Network] Discarding packet (invalid MAC address %x:%x:%x:%x:%x:%x)", etherFrame->dest[0], etherFrame->dest[1], etherFrame->dest[2], etherFrame->dest[3], etherFrame->dest[4], etherFrame->dest[5]); |
| 89 | } |
| 90 | |
| 91 | switch (etherFrame->etherType) |
| 92 | { |
| 93 | case EtherTypeIPv4: |
| 94 | OnReceiveIPv4(etherFrame->data, p.length - sizeof(EthernetFrame)); |
| 95 | break; |
| 96 | default: |
| 97 | Log::Warning("[Network] Discarding packet (invalid EtherType %x)", etherFrame->etherType); |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | void Initialize(){ |
| 105 | Scheduler::CreateChildThread(Scheduler::GetCurrentProcess(), (uintptr_t)InterfaceThread, (uintptr_t)kmalloc(NET_INTERFACE_STACKSIZE) + NET_INTERFACE_STACKSIZE, KERNEL_CS, KERNEL_SS); |
nothing calls this directly
no test coverage detected