LakshmanRekha

Made by ihans

creating barriers for sensitive data to leave the smart home

Created: May 10th, 2022

0

Description: Smart home devices paint a picture about the people and their lives through the collection of large amounts of data. Some of this data is sensitive and must never leave the realm of the smart home to protect the privacy of its occupants. LakshamRekha is the sanctimonious barrier in this home that must not be crossed by the sensitive data.

Originally a physical line drawn by Lord Lakshmana to protect goddess Sita from any evil, this LakshamRekha is a device located in the foyer close to the doorway. Indulge in the experience of walking around this smart home as either Alexa or Roomba to collect data and find out what the LakshmanRekha might forbid you to take past the doorway.
0

Process: My process included four main steps:

Step 1: Find out the RFID tag UID by using arduino

Step 2: Segregate the UIDs for data that represent data that is sensitive v/s the data that is okay for being taken out. I maintained an excel sheet to keep track of it and used Particle cloud function to see if RFID was bein read properly as per these. For example, for Alexa, there were two functions: AlexaYes and AlexaNo.

This step also helped me learn that Particle by default removes the extra zeros in the RFID UID, and it was helpful in the next step.

0
// This #include statement was automatically added by the Particle IDE.
#include "MFRC522.h"


//obtained from source mentioned above
 
#define SS_PIN SS
#define RST_PIN D2
 
MFRC522 mfrc522(SS_PIN, RST_PIN);	// Create MFRC522 instance.
 
void setup() {
	// Initialize serial communications with the computer
	Serial.begin(9600);	
	mfrc522.setSPIConfig(); // sets up SPI config
 
	mfrc522.PCD_Init();	// Initialize RC522 card
	Serial.println("Start Scanning");
}
 
void loop() {
	// Look for new cards
	if ( ! mfrc522.PICC_IsNewCardPresent()) {
		return;
	}
	//Serial.println("New card Detected");
	// Read tapped card data
	if ( ! mfrc522.PICC_ReadCardSerial()) {
		return;
	}
 
	//Dump all card data to Serial
  //Uncomment this if you want to debug / find info on tags
	//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));

  // get the ID 
 String id;
  for (byte i = 0; i < mfrc522.uid.size; i++) {
		// Create a RFID Hexdecimal String
		id += String(mfrc522.uid.uidByte[i], HEX);

	}
	// Convert to Uppercase
	id.toUpperCase();

  // print it to the console.
	Serial.print(id);
	Serial.println();


	// If it is this card, do something
	if (id == "44681A4A6E81" || "45981A4A6E81" ) {
		Particle.publish("AlexaNo", id, PRIVATE);
	}
    
	// Reset Id
	id = "";
	
	if (id == "44781A4A6E81" || "46E81A4A6E81" || "45A81A4A6E81" ); {
            Particle.publish("AlexaYes", id, PRIVATE);
    }
    
    	// Reset Id
	id = "";
	mfrc522.PICC_HaltA();
	mfrc522.PCD_StopCrypto1();
}
Click to Expand
0

Step 3: Use processing to receive the data and play a sound based on the UID. I had picked out two sounds and respective images for the sketch to display.

0
// Serial Port Communication library
import processing.serial.*;
import processing.sound.*;

SoundFile no;
SoundFile ok;

//New instance of Serial Port
Serial port;

String id = "";
String buff = "";
// Setup a new instance of image
PImage img; 
 
 
void setup() {
  background(0,0,0); 
  size(640, 540);
  // Set the Processing Sketch always on Top
  surface.setAlwaysOnTop(true);
  // List of Serial Port / COM Port
  //printArray(Serial.list());
  // Choose the correct Serial Port / COM Port
  // Baud Rate must match the Arduino Sketch 
  // format: new Serial(this, Serial Port / COM Port, Baud Rate); 
  port = new Serial(this, "/dev/cu.usbmodem14101", 9600);
  no = new SoundFile(this, "data/ohno.mp3");
  ok = new SoundFile(this, "data/ok.mp3");
}
void draw(){
  // Check if the port send anything
  if(port.available() > 0) {
    // Read the port 
    serialEvent(port.read());  
  }
}
 
void serialEvent(int serial) {
  // Get all the information in buffer string until new line
  if(serial != '\n') { 
    buff += char(serial);
  } 
  /* Trim the buff to get the ID Hexadecimal
     This depends on how you send the data */
  else {   
   id = trim(buff.substring(0));
   // Load Oh no image
   if ((id.equals("48281A4A6E81")) || (id.equals("44681A4A6E81")) || (id.equals("45B81A4A6E81"))) {
     img = loadImage("ohno.jpg");
     image(img, 0, 0);
     no.stop();
     no.play();
     
   // Load yeah okay image
   } else if ((id.equals("46E81A4A6E81")) || (id.equals("44781A4A6E81")) || (id.equals("47081A4A6E81"))){
     background(0,0,0);
     no.stop();
img = loadImage("sure.jpg");
     image(img, 0, 0);
     ok.play();
     
   // If anything other RFID tag reset  
   } else {
     background(0,0,0); 
   }
   // Reset Buffer String
   buff = "";
  }
}
Click to Expand
0

Step 4: Code information into each tag so that the visitors can learn more about what each tag is supposed to represent by using NFC on their phone. I used particle to code this and made sure that each tag represents a plasuible data point collected in the space where the tag was placed in the exhibition. For example, in the office areas, the roomba tag was showed the following information:

0
#include "application.h"
#include "MFRC522.h"
#include "MifareUltralight.h"
#include <math.h>



// MORE AT: https://github.com/aroller/NDEF-MFRC522

// MFRC522 Wiring
// 
// Pin on MRFC522       Pin on Argon
// MOSI                 MO
// MISO                 MI
// SCK                  SCK
// SS                   A5
// RST                  A2 (configurable)
// GND                  GND
// 3v3                  3v3

// IMPORTANT NOTE
// The MRFC522 Library (default) has an issue
// Described here: https://community.particle.io/t/mfrc522-rfid-library-stopped-working/61516/2
// It requires (since Nov 2021) adding the library manually and repairing a function

using namespace ndef_mfrc522;


#define SS_PIN SS // 
#define RST_PIN D2
 
MFRC522 mfrc522(SS_PIN, RST_PIN);	// Create MFRC522 instance.

long lastDetection = -1;
String lastDetected = "";
long redetectAfter = 10000;

bool writeNextTag = false;
bool overwriteOK = false;
String ndef_text = "";
bool isURL = false;

void setup() {
    
  Serial.begin(9600);	

  mfrc522.setSPIConfig(); // sets up SPI config

  mfrc522.PCD_Init();	// Initialize RC522 card
   
  // Use this to add a HTTP URL to the tag
  // ARG: any string beginning 'http' 
  Particle.function( "addNFCURL", handleWriteNDefURL );
  // Use this to add a piece of text or a message
  // ARG: any string (limit will be 65 characters based on particles limits)
  Particle.function( "addNFCTxt", handleWriteNDefText );
  // By default this won't overwrite data on a tag
  // If you want it to overwrite content, use the Particle console
  // and call this function with 'allowed' as the arg.
  Particle.function( "overwrite", handleOverwrite );
   

}

void loop() {
	// Look for new cards
	// Look for new cards
	if ( ! mfrc522.PICC_IsNewCardPresent()) {
		return;
	}
	// Serial.println("New card Detected");
	// Read tapped card data
	if ( ! mfrc522.PICC_ReadCardSerial()) {
		return;
	}
	
	Serial.println("Discovered Card");
   
    String rfid_card_id = readTagID();
    String payloads = readTagAndNDefInfo();
    
    if( writeNextTag ){
      
        if( payloads.length() > 0 and !overwriteOK ){
            Serial.println( "Card not empty and cannot overwrite. Contains the following payload:" );
            Serial.println( payloads );
        }else{
            Serial.println(F("Attempting to write to the card."));
         
            if( isURL ){
                writeURITag( ndef_text );
            }else{
                writeTextTag( ndef_text);
            }
        }
      
        writeNextTag = false;
   }
 
   publishEvent( rfid_card_id );

   delay( 1000);
}


int handleOverwrite( String cmd ){
   
   if( cmd.indexOf( "allowed" ) < 0 ){
      return -1;
   }
   overwriteOK = true;
   return 1;
}


int handleWriteNDefURL( String cmd ){
   
   if( cmd.indexOf( "http" ) < 0 ){
      return -1;
   }
   
   ndef_text = cmd;
   writeNextTag = true;
   isURL = true; 
   
   return 1;
   
}



int handleWriteNDefText( String cmd ){

   ndef_text = cmd;
   writeNextTag = true;
   isURL = false;
   
   return 1;
   
}



void publishEvent( String data ){
   
   long timeNow = millis();
	if( lastDetection + redetectAfter < timeNow ){
		lastDetection = timeNow;
		Particle.publish("com/daraghbyrne/nfc-writer", data );
	}
   
   
}



void writeURITag( String uri ){

   //String url = String("http://daraghbyrne.me");
   //String url = String(ndef_text);
   
   ndef_mfrc522::NdefMessage message = ndef_mfrc522::NdefMessage();
   message.addUriRecord(uri);
   MifareUltralight writer = MifareUltralight(mfrc522);
   bool success = writer.write(message);
   if (success)
     Serial.println(F("Success. Now read the tag with your phone."));
   else
     Serial.println(F("Failure. See output above?"));
   delay(5000); // avoids duplicate scans
   
}

void writeTextTag( String txt ){

   ndef_mfrc522::NdefMessage message = ndef_mfrc522::NdefMessage();
   message.addTextRecord(txt);
   MifareUltralight writer = MifareUltralight(mfrc522);
   bool success = writer.write(message);
   if (success)
     Serial.println(F("Success. Now read the tag with your phone."));
   else
     Serial.println(F("Failure. See output above?"));
   delay(5000); // avoids duplicate scans
   
}


String readTagID(){
   
	// discover the id of the last item;
	String uuid = "";

	for (byte i = 0; i < mfrc522.uid.size; i++) {
		// Create a RFID Hexdecimal String
		uuid += String(mfrc522.uid.uidByte[i], HEX);
	}
	// Convert to Uppercase
	uuid.toUpperCase();
   
	Serial.println(uuid);
   
   return uuid;
}


String readTagAndNDefInfo(){
   
   MifareUltralight reader = MifareUltralight(mfrc522);
   NfcTag tag = reader.read();
   
   String payloads = "";
   
   if( tag.hasNdefMessage() )
   {
   	ndef_mfrc522::NdefMessage message = tag.getNdefMessage();
      
      Serial.print("\nThis NFC Tag contains an NDEF Message with ");
      Serial.print(message.getRecordCount());
      Serial.print(" NDEF Record");
      if (message.getRecordCount() != 1) {
        Serial.print("s");
      }
      Serial.println(".");
      
      // cycle through the records, printing some info from each
      int recordCount = message.getRecordCount();
      for (int i = 0; i < recordCount; i++)
      {
        Serial.print("\nNDEF Record ");Serial.println(i+1);
        NdefRecord record = message.getRecord(i);
        // NdefRecord record = message[i]; // alternate syntax

        Serial.print("  TNF: ");Serial.println(record.getTnf());
        Serial.print("  Type: ");Serial.println(record.getType()); // will be "" for TNF_EMPTY

        // The TNF and Type should be used to determine how your application processes the payload
        // There's no generic processing for the payload, it's returned as a byte[]
        int payloadLength = record.getPayloadLength();
        byte payload[payloadLength];
        record.getPayload(payload);

        // Force the data into a String (might work depending on the content)
        // Real code should use smarter processing
        String payloadAsString = "";
        Serial.print( "Payload has lenght:" ) ;
        Serial.println( payloadLength );
        
        for (int c = 0; c < payloadLength; c++) {
          Serial.print( payload[c], HEX );
          char cc = (char)payload[c];
          Serial.print( cc );
          payloadAsString += String( cc ) ;
        }
        
        Serial.print("\n  Payload (as String): ");
        Serial.println(payloadAsString);
        
        payloads += payloadAsString + ";";

        // id is probably blank and will return ""
        String uid = record.getId();
        if (uid != "") {
          Serial.print("  ID: ");Serial.println(uid);
        }

      }
      
      if( payloads.length() > 0 )
         payloads = payloads.remove( payloads.length() -1 );
      return payloads;
      
   }else{
      return "";
   }
   
}
Click to Expand
0


x
Share this Project

Courses

48-528 Responsive Mobile Environments - Spooky Technology

· 12 members

As part of this project-based course, we’ll get hands-on with emerging technologies, concepts and applications in the internet of things through a critical socio-technical lens. Over it’s 14-weeks,...more


About

creating barriers for sensitive data to leave the smart home