Index: hci_comm_listener.c
===================================================================
--- hci_comm_listener.c	(revision 56)
+++ hci_comm_listener.c	(revision 57)
@@ -15,7 +15,12 @@
 #include <string.h>
 #include <unistd.h>
 #include "../mxml/mxml.h"
+#include "hciChanged.h"
 
+// Global variables from startup/main.c
+    extern pthread_mutex_t mtx;
+    extern int hciChanged;
+
 int listenTo(unsigned short int portNum) {
 
     // Holders
@@ -34,6 +39,11 @@
 		printf("HCI comm error: Cannot allocate buffer.\n");
 		return HCI_COMM_ERR_BUF_ALOC_FAIL;
 	}
+	char *lineBuffer = malloc(HCI_COMM_LINE_BUFFER_SIZE * sizeof(char));
+	if(lineBuffer == NULL) {
+		printf("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);
@@ -68,6 +78,11 @@
 	// Infinite listening
 	while(1) {
 
+        memset(responseBuffer,'\0',HCI_COMM_RESPONSE_BUFFER_SIZE);
+        memset(requestBuffer,'\0',HCI_COMM_REQUEST_BUFFER_SIZE);
+        memset(lineBuffer,'\0',HCI_COMM_LINE_BUFFER_SIZE);
+        responseLength = 0;
+
 	    printf("[hci_comm_listener] Waiting for new connection...\n");
 
 		// Accept request
@@ -74,9 +89,6 @@
 		int connectionHolder = accept(socketHolder,NULL,NULL);
 		if(connectionHolder < 0) {
 			printf("HCI comm error: Error accepting request.\n");
-            strcpy(responseBuffer,"<logic-response type=\"error\">Could not accept request!</logic-response>");
-            responseLength = strlen(responseBuffer);
-            write(connectionHolder,responseBuffer,responseLength);
             shutdown(connectionHolder,SHUT_RDWR);
             close(connectionHolder);
             continue;
@@ -142,14 +154,50 @@
             responseLength = strlen(responseBuffer);
             printf("[hci_comm_listener] Response length formed: %d\n",responseLength);
         } else if(strcmp(attrVal,"getConfig") == 0) {
+            printf("[hci_comm_listener] getConfig request\n");
             // TODO
         } else if(strcmp(attrVal,"setConfig") == 0) {
+            printf("[hci_comm_listener] setConfig request\n");
             // TODO
         } else if(strcmp(attrVal,"getScenarios") == 0) {
-            // TODO
+            printf("[hci_comm_listener] getScenarios request\n");
+            FILE *fp;
+            if(fp = fopen("./scenariotree.xml", "r")) {
+                printf("[hci_comm_listener] File opened\n");
+                strcat(responseBuffer,"<logic-response type=\"getScenarios\">");
+                while(fgets(lineBuffer,HCI_COMM_LINE_BUFFER_SIZE,fp)) {
+                    strcat(responseBuffer,lineBuffer);
+                }
+                strcat(responseBuffer,"</logic-response>");
+                responseLength = strlen(responseBuffer);
+                fclose(fp);
+            } else {
+                 printf("[hci_comm_listener] Error: Can't open file scenariotree.xml\n");
+                 strcpy(responseBuffer,"<logic-response type=\"error\">Could not read file!</logic-response>");
+                 responseLength = strlen(responseBuffer);
+            }
         } else if(strcmp(attrVal,"setScenarios") == 0) {
-            // TODO
+            printf("[hci_comm_listener] setScenarios request\n");
+            // Prepare new content for scenariotree.xml
+            strncpy(lineBuffer,requestBuffer+54,strlen(requestBuffer)-(54+14+2));
+            strcpy(requestBuffer,"<?xml version=\"1.0\"?>");
+            strcat(requestBuffer,lineBuffer);
+            FILE *fp;
+            if(fp = fopen("./scenariotree.xml", "w")) {
+                fputs(requestBuffer,fp);
+                fclose(fp);
+                pthread_mutex_lock(&mtx);
+                hciChanged = HCI_CHANGED_SCENARIOS;
+                pthread_mutex_unlock(&mtx);
+                strcpy(responseBuffer,"<logic-response type=\"setScenarios\"></logic-response>");
+                responseLength = strlen(responseBuffer);
+            } else {
+                printf("[hci_comm_listener] Error: Can't open file scenariotree.xml for writing\n");
+                strcpy(responseBuffer,"<logic-response type=\"error\">Could not write file!</logic-response>");
+                responseLength = strlen(responseBuffer);
+            }
         } else if(strcmp(attrVal,"executeAction") == 0) {
+            printf("[hci_comm_listener] executeAction request\n");
             // TODO
         } else {
             strcpy(responseBuffer,"<logic-response type=\"error\">Invalid request!</logic-response>");
