 #include <user_interface.h>
 }
 // maximum number of unique mac addresses to remember
-#define MAX_MAC 64
+#define MAX_MAC 200
 
 static int unique_num = 0;
-static uint8_t unique_mac[MAX_MAC][6];
+
+typedef struct {
+    uint8_t mac[6];
+    unsigned long last_seen;
+} mac_t;
+
+static mac_t unique_mac[MAX_MAC];
+
+// prints a mac address
+static void print_mac(const uint8_t * mac)
+{
+    char text[32];
+    sprintf(text, "%02X:%02X:%02X:%02X:%02X:%02X",
+            mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+    Serial.print(text);
+}
 
 // returns true if a new mac was added to the table of unique mac addresses
-static bool add_mac(const uint8_t * mac)
+static bool add_mac(unsigned long now, const uint8_t * mac)
 {
     // try to find it
     int i;
     for (i = 0; i < unique_num; i++) {
-        if (memcmp(mac, unique_mac[i], 6) == 0) {
-            // not unique
+        if (memcmp(mac, unique_mac[i].mac, 6) == 0) {
+            // found it, update timestamp
+            unique_mac[i].last_seen = now;
             return false;
         }
     }


        // check for packet with FromDS=0, packets from station
        if (((fc >> 9) & 1) == 0) {
            if (add_mac(addr2)) {
                sprintf(text, "%04X: ", fc);
                Serial.print(text);
                print_mac(addr2);
            }
        }
    }

    }
}

// expires old mac entries
static void expire_mac(unsigned long now, unsigned long expiry)
{
    char text[32];
    int i;
    for (i = 0; i < unique_num; i++) {
        if ((now - unique_mac[i].last_seen) > expiry) {
            // expired, overwrite it with the last one
            if (--unique_num > i) {
                sprintf(text, "%10d: ", now);
                Serial.print(text);
                print_mac(unique_mac[i].mac);
                sprintf(text, " expired: %d\n", unique_num);
                Serial.print(text);
                memcpy(&unique_mac[i], &unique_mac[unique_num], sizeof(mac_t));
            }
        }
    }
}

// callback for promiscuous mode
