Bandsteering:  Improved logging.

Adds a new type of logged file, for when bandsteering fails.  Garbage
collection of bandsteering log files is now limited to probe request
logs.

Change-Id: Id6acb034e6ee736aeb65022e0645d3b19bdafe18
diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
index 74a887c..034c9e4 100644
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -1648,6 +1648,8 @@
 				           bandsteer_until.usec);
 				resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
 				goto fail;
+			} else {
+				write_timestamp_file(mgmt, hapd, LOG_BANDSTEERING_FAILED, now);
 			}
 		}
 	}
diff --git a/src/ap/steering.c b/src/ap/steering.c
index 75978c1..f7a7f99 100644
--- a/src/ap/steering.c
+++ b/src/ap/steering.c
@@ -168,6 +168,15 @@
 	return astat.st_ctime - bstat.st_ctime;
 }
 
+/* Only garbage collect LOG_PROBE files. */
+int should_garbage_collect(const struct dirent *name) {
+	char *extension = os_strrchr(name->d_name, '.');
+	char buf[4];
+	os_snprintf(buf, sizeof(buf), ".%d", LOG_PROBE);
+
+	return os_strncmp(extension, buf, sizeof(buf)) == 0;
+}
+
 int garbage_collect_timestamp_files(const char *path) {
 	int num_timestamp_files = 0, num_timestamp_files_deleted = 0, i = 0;
 	struct dirent **namelist;
@@ -186,8 +195,8 @@
 		return -1;
 	}
 
-	num_timestamp_files = scandir(request_logging_path, &namelist, NULL,
-	                              file_ctime_lt);
+	num_timestamp_files = scandir(request_logging_path, &namelist,
+	                              should_garbage_collect, file_ctime_lt);
 	for (i = 0; i < num_timestamp_files; ++i) {
 		if (MAX_STEERING_TIMESTAMP_FILES <
 		    /* The -2 is because scandir includes "." and "..". */
diff --git a/src/ap/steering.h b/src/ap/steering.h
index bc9913e..98b0c40 100644
--- a/src/ap/steering.h
+++ b/src/ap/steering.h
@@ -27,6 +27,7 @@
 typedef enum {
   LOG_PROBE,
   LOG_ASSOC,
+  LOG_BANDSTEERING_FAILED,
   NUM_LOGGED_REQUEST_TYPES } logged_request_type;
 typedef enum {
   LOGGING_PATH,
@@ -62,7 +63,7 @@
                         struct os_reltime *timestamp);
 
 /**
- * Delete all but the most recent MAX_TIMESTAMP_FILES files in
+ * Delete all but the most recent MAX_TIMESTAMP_FILES files of type LOG_PROBE in
  * request_logging_path.  Returns the number of files deleted.
  */
 int garbage_collect_timestamp_files();