git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Misc changes
[tpg/acess2.git]
/
Modules
/
IPStack
/
link.c
diff --git
a/Modules/IPStack/link.c
b/Modules/IPStack/link.c
index
cb59f0f
..
8de8729
100644
(file)
--- a/
Modules/IPStack/link.c
+++ b/
Modules/IPStack/link.c
@@
-17,6
+17,7
@@
void Link_WatchDevice(tAdapter *Adapter);
// === GLOBALS ===
int giRegisteredTypes = 0;
// === GLOBALS ===
int giRegisteredTypes = 0;
+ int giRegisteredTypeSpace = 0;
struct {
Uint16 Type;
tPacketCallback Callback;
struct {
Uint16 Type;
tPacketCallback Callback;
@@
-36,12
+37,10
@@
void Link_RegisterType(Uint16 Type, tPacketCallback Callback)
int i;
void *tmp;
int i;
void *tmp;
- Type = htons(Type); // Set to network order
-
for( i = giRegisteredTypes; i -- ; )
{
if(gaRegisteredTypes[i].Type == Type) {
for( i = giRegisteredTypes; i -- ; )
{
if(gaRegisteredTypes[i].Type == Type) {
-
Warning("[NET ]
Attempt to register 0x%x twice", Type);
+
Log_Warning("Net Link", "
Attempt to register 0x%x twice", Type);
return ;
}
// Ooh! Free slot!
return ;
}
// Ooh! Free slot!
@@
-50,14
+49,18
@@
void Link_RegisterType(Uint16 Type, tPacketCallback Callback)
if(i == -1)
{
if(i == -1)
{
- tmp = realloc(gaRegisteredTypes, (giRegisteredTypes+1)*sizeof(*gaRegisteredTypes));
+ giRegisteredTypeSpace += 5;
+ tmp = realloc(gaRegisteredTypes, giRegisteredTypeSpace*sizeof(*gaRegisteredTypes));
if(!tmp) {
if(!tmp) {
- Warning("[NET ] Out of heap space!");
+ Log_Warning("Net Link",
+ "Out of heap space! (Attempted to allocate %i)",
+ giRegisteredTypeSpace*sizeof(*gaRegisteredTypes)
+ );
return ;
}
return ;
}
+ gaRegisteredTypes = tmp;
i = giRegisteredTypes;
giRegisteredTypes ++;
i = giRegisteredTypes;
giRegisteredTypes ++;
- gaRegisteredTypes = tmp;
}
gaRegisteredTypes[i].Callback = Callback;
}
gaRegisteredTypes[i].Callback = Callback;
@@
-70,11
+73,11
@@
void Link_RegisterType(Uint16 Type, tPacketCallback Callback)
*/
void Link_SendPacket(tAdapter *Adapter, Uint16 Type, tMacAddr To, int Length, void *Buffer)
{
*/
void Link_SendPacket(tAdapter *Adapter, Uint16 Type, tMacAddr To, int Length, void *Buffer)
{
- int bufSize = sizeof(tEthernetHeader) +
Length
+ 4;
+ int bufSize = sizeof(tEthernetHeader) +
((Length+3)&~3)
+ 4;
Uint8 buf[bufSize]; // dynamic stack arrays ftw!
tEthernetHeader *hdr = (void*)buf;
Uint8 buf[bufSize]; // dynamic stack arrays ftw!
tEthernetHeader *hdr = (void*)buf;
- Log
("[NET ]
Sending %i bytes to %02x:%02x:%02x:%02x:%02x:%02x (Type 0x%x)",
+ Log
_Log("Net Link", "
Sending %i bytes to %02x:%02x:%02x:%02x:%02x:%02x (Type 0x%x)",
Length, To.B[0], To.B[1], To.B[2], To.B[3], To.B[4], To.B[5], Type);
hdr->Dest = To;
Length, To.B[0], To.B[1], To.B[2], To.B[3], To.B[4], To.B[5], Type);
hdr->Dest = To;
@@
-83,9
+86,8
@@
void Link_SendPacket(tAdapter *Adapter, Uint16 Type, tMacAddr To, int Length, vo
memcpy(hdr->Data, Buffer, Length);
memcpy(hdr->Data, Buffer, Length);
- *(Uint32*) &hdr->Data[Length] = 0;
- *(Uint32*) &hdr->Data[Length] = htonl( Link_CalculateCRC(buf, bufSize) );
-
+ *(Uint32*) &hdr->Data[bufSize-4] = 0;
+ *(Uint32*) &hdr->Data[bufSize-4] = htonl( Link_CalculateCRC(buf, bufSize) );
VFS_Write(Adapter->DeviceFD, bufSize, buf);
}
VFS_Write(Adapter->DeviceFD, bufSize, buf);
}
@@
-99,18
+101,21
@@
void Link_WatchDevice(tAdapter *Adapter)
int tid = Proc_SpawnWorker(); // Create a new worker thread
if(tid < 0) {
int tid = Proc_SpawnWorker(); // Create a new worker thread
if(tid < 0) {
-
Warning("[NET ]
Unable to create watcher thread for '%s'", Adapter->Device);
+
Log_Warning("NET", "
Unable to create watcher thread for '%s'", Adapter->Device);
return ;
}
if(tid > 0) {
return ;
}
if(tid > 0) {
- Log
("[NET ]
Watching '%s' using tid %i", Adapter->Device, tid);
+ Log
_Log("Net Link", "
Watching '%s' using tid %i", Adapter->Device, tid);
return ;
}
if( !gbLink_CRCTableGenerated )
Link_InitCRC();
return ;
}
if( !gbLink_CRCTableGenerated )
Link_InitCRC();
+ Threads_SetName(Adapter->Device);
+ Log_Log("Net Link", "Thread %i watching '%s'", Threads_GetTID(), Adapter->Device);
+
// Child Thread
while(Adapter->DeviceFD != -1)
{
// Child Thread
while(Adapter->DeviceFD != -1)
{
@@
-120,33
+125,36
@@
void Link_WatchDevice(tAdapter *Adapter)
Uint32 checksum;
// Wait for a packet (Read on a network device is blocking)
Uint32 checksum;
// Wait for a packet (Read on a network device is blocking)
+ //Log_Debug("NET", "Waiting on adapter FD#0x%x", Adapter->DeviceFD);
ret = VFS_Read(Adapter->DeviceFD, MAX_PACKET_SIZE, buf);
if(ret == -1) break;
ret = VFS_Read(Adapter->DeviceFD, MAX_PACKET_SIZE, buf);
if(ret == -1) break;
- if(ret <= sizeof(tEthernetHeader)) {
- Log
("[NET ]
Recieved an undersized packet");
+ if(ret <=
(int)
sizeof(tEthernetHeader)) {
+ Log
_Log("NET", "
Recieved an undersized packet");
continue;
}
continue;
}
- Log("[NET ] Packet from %02x:%02x:%02x:%02x:%02x:%02x",
+ Log_Log("Net Link",
+ "Packet from %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[0], hdr->Src.B[1], hdr->Src.B[2],
- hdr->Src.B[3], hdr->Src.B[4], hdr->Src.B[5]
- );
- Log("[NET ] to %02x:%02x:%02x:%02x:%02x:%02x",
+ 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[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];
);
checksum = *(Uint32*)&hdr->Data[ret-sizeof(tEthernetHeader)-4];
- Log("[NET ] Checksum 0x%08x", checksum);
+ //Log_Log("NET", "Checksum 0x%08x", checksum);
+ // TODO: Check checksum
// Check if there is a registered callback for this packet type
for( i = giRegisteredTypes; i--; )
{
// Check if there is a registered callback for this packet type
for( i = giRegisteredTypes; i--; )
{
- if(gaRegisteredTypes[i].Type ==
hdr->Type)
break;
+ if(gaRegisteredTypes[i].Type ==
ntohs(hdr->Type))
break;
}
// No? Ignore it
if( i == -1 ) {
}
// No? Ignore it
if( i == -1 ) {
- Log
("[NET ]
Unregistered type 0x%x", ntohs(hdr->Type));
+ Log
_Log("Net Link", "
Unregistered type 0x%x", ntohs(hdr->Type));
continue;
}
continue;
}
@@
-159,7
+167,9
@@
void Link_WatchDevice(tAdapter *Adapter)
);
}
);
}
- Log("[NET ] Watcher terminated (file closed)");
+ Log_Log("NET", "Watcher terminated (file closed)");
+
+ Threads_Exit(0, 0);
}
// From http://www.cl.cam.ac.uk/research/srg/bluebook/21/crc/node6.html
}
// From http://www.cl.cam.ac.uk/research/srg/bluebook/21/crc/node6.html
UCC
git Repository :: git.ucc.asn.au