// === IMPORTS ===
extern int ARP_Initialise();
+extern void UDP_Initialise();
+extern void TCP_Initialise();
extern int IPv4_Initialise();
extern int IPv4_Ping(tInterface *Iface, tIPv4 Addr);
+extern int IPv6_Initialise();
+//extern int IPv6_Ping(tInterface *Iface, tIPv6 Addr);
// === PROTOTYPES ===
int IPStack_Install(char **Arguments);
{
int i = 0;
- // Install Handlers
+ // Layer 2 - Data Link Layer
ARP_Initialise();
+ // Layer 3 - Network Layer
IPv4_Initialise();
+ IPv6_Initialise();
+ // Layer 4 - Transport Layer
+ TCP_Initialise();
+ UDP_Initialise();
if(Arguments)
{
DevFS_AddDevice( &gIP_DriverInfo );
- return 1;
+ return MODULE_ERR_OK;
}
/**
*/
int IPStack_AddFile(tSocketFile *File)
{
+ Log_Log("IPStack", "Added file '%s'", File->Name);
File->Next = gIP_FileTemplates;
gIP_FileTemplates = File;
return 0;
return NULL;
}
- name = malloc(6);
- name[0] = 'i';
- name[1] = 'p';
+ name = malloc(4);
// Create the name
Pos = iface->Node.ImplInt;
if(Pos < 10) {
- name[2] = '0' + Pos;
- name[3] = '\0';
+ name[0] = '0' + Pos;
+ name[1] = '\0';
}
else if(Pos < 100) {
- name[2] = '0' + Pos/10;
- name[3] = '0' + Pos%10;
- name[4] = '\0';
+ name[0] = '0' + Pos/10;
+ name[1] = '0' + Pos%10;
+ name[2] = '\0';
}
else {
- name[2] = '0' + Pos/100;
- name[3] = '0' + (Pos/10)%10;
- name[4] = '0' + Pos%10;
- name[5] = '\0';
+ name[0] = '0' + Pos/100;
+ name[1] = '0' + (Pos/10)%10;
+ name[2] = '0' + Pos%10;
+ name[3] = '\0';
}
LEAVE('s', name);
ENTER("pNode sName", Node, Name);
- if(Name[0] != 'i' || Name[1] != 'p') {
- LEAVE('n');
- return NULL;
- }
-
- i = 2; num = 0;
+ i = 0; num = 0;
while('0' <= Name[i] && Name[i] <= '9')
{
num *= 10;
char *IPStack_Iface_ReadDir(tVFS_Node *Node, int Pos)
{
tSocketFile *file = gIP_FileTemplates;
- while(Pos-- && file) file = file->Next;
+ while(Pos-- && file) {
+ file = file->Next;
+ }
if(!file) return NULL;
"get_address", "set_address",
"getset_subnet",
"get_gateway", "set_gateway",
+ "get_device",
"ping",
NULL
};
}
break;
+ /*
+ * get_device
+ * - Gets the name of the attached device
+ */
+ case 10:
+ if( Data == NULL )
+ LEAVE_RET('i', iface->Adapter->DeviceLen);
+ if( !CheckMem( Data, iface->Adapter->DeviceLen+1 ) )
+ LEAVE_RET('i', -1);
+ strcpy( Data, iface->Adapter->Device );
+ return iface->Adapter->DeviceLen;
+
/*
* ping
* - Send an ICMP Echo
*/
- case 10:
+ case 11:
switch(iface->Type)
{
case 0:
int IPStack_AddInterface(char *Device)
{
tInterface *iface;
+ tAdapter *card;
ENTER("sDevice", Device);
+ card = IPStack_GetAdapter(Device);
+
iface = malloc(sizeof(tInterface));
if(!iface) {
LEAVE('i', -2);
// Create Node
iface->Node.ImplPtr = iface;
- iface->Node.ImplInt = giIP_NextIfaceId++;
iface->Node.Flags = VFS_FFLAG_DIRECTORY;
- iface->Node.Size = 0;
+ iface->Node.Size = -1;
iface->Node.NumACLs = 1;
iface->Node.ACLs = &gVFS_ACL_EveryoneRX;
iface->Node.ReadDir = IPStack_Iface_ReadDir;
return -1; // Return ERR_YOUFAIL
}
+ // Delay setting ImplInt until after the adapter is opened
+ // Keeps things simple
+ iface->Node.ImplInt = giIP_NextIfaceId++;
+
// Append to list
LOCK( &glIP_Interfaces );
if( gIP_Interfaces ) {
// Fill Structure
strcpy( dev->Device, Path );
dev->NRef = 1;
+ dev->DeviceLen = strlen(Path);
// Open Device
dev->DeviceFD = VFS_Open( dev->Device, VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE );