diff -ur hostapd-2.2/hostapd/config_file.c 2.2-manna/hostapd/config_file.c
--- hostapd-2.2/hostapd/config_file.c	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/hostapd/config_file.c	2014-07-07 20:56:43.000000000 +0200
@@ -116,7 +116,6 @@
 	return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
 }
 
-
 static int hostapd_config_read_maclist(const char *fname,
 				       struct mac_acl_entry **acl, int *num)
 {
@@ -1876,6 +1875,14 @@
 		bss->logger_syslog = atoi(pos);
 	} else if (os_strcmp(buf, "logger_stdout") == 0) {
 		bss->logger_stdout = atoi(pos);
+	// KARMA START
+	} else if (os_strcmp(buf, "enable_karma") == 0) {
+		int val = atoi(pos);
+		conf->enable_karma = (val != 0);
+		if (conf->enable_karma) {
+			wpa_printf(MSG_DEBUG, "KARMA: Enabled");
+		}
+	// KARMA END
 	} else if (os_strcmp(buf, "dump_file") == 0) {
 		wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
 			   line);
@@ -3206,6 +3213,11 @@
 
 	bss = conf->last_bss = conf->bss[0];
 
+	// KARMA START
+	conf->enable_karma = 0; //default off
+	
+	// KARMA END
+
 	while (fgets(buf, sizeof(buf), f)) {
 		bss = conf->last_bss;
 		line++;
diff -ur hostapd-2.2/hostapd/ctrl_iface.c 2.2-manna/hostapd/ctrl_iface.c
--- hostapd-2.2/hostapd/ctrl_iface.c	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/hostapd/ctrl_iface.c	2014-07-07 20:59:47.000000000 +0200
@@ -37,6 +37,7 @@
 #include "wps/wps.h"
 #include "config_file.h"
 #include "ctrl_iface.h"
+#include "ap/beacon.h"
 
 
 struct wpa_ctrl_dst {
@@ -156,6 +157,96 @@
 	return 0;
 }
 
+// KARMA START
+
+static int hostapd_ctrl_iface_karma_get_state (struct hostapd_data *hapd)
+{
+	wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE STATUS QUERY");
+	return hapd->iconf->enable_karma;
+}
+// Used in the hostapd_ctrl_iface_karma_add_mac function to sort the MAC ACL list
+static int hostapd_acl_comp(const void *a, const void *b)
+{
+	const struct mac_acl_entry *aa = a;
+	const struct mac_acl_entry *bb = b;
+	return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
+}
+
+static int hostapd_ctrl_iface_karma_add_mac (struct hostapd_data *hapd,
+					     const char *mac, int black) {
+
+	u8 addr[ETH_ALEN];
+	struct mac_acl_entry *newacl;
+	struct hostapd_bss_config *bss;
+	char buf[128];
+	struct mac_acl_entry **acl;
+	int *num;
+	// for now we don't care about VLANs so just hardcoding 0
+	int vlan_id = 0;
+
+	if (hwaddr_aton(mac, addr)) {
+		wpa_printf(MSG_ERROR, "Invalid MAC address '%s'", buf);
+		return -1;
+	}
+
+	bss = hapd->iconf->last_bss;
+	if (black) {
+		hostapd_ctrl_iface_deauthenticate(hapd, buf);
+		num = &bss->num_deny_mac;
+		acl = &bss->deny_mac;
+	} else {
+		num = &bss->num_accept_mac;
+		acl = &bss->accept_mac;
+	}
+
+	newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
+	if (newacl == NULL) {
+		wpa_printf(MSG_ERROR, "MAC list reallocation failed");
+		return -1;
+	}
+
+	*acl = newacl;
+	os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
+	(*acl)[*num].vlan_id = vlan_id;
+	(*num)++;
+
+	qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
+
+	//num = &bss->num_deny_mac;
+	wpa_printf(MSG_DEBUG, "There are now %i MAC addresses in the list", *num);
+
+	return 0;
+}
+
+static int hostapd_ctrl_iface_karma_change_ssid (struct hostapd_data *hapd,
+					     const char *ssid) {
+	wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE CHANGE SSID %s", ssid);
+
+	if (strlen(ssid) > HOSTAPD_MAX_SSID_LEN || strlen(ssid) == 0) {
+		return -1;
+	}
+
+	hapd->conf->ssid.ssid_len = strlen(ssid);
+	// Not sure if the +1 is needed here or not
+	os_memcpy(hapd->conf->ssid.ssid, ssid, strlen(ssid) + 1);
+	ieee802_11_set_beacon(hapd);
+	wpa_printf(MSG_DEBUG, "CTRL_IFACE KARMA Default SSID Changed");
+	return 0;
+}
+
+static int hostapd_ctrl_iface_karma_enable_disable (struct hostapd_data *hapd,
+						int status)
+{
+	if (status) {
+		wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE ENABLED");
+	} else {
+		wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE DISABLED");
+	}
+	hapd->iconf->enable_karma = status;
+
+	return 0;
+}
+// KARMA END
 
 #ifdef CONFIG_IEEE80211W
 #ifdef NEED_AP_MLME
@@ -253,7 +344,6 @@
 	return ret;
 }
 
-
 #ifdef CONFIG_WPS_NFC
 static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data *hapd,
 					       char *pos)
@@ -1546,7 +1636,52 @@
 	} else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
 		reply_len = hostapd_ctrl_iface_vendor(hapd, buf + 7, reply,
 						      reply_size);
-
+	// KARMA
+	} else if (os_strcmp(buf, "KARMA_STATE") == 0) {
+		if (hostapd_ctrl_iface_karma_get_state(hapd)) {
+			os_memcpy(reply, "ENABLED\n", 8);
+			reply_len = 8;
+		} else {
+			os_memcpy(reply, "DISABLED\n", 9);
+			reply_len = 9;
+		}
+	} else if (os_strncmp(buf, "KARMA_ADD_WHITE_MAC ", 20) == 0) {
+		if (hostapd_ctrl_iface_karma_add_mac (hapd, buf + 20, 0)) {
+			reply_len = -1;
+		} else {
+			os_memcpy(reply, "ADDED\n", 6);
+			reply_len = 6;
+		}
+	} else if (os_strncmp(buf, "KARMA_ADD_BLACK_MAC ", 20) == 0) {
+		if (hostapd_ctrl_iface_karma_add_mac (hapd, buf + 20, 1)) {
+			reply_len = -1;
+		} else {
+			os_memcpy(reply, "ADDED\n", 6);
+			reply_len = 6;
+		}
+	} else if (os_strcmp(buf, "KARMA_GET_SSID") == 0) {
+		wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE GET SSID");
+		size_t len;
+ 
+		// +2 for the new line and the null byte terminator
+		len = hapd->conf->ssid.ssid_len + 2;
+		os_snprintf(reply, len, "%s\n", hapd->conf->ssid.ssid);
+		reply_len = len;
+ 
+	} else if (os_strncmp(buf, "KARMA_CHANGE_SSID ", 18) == 0) {
+		if (hostapd_ctrl_iface_karma_change_ssid (hapd, buf + 18)) {
+			reply_len = -1;
+		} else {
+			os_memcpy(reply, "CHANGED\n", 8);
+			reply_len = 8;
+		}
+	} else if (os_strcmp(buf, "KARMA_DISABLE") == 0) {
+		if (hostapd_ctrl_iface_karma_enable_disable(hapd, 0))
+			reply_len = -1;
+	} else if (os_strcmp(buf, "KARMA_ENABLE") == 0) {
+		if (hostapd_ctrl_iface_karma_enable_disable(hapd, 1))
+			reply_len = -1;
+	// END KARMA
 	} else {
 		os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
 		reply_len = 16;
diff -ur hostapd-2.2/hostapd/hostapd.conf 2.2-manna/hostapd/hostapd.conf
--- hostapd-2.2/hostapd/hostapd.conf	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/hostapd/hostapd.conf	2014-07-07 20:53:33.000000000 +0200
@@ -1,3 +1,7 @@
+# 0 = disabled
+# 1 = enabled
+enable_karma=1
+
 ##### hostapd configuration file ##############################################
 # Empty lines and lines starting with # are ignored
 
@@ -400,18 +404,18 @@
 # disassociation frame is not sent immediately without first polling
 # the STA with a data frame.
 # default: 300 (i.e., 5 minutes)
-#ap_max_inactivity=300
+ap_max_inactivity=3000
 #
 # The inactivity polling can be disabled to disconnect stations based on
 # inactivity timeout so that idle stations are more likely to be disconnected
 # even if they are still in range of the AP. This can be done by setting
 # skip_inactivity_poll to 1 (default 0).
-#skip_inactivity_poll=0
+skip_inactivity_poll=0
 
 # Disassociate stations based on excessive transmission failures or other
 # indications of connection loss. This depends on the driver capabilities and
 # may not be available with all drivers.
-#disassoc_low_ack=1
+disassoc_low_ack=0
 
 # Maximum allowed Listen Interval (how many Beacon periods STAs are allowed to
 # remain asleep). Default: 65535 (no limit apart from field size)
@@ -1739,8 +1743,9 @@
 # as the defaults for the following BSSes. However, it is recommended that all
 # BSSes include explicit configuration of all relevant configuration items.
 #
-#bss=wlan0_0
+#bss=wlan1
 #ssid=test2
+#bssid=02:21:91:01:11:31
 # most of the above items can be used here (apart from radio interface specific
 # items, like channel)
 
diff -ur hostapd-2.2/hostapd/hostapd_cli.c 2.2-manna/hostapd/hostapd_cli.c
--- hostapd-2.2/hostapd/hostapd_cli.c	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/hostapd/hostapd_cli.c	2014-07-07 20:53:33.000000000 +0200
@@ -14,7 +14,7 @@
 #include "utils/eloop.h"
 #include "utils/edit.h"
 #include "common/version.h"
-
+#include "ap/ap_config.h"
 
 static const char *hostapd_cli_version =
 "hostapd_cli v" VERSION_STR "\n"
@@ -86,6 +86,16 @@
 "   interface [ifname]   show interfaces/select interface\n"
 "   level <debug level>  change debug level\n"
 "   license              show full hostapd_cli license\n"
+// KARMA START
+"   ping                   send a ping, get a pong\n"
+"   karma_change_ssid      change the default SSID for when Karma is off\n"
+"   karma_get_ssid         get the default SSID for when Karma is off\n"
+"   karma_enable           enable Karma\n"
+"   karma_disable          disable Karma\n"
+"   karma_get_state        get the state of Karma\n"
+"   karma_add_black_mac    add a MAC to the black list\n"
+"   karma_add_white_mac    add a MAC to the white list\n"
+// KARMA END
 "   quit                 exit hostapd_cli\n";
 
 static struct wpa_ctrl *ctrl_conn;
@@ -345,6 +355,86 @@
 	return wpa_ctrl_command(ctrl, buf);
 }
 
+// KARMA START
+static int hostapd_cli_cmd_karma_change_ssid(struct wpa_ctrl *ctrl, int argc,
+					char *argv[])
+{
+	// Max length of SSID is 32 chars + the command and the null byte
+	char buf[50];
+	if (argc < 1) {
+		printf("Invalid 'change Karma SSID' command - exactly one "
+		       "argument, SSID, is required.\n");
+		return -1;
+	}
+	if (strlen(argv[0]) > HOSTAPD_MAX_SSID_LEN) {
+		printf("The max length of an SSID is %i\n", HOSTAPD_MAX_SSID_LEN);
+		return -1;
+	}
+	os_snprintf(buf, sizeof(buf), "KARMA_CHANGE_SSID %s", argv[0]);
+	return wpa_ctrl_command(ctrl, buf);
+}
+
+static int hostapd_cli_cmd_karma_get_ssid(struct wpa_ctrl *ctrl, int argc,
+					char *argv[])
+{
+	return wpa_ctrl_command(ctrl, "KARMA_GET_SSID");
+}
+
+static int hostapd_cli_cmd_karma_add_white_mac(struct wpa_ctrl *ctrl, int argc,
+					char *argv[])
+{
+	// Max length of MAC is 17 chars + the command and the null byte
+	char buf[50];
+	if (argc < 1) {
+		printf("Invalid 'add white MAC' command - exactly one "
+		       "argument, MAC, is required.\n");
+		return -1;
+	}
+	// Can't find a define for the length of a MAC address as a string
+	// ETH_ALEN is the number of individual bytes
+	if (strlen(argv[0]) != 17) {
+		printf("The MAC should be in the format 00:11:22:33:44:55\n");
+		return -1;
+	}
+	os_snprintf(buf, sizeof(buf), "KARMA_ADD_WHITE_MAC %s", argv[0]);
+	return wpa_ctrl_command(ctrl, buf);
+}
+
+static int hostapd_cli_cmd_karma_add_black_mac(struct wpa_ctrl *ctrl, int argc,
+					char *argv[])
+{
+	// Max length of MAC is 17 chars + the command and the null byte
+	char buf[50];
+	if (argc < 1) {
+		printf("Invalid 'add black MAC' command - exactly one "
+		       "argument, MAC, is required.\n");
+		return -1;
+	}
+	// Can't find a define for the length of a MAC address as a string
+	// ETH_ALEN is the number of individual bytes
+	if (strlen(argv[0]) != 17) {
+		printf("The MAC should be in the format 00:11:22:33:44:55\n");
+		return -1;
+	}
+	os_snprintf(buf, sizeof(buf), "KARMA_ADD_BLACK_MAC %s", argv[0]);
+	return wpa_ctrl_command(ctrl, buf);
+}
+
+// These should be one function with a parameter
+static int hostapd_cli_cmd_karma_disable(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+	return wpa_ctrl_command(ctrl, "KARMA_DISABLE");
+}
+static int hostapd_cli_cmd_karma_enable(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+	return wpa_ctrl_command(ctrl, "KARMA_ENABLE");
+}
+static int hostapd_cli_cmd_karma_get_state(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+	return wpa_ctrl_command(ctrl, "KARMA_STATE");
+}
+// END KARMA
+
 
 #ifdef CONFIG_IEEE80211W
 static int hostapd_cli_cmd_sa_query(struct wpa_ctrl *ctrl, int argc,
@@ -1004,6 +1094,17 @@
 	{ "quit", hostapd_cli_cmd_quit },
 	{ "set", hostapd_cli_cmd_set },
 	{ "get", hostapd_cli_cmd_get },
+// KARMA START
+// Because I always type ? first
+	{ "?", hostapd_cli_cmd_help },
+	{ "karma_add_black_mac", hostapd_cli_cmd_karma_add_black_mac},
+	{ "karma_add_white_mac", hostapd_cli_cmd_karma_add_white_mac},
+	{ "karma_change_ssid", hostapd_cli_cmd_karma_change_ssid},
+	{ "karma_get_ssid", hostapd_cli_cmd_karma_get_ssid},
+	{ "karma_get_state", hostapd_cli_cmd_karma_get_state},
+	{ "karma_disable", hostapd_cli_cmd_karma_disable},
+	{ "karma_enable", hostapd_cli_cmd_karma_enable},
+// END KARMA
 	{ "set_qos_map_set", hostapd_cli_cmd_set_qos_map_set },
 	{ "send_qos_map_conf", hostapd_cli_cmd_send_qos_map_conf },
 	{ "chan_switch", hostapd_cli_cmd_chan_switch },
diff -ur hostapd-2.2/hostapd/main.c 2.2-manna/hostapd/main.c
--- hostapd-2.2/hostapd/main.c	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/hostapd/main.c	2014-07-07 20:53:33.000000000 +0200
@@ -416,7 +416,8 @@
 		"User space daemon for IEEE 802.11 AP management,\n"
 		"IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n"
 		"Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi> "
-		"and contributors\n");
+		"and contributors\n"
+		"Karma patches by Robin Wood - robin@digininja.org & singe dominic@sensepost.com\n");
 }
 
 
diff -ur hostapd-2.2/src/ap/ap_config.h 2.2-manna/src/ap/ap_config.h
--- hostapd-2.2/src/ap/ap_config.h	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/src/ap/ap_config.h	2014-07-07 20:53:33.000000000 +0200
@@ -522,6 +522,10 @@
 	struct hostapd_bss_config **bss, *last_bss;
 	size_t num_bss;
 
+	// KARMA
+	int enable_karma;
+	// KARMA END
+
 	u16 beacon_int;
 	int rts_threshold;
 	int fragm_threshold;
diff -ur hostapd-2.2/src/ap/beacon.c 2.2-manna/src/ap/beacon.c
--- hostapd-2.2/src/ap/beacon.c	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/src/ap/beacon.c	2014-07-07 21:27:18.000000000 +0200
@@ -29,6 +29,9 @@
 #include "hs20.h"
 #include "dfs.h"
 
+// KARMA START
+struct karma_ssid *karma_data = NULL;
+// KARMA END
 
 #ifdef NEED_AP_MLME
 
@@ -324,9 +327,8 @@
 	return pos;
 }
 
-
 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
-				   struct sta_info *sta,
+				   struct sta_info *sta, const u8 *ssid, size_t ssid_len,
 				   const struct ieee80211_mgmt *req,
 				   int is_p2p, size_t *resp_len)
 {
@@ -364,13 +366,21 @@
 
 	/* hardware or low-level driver will setup seq_ctrl and timestamp */
 	resp->u.probe_resp.capab_info =
-		host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
+		host_to_le16(hostapd_own_capab_info(hapd, sta, 1)); // KARMA - FOLLOW
 
 	pos = resp->u.probe_resp.variable;
 	*pos++ = WLAN_EID_SSID;
-	*pos++ = hapd->conf->ssid.ssid_len;
-	os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
-	pos += hapd->conf->ssid.ssid_len;
+	// KARMA START
+	if (hapd->iconf->enable_karma && ssid_len > 0) {
+		*pos++ = ssid_len;
+		os_memcpy(pos, ssid, ssid_len);
+		pos += ssid_len;
+	} else {
+		*pos++ = hapd->conf->ssid.ssid_len;
+		os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
+		pos += hapd->conf->ssid.ssid_len;
+	}
+	// KARMA END
 
 	/* Supported rates */
 	pos = hostapd_eid_supp_rates(hapd, pos);
@@ -455,7 +465,6 @@
 	return (u8 *) resp;
 }
 
-
 enum ssid_match_result {
 	NO_SSID_MATCH,
 	EXACT_SSID_MATCH,
@@ -584,19 +593,42 @@
 
 	res = ssid_match(hapd, elems.ssid, elems.ssid_len,
 			 elems.ssid_list, elems.ssid_list_len);
+ 	// KARMA start
 	if (res != NO_SSID_MATCH) {
-		if (sta)
-			sta->ssid_probe = &hapd->conf->ssid;
+    	if (sta)
+    		sta->ssid_probe = &hapd->conf->ssid;
 	} else {
 		if (!(mgmt->da[0] & 0x01)) {
-			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
-				   " for foreign SSID '%s' (DA " MACSTR ")%s",
-				   MAC2STR(mgmt->sa),
-				   wpa_ssid_txt(elems.ssid, elems.ssid_len),
-				   MAC2STR(mgmt->da),
-				   elems.ssid_list ? " (SSID list)" : "");
+			wpa_printf(MSG_INFO, "ZZZZ : Probe Request from " MACSTR
+				" for foreign SSID '%s' (DA " MACSTR ")%s",
+				MAC2STR(mgmt->sa),
+				wpa_ssid_txt(elems.ssid, elems.ssid_len),
+				MAC2STR(mgmt->da),
+				elems.ssid_list ? " (SSID list)" : "");
+			if (hapd->iconf->enable_karma) {
+				wpa_printf(MSG_MSGDUMP, "KARMA CTRL_IFACE Karma is enabled for handling probe request\n");
+				if (sta) {
+					wpa_printf(MSG_INFO, "ZZZZ : PROBE REQUEST FOR FOREIGN SSID %s WITH STA STRUCTURE", wpa_ssid_txt(elems.ssid, elems.ssid_len));
+					sta->ssid_probe = &hapd->conf->ssid;
+				}
+			}
 		}
-		return;
+		if (hapd->iconf->enable_karma) {
+			struct karma_ssid *d = NULL;
+			HASH_FIND_STR(karma_data, wpa_ssid_txt(elems.ssid, elems.ssid_len), d);
+			if (d == NULL) {
+				//wpa_printf(MSG_INFO, "ZZZZ : ADDING SSID %s(%d) TO THE HASH", wpa_ssid_txt(elems.ssid, elems.ssid_len), elems.ssid_len);
+				d = (struct karma_ssid*)os_malloc(sizeof(struct karma_ssid));
+				os_memcpy(d->ssid_txt, wpa_ssid_txt(elems.ssid, elems.ssid_len), elems.ssid_len+1);
+				os_memcpy(d->ssid, elems.ssid, elems.ssid_len);
+				d->ssid_len = elems.ssid_len;
+				os_memcpy(d->sta_addr, mgmt->sa, ETH_ALEN);
+				HASH_ADD_STR(karma_data, ssid_txt, d);
+			}
+		}
+ 		if (!hapd->iconf->enable_karma)
+			return;
+	// KARMA END
 	}
 
 #ifdef CONFIG_INTERWORKING
@@ -654,8 +686,8 @@
 	}
 #endif /* CONFIG_TESTING_OPTIONS */
 
-	resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
-				      &resp_len);
+	resp = hostapd_gen_probe_resp(hapd, sta, elems.ssid, elems.ssid_len,
+			mgmt, elems.p2p != NULL, &resp_len);
 	if (resp == NULL)
 		return;
 
@@ -668,9 +700,29 @@
 
 	if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
 		wpa_printf(MSG_INFO, "handle_probe_req: send failed");
-
 	os_free(resp);
 
+	// KARMA START
+	struct karma_ssid *k;
+	for ( k = karma_data; k != NULL; k = (struct karma_ssid*)(k->hh.next))
+	{
+		u8 *resp2;
+		size_t resp2_len;
+		if (os_memcmp(k->sta_addr, mgmt->sa, ETH_ALEN) == 0) {
+			wpa_printf(MSG_INFO, "ZZZZ : BROADCAST RESPONSE : %s (%d) for STA " MACSTR, k->ssid_txt, k->ssid_len, MAC2STR(k->sta_addr));
+			resp2 = hostapd_gen_probe_resp(hapd, sta, k->ssid, k->ssid_len, mgmt, elems.p2p != NULL, &resp2_len);
+			if (resp2 == NULL) {
+				wpa_printf(MSG_INFO, "ZZZZ : COULD NOT GENERATE SSID response for %s (%d)", k->ssid_txt, k->ssid_len);
+			} else {
+				wpa_printf(MSG_INFO, "ZZZZ : GENERATED SSID response for %s (len %d) :)", k->ssid_txt, k->ssid_len);
+				if (hostapd_drv_send_mlme(hapd, resp2, resp2_len, noack) < 0) {
+					wpa_printf(MSG_INFO, "ZZZZ : FAILED SENDING PROBE RESP FOR SSID %s (%d)", k->ssid_txt, k->ssid_len);
+				}
+				os_free(resp2);
+			}
+		}
+	}
+
 	wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
 		   "SSID", MAC2STR(mgmt->sa),
 		   elems.ssid_len == 0 ? "broadcast" : "our");
@@ -709,7 +761,7 @@
 			   "this");
 
 	/* Generate a Probe Response template for the non-P2P case */
-	return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
+	return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, NULL, 0, resp_len); //KARMA mod
 }
 
 #endif /* NEED_AP_MLME */
diff -ur hostapd-2.2/src/ap/beacon.h 2.2-manna/src/ap/beacon.h
--- hostapd-2.2/src/ap/beacon.h	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/src/ap/beacon.h	2014-07-07 20:53:33.000000000 +0200
@@ -23,3 +23,15 @@
 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params);
 
 #endif /* BEACON_H */
+
+// KARMA START
+#include "uthash/uthash.h"
+struct karma_ssid {
+        char ssid_txt[HOSTAPD_MAX_SSID_LEN+1];
+        u8 ssid[HOSTAPD_MAX_SSID_LEN];
+        size_t ssid_len;
+		u8 sta_addr[6];
+        UT_hash_handle hh;
+};
+struct karma_ssid *karma_data;
+// KARMA END
diff -ur hostapd-2.2/src/ap/drv_callbacks.c 2.2-manna/src/ap/drv_callbacks.c
--- hostapd-2.2/src/ap/drv_callbacks.c	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/src/ap/drv_callbacks.c	2014-07-07 20:53:33.000000000 +0200
@@ -670,7 +670,7 @@
 		return HAPD_BROADCAST;
 
 	for (i = 0; i < iface->num_bss; i++) {
-		if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
+		if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) 
 			return iface->bss[i];
 	}
 
diff -ur hostapd-2.2/src/ap/ieee802_11.c 2.2-manna/src/ap/ieee802_11.c
--- hostapd-2.2/src/ap/ieee802_11.c	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/src/ap/ieee802_11.c	2014-07-07 21:39:56.000000000 +0200
@@ -789,17 +789,23 @@
 {
 	if (ssid_ie == NULL)
 		return WLAN_STATUS_UNSPECIFIED_FAILURE;
-
-	if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
-	    os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
-		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
-			       HOSTAPD_LEVEL_INFO,
-			       "Station tried to associate with unknown SSID "
-			       "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
-		return WLAN_STATUS_UNSPECIFIED_FAILURE;
-	}
+	// KARMA
+	if (hapd->iconf->enable_karma) {
+		wpa_printf(MSG_MSGDUMP, "KARMA: Checking SSID for start of association, pass through %s", wpa_ssid_txt(ssid_ie, ssid_ie_len));
+		return WLAN_STATUS_SUCCESS;
+	} else {
+		if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
+			os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
+			hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+					   HOSTAPD_LEVEL_INFO,
+					   "Station tried to associate with unknown SSID "
+					   "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
+			return WLAN_STATUS_UNSPECIFIED_FAILURE;
+		}
 
 	return WLAN_STATUS_SUCCESS;
+	}
+	// KARMA END
 }
 
 
@@ -1943,6 +1949,21 @@
 		 * step.
 		 */
 		ap_sta_set_authorized(hapd, sta, 1);
+
+		// KARMA
+		// Print that it has associated and give the MAC and AP
+		// Doesn't currently work though as can't find ESSID
+		if (hapd->iconf->enable_karma) {
+			// This gives the ESSID of the AP and not the one from the probe.
+			//struct hostapd_ssid *ssid = sta->ssid;
+
+			// printf("KARMA: Successful association of " MACSTR " to ESSID '%s'\n",
+			//	   MAC2STR(mgmt->da), ssid->ssid);
+			printf("KARMA: Successful association of " MACSTR "\n",
+				   MAC2STR(mgmt->da));
+		}
+
+		// KARMA END
 	}
 
 	if (reassoc)
diff -ur hostapd-2.2/src/ap/sta_info.h 2.2-manna/src/ap/sta_info.h
--- hostapd-2.2/src/ap/sta_info.h	2014-06-04 15:26:14.000000000 +0200
+++ 2.2-manna/src/ap/sta_info.h	2014-07-07 20:53:33.000000000 +0200
@@ -93,6 +93,7 @@
 
 	struct hostapd_ssid *ssid; /* SSID selection based on (Re)AssocReq */
 	struct hostapd_ssid *ssid_probe; /* SSID selection based on ProbeReq */
+	struct hostapd_ssid *ssid_probe_karma; /* SSID selection based on ProbeReq */
 
 	int vlan_id;
 	 /* PSKs from RADIUS authentication server */
Only in 2.2-manna/src/ap: uthash
