BIN = ../nettest
# Kernel Sources (compiled with -ffreestanding)
K_OBJ := lib.o adt.o
-#K_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o
+K_OBJ += vfs/acls.o vfs/io.o vfs/fs/devfs.o
+#K_OBJ += vfs/main.o vfs/open.o vfs/io.o vfs/dir.o
#K_OBJ += vfs/nodecache.o vfs/mount.o vfs/memfile.o # vfs/select.o
#K_OBJ += vfs/fs/root.o vfs/fs/devfs.o
#K_OBJ += drvutil_disk.o drv/proc.o
--- /dev/null
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * nettest.h
+ * - Common functions
+ */
+#ifndef _NETTEST_H_
+#define _NETTEST_H_
+
+#include <stddef.h>
+
+extern int NativeNic_AddDev(char *Desc);
+
+extern void *NetTest_OpenTap(const char *Name);
+extern size_t NetTest_WritePacket(void *Handle, size_t Size, const void *Data);
+extern size_t NetTest_ReadPacket(void *Handle, size_t MaxSize, void *Data);
+
+#endif
+
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * main.c
+ * - Program Core
+ */
+#include <stdio.h>
+#include <acess_logging.h>
+#include <nettest.h>
+#include <string.h>
+
+extern int IPStack_Install(char **Args);
+
+// === CODE ===
+void PrintUsage(const char *ProgramName)
+{
+ fprintf(stderr, "Usage: %s <commands...>\n", ProgramName);
+ fprintf(stderr, "\n");
+ fprintf(stderr,
+ "-dev <tapdev>:<mac>\n"
+ "-ip <dev>,<addr>,<mask>\n"
+ "-route <net>,<mask>,<nexthop>\n"
+ );
+}
+
+int main(int argc, char *argv[])
+{
+ if( argc <= 1 ) {
+ PrintUsage(argv[0]);
+ return 1;
+ }
+
+ // Startup
+ {
+ char *ipstack_args[] = {NULL};
+ IPStack_Install( ipstack_args );
+ }
+
+ for( int i = 0; i < argc; i ++ )
+ {
+ if( argv[i][0] != '-' ) {
+ }
+ else if( strcmp(argv[i], "-dev") == 0 )
+ {
+ if( ++i == argc ) { PrintUsage(argv[0]); return 1; }
+ NativeNic_AddDev(argv[i]);
+ }
+ }
+
+ // Run suite
+
+
+ // Teardown
+
+ return 0;
+}
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * nic.c
+ * - Acess -> TAP Wrapper
+ */
+#include <acess.h>
+#include <IPStack/include/adapters_api.h>
+#include <nettest.h>
+
+// === CONSTANTS ===
+static const int MTU = 1520;
+
+// === PROTOTYPES ===
+void NativeNic_int_FreePacket(void *Ptr, size_t pkt_length, size_t Unused, const void *DataPtr);
+tIPStackBuffer *NativeNic_WaitForPacket(void *Ptr);
+ int NativeNic_SendPacket(void *Ptr, tIPStackBuffer *Buffer);
+
+// === GLOBALS ===
+tIPStack_AdapterType gNativeNIC_AdapterType = {
+ .Name = "NativeNIC",
+ .Type = 0, // TODO: Differentiate differnet wire protos and speeds
+ .Flags = 0, // TODO: IP checksum offloading, MAC checksum offloading etc
+ .SendPacket = NativeNic_SendPacket,
+ .WaitForPacket = NativeNic_WaitForPacket
+ };
+
+// === CODE ===
+int NativeNic_AddDev(char *DevDesc)
+{
+ Uint8 macaddr[6];
+ char *colonpos = strchr(DevDesc, ':');
+ if( !colonpos )
+ return -1;
+ *colonpos = 0;
+ if( UnHex(macaddr, 6, DevDesc) != 6 )
+ return -1;
+ void *ptr = NetTest_OpenTap(colonpos+1);
+ if( !ptr )
+ return 1;
+ IPStack_Adapter_Add(&gNativeNIC_AdapterType, ptr, macaddr);
+
+ return 0;
+}
+
+void NativeNic_int_FreePacket(void *Ptr, size_t pkt_length, size_t Unused, const void *DataPtr)
+{
+ free( (void*)DataPtr );
+}
+
+tIPStackBuffer *NativeNic_WaitForPacket(void *Ptr)
+{
+ char *buf = malloc( MTU );
+ size_t len;
+
+ len = NetTest_ReadPacket(Ptr, MTU, buf);
+
+ tIPStackBuffer *ret = IPStack_Buffer_CreateBuffer(1);
+ IPStack_Buffer_AppendSubBuffer(ret, len, 0, buf, NativeNic_int_FreePacket, Ptr);
+ return ret;
+}
+
+int NativeNic_SendPacket(void *Ptr, tIPStackBuffer *Buffer)
+{
+ size_t len = IPStack_Buffer_GetLength(Buffer);
+
+ // Check against MTU
+ if( len > MTU )
+ return -1;
+
+ // Serialise into stack
+ char buf[len];
+ IPStack_Buffer_GetData(Buffer, buf, len);
+
+ NetTest_WritePacket(Ptr, len, buf);
+ return 0;
+}
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * tap.c
+ * - TAP Network driver
+ */
+#include <nettest.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+//#include <linux/if.h>
+#include <linux/if_tun.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+// === CODE ===
+void *NetTest_OpenTap(const char *Name)
+{
+ int rv;
+
+ struct ifreq ifr;
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
+
+ if( Name[0] != '\0' )
+ {
+ if( strlen(Name) > IFNAMSIZ )
+ return NULL;
+ strncpy(ifr.ifr_name, Name, IFNAMSIZ);
+ }
+
+ int fd = open("/dev/net/tun", O_RDWR);
+ if( fd < 0 )
+ {
+ perror("NetTest_OpenTap - open");
+ return NULL;
+ }
+
+ if( (rv = ioctl(fd, TUNSETIFF, &ifr)) )
+ {
+ perror("NetTest_OpenTap - ioctl(TUNSETIFF)");
+ fprintf(stderr, "Opening TUN/TAP device '%s'\n", Name);
+ close(fd);
+ return NULL;
+ }
+
+ return (void*)(intptr_t)fd;
+}
+
+size_t NetTest_WritePacket(void *Handle, size_t Size, const void *Data)
+{
+ return write( (intptr_t)Handle, Data, Size);
+}
+
+size_t NetTest_ReadPacket(void *Handle, size_t MaxSize, void *Data)
+{
+ return read( (intptr_t)Handle, Data, MaxSize);
+}
+/*
+ * Acess2 Networking Test Suite (NetTest)
+ * - By John Hodge (thePowersGang)
+ *
+ * vfs_shim.c
+ * - VFS Layer Emulation
+ */
+#include <vfs.h>
+#include <vfs_int.h>
+#include <events.h>
+
+// === CODE ===
+int VFS_SelectNode(tVFS_Node *Node, int Type, tTime *Timeout, const char *Name)
+{
+
+ return 0;
+}
+
+int VFS_MarkAvaliable(tVFS_Node *Node, BOOL bAvail)
+{
+ Node->DataAvaliable = bAvail;
+ if( Node->DataAvaliable && Node->ReadThreads )
+ Threads_PostEvent( (void*)Node->ReadThreads, THREAD_EVENT_VFS );
+ return 0;
+}
+
+int VFS_MarkError(tVFS_Node *Node, BOOL bError)
+{
+ Node->ErrorOccurred = bError;
+ if( Node->ErrorOccurred && Node->ErrorThreads )
+ Threads_PostEvent( (void*)Node->ErrorThreads, THREAD_EVENT_VFS );
+ return 0;
+}
+
+int VFS_Open(const char *Path, Uint Flags)
+{
+ return -1;
+}
+
+void VFS_Close(int FD)
+{
+}
+
+tVFS_Handle *VFS_GetHandle(int FD)
+{
+ return NULL;
+}
+
NOBJ := logging.o misc.o
KOBJ := threads.o time.o mutex.o
+
+NOBJ := $(NOBJ:%.o=obj/%.o)
+KOBJ := $(KOBJ:%.o=obj/%.o)
OBJ := $(NOBJ) $(KOBJ)
BIN := ../libnativelib.a
$(BIN): $(OBJ)
ar cru $(BIN) $(OBJ)
-$(NOBJ): %.o: %.c
- $(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS)
-$(KOBJ): %.o: %.c
- $(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS) -I $(KERNEL_DIR)/include
+$(NOBJ): obj/%.o: %.c
+ @echo [CC Native] $@
+ @mkdir -p $(dir $@)
+ @$(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS)
+$(KOBJ): obj/%.o: %.c
+ @echo [CC Kernel] $@
+ @mkdir -p $(dir $@)
+ @$(CC) -o $@ -c $< $(CFLAGS) $(CPPFLAGS) -I $(KERNEL_DIR)/include
return &a_errno;
}
+struct sThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data)
+{
+ Log_Error("Threads", "TODO - Use pthreads to impliment Proc_SpawnWorker");
+ return NULL;
+}
+