AcessNative - Adding network support
authorJohn Hodge <[email protected]>
Sat, 23 Nov 2013 09:36:13 +0000 (17:36 +0800)
committerJohn Hodge <[email protected]>
Sat, 23 Nov 2013 09:36:13 +0000 (17:36 +0800)
AcessNative/acesskernel_src/Makefile
AcessNative/acesskernel_src/main.c
AcessNative/acesskernel_src/net.c [new file with mode: 0644]
AcessNative/acesskernel_src/net_wrap.c [new file with mode: 0644]
AcessNative/acesskernel_src/net_wrap.h [new file with mode: 0644]

index f90b18b..f831a43 100644 (file)
@@ -32,6 +32,8 @@ BUILDINFO_SRC := $(BUILDINFO_OBJ:%.o=%.c)
 \r
 OBJ := helpers.o threads.o threads_glue.o server.o syscalls.o time.o\r
 OBJ += video.o keyboard.o mouse.o nativefs.o vfs_handle.o ui_sdl.o\r
+OBJ += net.o net_wrap.o\r
+\r
 OBJ := $(addprefix obj-$(PLATFORM)/,$(OBJ))\r
 N_OBJ := $(addprefix obj-$(PLATFORM)/,$(N_OBJ))\r
 K_OBJ := $(addprefix $(KERNEL_SRC)obj-native-$(PLATFORM)/,$(KERNEL_OBJ))\r
index be03fe6..61ed0fd 100644 (file)
@@ -29,6 +29,7 @@ extern void   Debug_SetKTerminal(char *Path);
 extern int     VT_Install(char **Arguments);
 extern int     Mouse_Install(char **Arguments);
 extern int     IPCPipe_Install(char **Arguments);
+extern int     Net_Install(char **Arguments);
 extern int     VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options);
 extern int     VFS_MkDir(const char *Path);
 extern int     SyscallServer(void);
@@ -100,6 +101,7 @@ int main(int argc, char *argv[])
        Mouse_Install(NULL);
        IPCPipe_Install(NULL);
        PTY_Install(NULL);
+       Net_Install(NULL);
        // - Start VTerm
        {
                char    *args[] = {
@@ -129,13 +131,13 @@ int main(int argc, char *argv[])
                args[argcount++] = "valgrind";
                #endif
                args[argcount++] = "./ld-acess";
-               args[argcount++] = "--open";    args[argcount++] = "/Devices/VTerm/0";
-               args[argcount++] = "--open";    args[argcount++] = "/Devices/VTerm/0";
-               args[argcount++] = "--open";    args[argcount++] = "/Devices/VTerm/0";
+               args[argcount++] = "--open";    args[argcount++] = "/Devices/pts/vt0";
+               args[argcount++] = "--open";    args[argcount++] = "/Devices/pts/vt0";
+               args[argcount++] = "--open";    args[argcount++] = "/Devices/pts/vt0";
                for( i = 0; i < rootapp_argc; i ++ )
                        args[argcount+i] = rootapp[i];
                args[argcount+rootapp_argc] = NULL;
-               pid = spawnv(P_NOWAIT, "./ld-acess", args);
+               pid = spawnv(P_NOWAIT, "./ld-acess", (char *const*)args);
                if(pid < 0) {
                        perror("Starting root application [fork(2)]");
                        return 1;
@@ -166,3 +168,8 @@ int Module_EnsureLoaded(const char *Name)
        return 0;
 }
 
+void Proc_PrintBacktrace(void)
+{
+       
+}
+
diff --git a/AcessNative/acesskernel_src/net.c b/AcessNative/acesskernel_src/net.c
new file mode 100644 (file)
index 0000000..1f0f977
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * Acess2 Native Kernel
+ * - Acess kernel emulation on another OS using SDL and UDP
+ *
+ * net.c
+ * - Networking
+ */
+#define DEBUG  0
+#include <acess.h>
+#include <vfs.h>
+#include <fs_devfs.h>
+#include "net_wrap.h"
+
+// === PROTOTYPES ===
+ int   Net_Install(char **Arguments);
+tVFS_Node      *Net_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
+tVFS_Node      *Net_IFace_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
+tVFS_Node      *Net_Routes_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
+
+tVFS_Node      *Net_TCPC_Open(int AddrType);
+size_t Net_TCPC_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags);
+size_t Net_TCPC_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags);
+ int   Net_TCPC_IOCtl(tVFS_Node *Node, int IOCtl, void *Arg);
+void   Net_TCPC_Close(tVFS_Node *Node);
+
+static size_t  _getaddrsize(int type);
+
+// === GLOBALS ===
+tVFS_NodeType  gNet_NT_Root = {
+       .FindDir = Net_Root_FindDir,
+};
+tVFS_NodeType  gNet_NT_IFace = {
+       .FindDir = Net_IFace_FindDir,
+};
+tVFS_NodeType  gNet_NT_Routes = {
+       .FindDir = Net_Routes_FindDir,
+};
+tVFS_NodeType  gNet_NT_TcpC = {
+       .Read = Net_TCPC_Read,
+       .Write = Net_TCPC_Write,
+       .IOCtl = Net_TCPC_IOCtl,
+       .Close = Net_TCPC_Close,
+};
+
+tDevFS_Driver  gNet_DevInfo = {
+       .Name = "ip",
+       .RootNode = {
+               .Type = &gNet_NT_Root,
+               .Flags = VFS_FFLAG_DIRECTORY,
+       }
+};
+tVFS_Node      gNet_Node_IFace4 = {
+       .Type = &gNet_NT_IFace,
+       .Flags = VFS_FFLAG_DIRECTORY,
+       .ImplInt = 4,
+};
+tVFS_Node      gNet_Node_Routes = {
+       .Type = &gNet_NT_Routes,
+       .Flags = VFS_FFLAG_DIRECTORY,
+};
+
+// === CODE ===
+int Net_Install(char **Arguments)
+{
+       DevFS_AddDevice(&gNet_DevInfo);
+       return 0;
+}
+
+tVFS_Node *Net_Root_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
+{
+       if( strcmp(Name, "routes") == 0 )
+               return &gNet_Node_Routes;
+       else if( strcmp(Name, "any4") == 0 )
+               return &gNet_Node_IFace4;
+       else
+               return NULL;
+}
+
+tVFS_Node *Net_IFace_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
+{
+       if( strcmp(Name, "tcpc") == 0 )
+               return Net_TCPC_Open(Node->ImplInt);
+       else
+               return NULL;
+}
+
+tVFS_Node *Net_Routes_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
+{
+       if( Name[0] == '@' ) {
+               switch( Name[1] )
+               {
+               case '4':       return &gNet_Node_IFace4;
+               default:        return NULL;
+               }
+       }
+       else
+               return NULL;
+}
+
+typedef struct
+{
+        int    AddrType;
+       tVFS_Node       Node;
+       short   SrcPort;
+       short   DstPort;
+       void    *DestAddr;
+} tNet_TCPC;
+
+tVFS_Node *Net_TCPC_Open(int AddrType)
+{
+       tNet_TCPC       *ret = calloc(sizeof(tNet_TCPC) + _getaddrsize(AddrType), 1);
+
+       ret->AddrType = AddrType;
+       ret->Node.ImplPtr = ret;
+       ret->Node.Type = &gNet_NT_TcpC;
+       ret->DestAddr = ret + 1;
+
+       return &ret->Node;
+}
+
+size_t Net_TCPC_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags)
+{
+       return Net_Wrap_ReadSocket(Node->Data, Length, Buffer);
+}
+
+size_t Net_TCPC_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags)
+{
+       return Net_Wrap_WriteSocket(Node->Data, Length, Buffer);
+}
+
+int Net_TCPC_IOCtl(tVFS_Node *Node, int IOCtl, void *Data)
+{
+       tNet_TCPC       *tcpc = Node->ImplPtr;
+       switch(IOCtl)
+       {
+       case 4:
+               if(!Data)
+                       return tcpc->SrcPort;
+               if(Node->Data)  // Connection is open
+                       return -1;
+               // TODO: Checkmem
+               tcpc->SrcPort = *(Uint16*)Data;
+               return tcpc->SrcPort;
+       case 5:
+               if(!Data)       return tcpc->DstPort;
+               if(Node->Data)  return -1;      // Connection open
+               // TODO: Checkmem
+               tcpc->DstPort = *(Uint16*)Data;
+               return tcpc->DstPort;
+       case 6:
+               if(Node->Data)  return -1;      // Connection open
+               memcpy(tcpc->DestAddr, Data, _getaddrsize(tcpc->AddrType));
+               return 0;
+       case 7: // Connect
+               Node->Data = Net_Wrap_ConnectTcp(Node, tcpc->SrcPort, tcpc->DstPort,
+                       tcpc->AddrType, tcpc->DestAddr);
+               return (Node->Data == NULL);
+       case 8:
+               Debug("TODO: TCPC rx buffer length");
+               return -1;
+       default:
+               return -1;
+       }
+}
+
+void Net_TCPC_Close(tVFS_Node *Node)
+{
+       tNet_TCPC *tcpc = Node->ImplPtr;
+       Node->ReferenceCount --;
+       if( Node->ReferenceCount == 0 )
+       {
+               Net_Wrap_CloseSocket(Node->Data);
+               free(tcpc);
+       }
+}
+
+
+static size_t _getaddrsize(int type)
+{
+       switch(type)
+       {
+       case 4: return 4;
+       case 6: return 16;
+       default:        return 0;
+       }
+}
+
diff --git a/AcessNative/acesskernel_src/net_wrap.c b/AcessNative/acesskernel_src/net_wrap.c
new file mode 100644 (file)
index 0000000..0b22e77
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Acess2 Native Kernel
+ * - Acess kernel emulation on another OS using SDL and UDP
+ *
+ * net.c
+ * - Networking
+ */
+#include <unistd.h>
+#include <logdebug.h>
+#include "net_wrap.h"
+
+typedef struct sNetSocket      tNetSocket;
+
+struct sNetSocket
+{
+       tNetSocket      *Next;
+        int    FD;
+};
+
+tNetSocket     *gNet_Wrap_FirstSocket;
+tNetSocket     *gNet_Wrap_LastSocket;
+
+// === CODE ===
+void *Net_Wrap_ConnectTcp(void *Node, short SrcPort, short DstPtr, int Type, const void *Addr)
+{
+       return NULL;
+}
+
+size_t Net_Wrap_ReadSocket(void *Handle, size_t Bytes, void *Dest)
+{
+       tNetSocket      *hdl = Handle;
+       if(!hdl)        return -1;
+       return read(hdl->FD, Dest, Bytes);
+}
+
+size_t Net_Wrap_WriteSocket(void *Handle, size_t Bytes, const void *Dest)
+{
+       tNetSocket      *hdl = Handle;
+       if(!hdl)        return -1;
+       return write(hdl->FD, Dest, Bytes);
+}
+
+void Net_Wrap_CloseSocket(void *Handle)
+{
+       // TODO
+}
+
diff --git a/AcessNative/acesskernel_src/net_wrap.h b/AcessNative/acesskernel_src/net_wrap.h
new file mode 100644 (file)
index 0000000..8d655d2
--- /dev/null
@@ -0,0 +1,11 @@
+
+#ifndef _NET_WRAP_H_
+#define _NET_WRAP_H_
+
+extern void    *Net_Wrap_ConnectTcp(void *Node, short SrcPort, short DstPtr, int Type, const void *Addr);
+extern size_t  Net_Wrap_ReadSocket(void *Handle, size_t Bytes, void *Dest);
+extern size_t  Net_Wrap_WriteSocket(void *Handle, size_t Bytes, const void *Dest);
+extern void    Net_Wrap_CloseSocket(void *Handle);
+
+#endif
+

UCC git Repository :: git.ucc.asn.au