Index: logic/trunk/src/hci_comm/hci_comm.h
===================================================================
--- logic/trunk/src/hci_comm/hci_comm.h	(revision 0)
+++ logic/trunk/src/hci_comm/hci_comm.h	(revision 7)
@@ -0,0 +1,30 @@
+/*
+ * hci_comm.h
+ *
+ * 2011, Aleksander Besir (alex.besir@gmail.com)
+ *
+ */
+ 
+ #ifndef _ENERAPTOR_HCI_COMM
+ #define _ENERAPTOR_HCI_COMM
+ 
+ // Error codes
+ #define HCI_COMM_TERMINATED_BY_LOGIC  0 // Terminated by logic
+ #define HCI_COMM_ERR_NEW_SOCKET_FAIL -1 // Cannot create new socket
+ #define HCI_COMM_ERR_BIND_FAIL       -2 // Cannot bind socket to port
+ #define HCI_COMM_ERR_LISTEN_FAIL     -3 // Cannot listen to port
+ #define HCI_COMM_ERR_ACCEPT_FAIL     -4 // Cannot accept request
+ #define HCI_COMM_ERR_READ_FAIL       -5 // Cannot read request
+ #define HCI_COMM_ERR_WRITE_FAIL      -6 // Cannot write response
+ #define HCI_COMM_ERR_BUF_ALOC_FAIL  -99 // Cannot alocate memory for buffer
+ 
+ // Program codes
+ #define HCI_COMM_TERMINATE           -1 // Terminates the infinite listening loop
+ 
+ // Constants
+ #define HCI_COMM_REQUEST_BUFFER_SIZE  1024 // Bufer size in bytes
+   // TODO: buffer size should be bigger!
+
+ int listenTo(unsigned short int portNum);
+ 
+ #endif
\ No newline at end of file
Index: logic/trunk/src/hci_comm/hci_comm_listener.c
===================================================================
--- logic/trunk/src/hci_comm/hci_comm_listener.c	(revision 0)
+++ logic/trunk/src/hci_comm/hci_comm_listener.c	(revision 7)
@@ -0,0 +1,101 @@
+/*
+ * hci_comm_listener.c
+ *
+ * 2011, Aleksander Besir (alex.besir@gmail.com)
+ *
+ */
+
+#include "hci_comm.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int listenTo(unsigned short int portNum) {
+	
+	// Buffer
+	char *requestBuffer = malloc(HCI_COMM_REQUEST_BUFFER_SIZE * sizeof char);
+	if(requestBuffer = NULL) {
+		fprintf(stderr,"HCI comm error: Cannot allocate buffer.\n");
+		return HCI_COMM_ERR_BUF_ALOC_FAIL;
+	}
+	
+	// Socket holder
+	int socketHolder = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+	if(socketHolder < 0) {
+		fpritf(stderr,"HCI comm error: Cannot create a new socket.\n");
+		return HCI_COMM_ERR_NEW_SOCKET_FAIL;
+	}
+	
+	// Socket address holder
+	struct sockaddr_in socketAddressHolder;
+	memset(&socketAddressHolder, 0, sizeof socketAddressHolder);
+	stSockAddr.sin_family      = AF_INET;
+    stSockAddr.sin_port        = htons(portNum);
+    stSockAddr.sin_addr.s_addr = INADDR_ANY;
+
+	// Bind socket to port
+	int bindingResult = bind(socketHolder,(struct sockaddr *)&socketAddressHolder, sizeof socketAddressHolder);
+	if(bindingResult == -1) {
+		fpritf(stderr,"HCI comm error: Cannot bind socket to port %d.\n",portNum);
+		close(socketHolder);
+		return HCI_COMM_ERR_BIND_FAIL;
+	}
+	
+	// Listen to port
+	int listenResult = listen(socketHolder, 10);
+	if(listenResult == -1) {
+		fpritf(stderr,"HCI comm error: Cannot listen to port %d.\n",portNum);
+		close(socketHolder);
+		return HCI_COMM_ERR_LISTEN_FAIL;
+	}
+	
+	// Infinite listening
+	while(true) {
+		
+		// Accept request
+		int connectionHolder = accept(socketHolder,NULL,NULL);
+		if(connectionHolder < 0) {
+			fpritf(stderr,"HCI comm error: Error accepting request.\n");
+			close(socketHolder);
+			return HCI_COMM_ERR_ACCEPT_FAIL;
+		}
+		
+		// Read request
+		int readResult = read(connectionHolder,requestBuffer,HCI_COMM_REQUEST_BUFFER_SIZE);
+		if(readResult < 0) {
+			fpritf(stderr,"HCI comm error: Error reading request.\n");
+			close(socketHolder);
+			return HCI_COMM_ERR_READ_FAIL;
+		}
+		
+		// Create a response
+		char *hciResponse = "Works!"; // TODO
+		int responseLength = 6; // TODO
+		
+		// Check if logic wants to terminate the infinite loop
+		if(responseLength == HCI_COMM_TERMINATE) {
+			break;
+		}
+		
+		// Send response
+		int writeResult = write(connectionHolder,hciResponse,responseLength);
+		if(writeResult < 0) {
+			fpritf(stderr,"HCI comm error: Error writting response.\n");
+			close(socketHolder);
+			return HCI_COMM_ERR_WRITE_FAIL;
+		}
+		
+	}
+	
+	// Terminate
+	close(socketHolder);
+	free(requestBuffer);
+	requestBuffer = NULL;
+	return HCI_COMM_TERMINATED_BY_LOGIC;
+
+}
Index: logic/trunk/src/startup/main.c
===================================================================
--- logic/trunk/src/startup/main.c	(revision 0)
+++ logic/trunk/src/startup/main.c	(revision 7)
@@ -0,0 +1,9 @@
+
+#import "hci_comm/hci_comm.h"
+
+int main(int argc, char *argv[]) {
+
+	listenTo(1100);
+	return 0;
+
+}
\ No newline at end of file
Index: logic/trunk/Makefile
===================================================================
--- logic/trunk/Makefile	(revision 0)
+++ logic/trunk/Makefile	(revision 7)
@@ -0,0 +1,19 @@
+# 
+# (2011, Aleksander Besir (alex.besir@gmail.com)
+#
+
+CC=gcc
+CFLAGS=-Wall -I .
+BIN=bin
+SRC=src
+
+OBJ=$(SRC)/hci_comm/hci_comm_listener.o $(SRC)/startup/main.o
+OBJC=$(SRC)/buf.h $(SRC)/buf_nf.c $(SRC)/buf_sim.h $(SRC)/buf_sim.c
+
+all: $(BIN)/startup
+
+%.o: %.c
+	$(CC) -c -o $@ $< $(CFLAGS)
+	
+$(BIN)/Startup: $(OBJ)
+	$(CC) -o $(BIN)/startup $^ $(CFLAGS)
\ No newline at end of file
