X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Flink.c;h=8bca51fccb694328a1f3f9ab50a7438923cab477;hb=c2bba6e776701404229ef2bebe10c8dc9046b026;hp=4be9d80ce19194aaf1261ef0f35b76d3d6f1f7e3;hpb=23096bbffa94688e90db5045d124dcdfe83a132e;p=tpg%2Facess2.git diff --git a/Modules/IPStack/link.c b/Modules/IPStack/link.c index 4be9d80c..8bca51fc 100644 --- a/Modules/IPStack/link.c +++ b/Modules/IPStack/link.c @@ -92,30 +92,13 @@ void Link_SendPacket(tAdapter *Adapter, Uint16 Type, tMacAddr To, int Length, vo VFS_Write(Adapter->DeviceFD, bufSize, buf); } -/** - * \fn void Link_WatchDevice(tAdapter *Adapter) - * \brief Spawns a worker thread to watch the specified adapter - */ -void Link_WatchDevice(tAdapter *Adapter) +void Link_WorkerThread(void *Ptr) { - int tid = Proc_SpawnWorker(); // Create a new worker thread - - if(tid < 0) { - Log_Warning("NET", "Unable to create watcher thread for '%s'", Adapter->Device); - return ; - } - - if(tid > 0) { - Log_Log("Net Link", "Watching '%s' using tid %i", Adapter->Device, tid); - return ; - } - - if( !gbLink_CRCTableGenerated ) - Link_InitCRC(); + tAdapter *Adapter = Ptr; Threads_SetName(Adapter->Device); Log_Log("Net Link", "Thread %i watching '%s'", Threads_GetTID(), Adapter->Device); - + // Child Thread while(Adapter->DeviceFD != -1) { @@ -129,18 +112,20 @@ void Link_WatchDevice(tAdapter *Adapter) ret = VFS_Read(Adapter->DeviceFD, MAX_PACKET_SIZE, buf); if(ret == -1) break; - if(ret <= (int)sizeof(tEthernetHeader)) { - Log_Log("NET", "Recieved an undersized packet"); + if(ret < sizeof(tEthernetHeader)) { + Log_Log("Net Link", "Recieved an undersized packet (%i < %i)", + ret, sizeof(tEthernetHeader)); continue; } Log_Log("Net Link", "Packet from %02x:%02x:%02x:%02x:%02x:%02x" - " to %02x:%02x:%02x:%02x:%02x:%02x", + " to %02x:%02x:%02x:%02x:%02x:%02x (Type=%04x)", hdr->Src.B[0], hdr->Src.B[1], hdr->Src.B[2], hdr->Src.B[3], hdr->Src.B[4], hdr->Src.B[5], hdr->Dest.B[0], hdr->Dest.B[1], hdr->Dest.B[2], - hdr->Dest.B[3], hdr->Dest.B[4], hdr->Dest.B[5] + hdr->Dest.B[3], hdr->Dest.B[4], hdr->Dest.B[5], + ntohs(hdr->Type) ); checksum = *(Uint32*)&hdr->Data[ret-sizeof(tEthernetHeader)-4]; //Log_Log("NET", "Checksum 0x%08x", checksum); @@ -166,11 +151,32 @@ void Link_WatchDevice(tAdapter *Adapter) ); } - Log_Log("NET", "Watcher terminated (file closed)"); + Log_Log("Net Link", "Watcher terminated (file closed)"); Threads_Exit(0, 0); } +/** + * \fn void Link_WatchDevice(tAdapter *Adapter) + * \brief Spawns a worker thread to watch the specified adapter + */ +void Link_WatchDevice(tAdapter *Adapter) +{ + int tid; + + if( !gbLink_CRCTableGenerated ) + Link_InitCRC(); + + tid = Proc_SpawnWorker(Link_WorkerThread, Adapter); // Create a new worker thread + + if(tid < 0) { + Log_Warning("Net Link", "Unable to create watcher thread for '%s'", Adapter->Device); + return ; + } + + Log_Log("Net Link", "Watching '%s' using tid %i", Adapter->Device, tid); +} + // From http://www.cl.cam.ac.uk/research/srg/bluebook/21/crc/node6.html #define QUOTIENT 0x04c11db7 void Link_InitCRC(void)