Hi Mr. Polastre, we are working with Tmote SKY and we would like to make an
application to implement security "stand alone" we are not sure we are
writing in the RAM and we are looking to check whether we are writing or
not, also we would like to know how can we run any kind of security on these
devises and if you have some examples we could run.   We would certainly
appreciate any help you can provide us in this matter. Here is the code that
we used; we verified the writing in the RAM with the leds, and don't work.

//////////////////////////////////////////////////////////////////////////////////////

configuration Encrypt
{
}

implementation
{
components Main,
   EncryptM,
   GenericComm as Comm,
   LedsC,
   HPLCC2420C,
   TimerC;

Main.StdControl -> EncryptM.StdControl;
Main.StdControl -> Comm.Control;
Main.StdControl -> TimerC.StdControl;
Main.StdControl -> HPLCC2420C.StdControl;

EncryptM.SendMsg -> Comm.SendMsg[1];
EncryptM.Leds -> LedsC;
EncryptM.Timer1 -> TimerC.Timer[unique("Timer")];
EncryptM.HPLChipcon -> HPLCC2420C.HPLCC2420;
EncryptM.HPLChipconRAM -> HPLCC2420C.HPLCC2420RAM;
}

////////////////////////////////////////////////////////////////////////////////////////////////////

module EncryptM
{
provides {
  interface StdControl;
}
uses {
  interface SendMsg;
  interface Leds;
  interface Timer as Timer1;
  interface HPLCC2420 as HPLChipcon;
  interface HPLCC2420RAM as HPLChipconRAM;
}
}

implementation
{

TOS_Msg msg1;
uint8_t mydata[16];
uint8_t read_data[16];
bool busy = FALSE;
uint8_t choice = 0;
bool keyWritten = FALSE;
uint8_t mykey[16];
uint8_t var;

command result_t StdControl.init() {
  uint8_t i;
  call Leds.init();

      // Set the security control register
      // Use Key 0 as stand-alone key, TX key and RX key; 8 bytes MIC in
   //CBC-MAC mode; length byte is authenticated

  if (call HPLChipcon.write( RESOURCE_NONE, CC2420_SECCTRL0, 0x030d)==
0xff)
  {
          call Leds.redToggle();
  }
  else
  {
          call Leds.greenToggle();
  }

  //call HPLChipcon.write(RESOURCE_NONE, CC2420_SECCTRL1, 0x0000);

  /* Set Key 0*/
  mykey[0] = (uint8_t) 0x55;
  mykey[1] = (uint8_t) 0x15;
  mykey[2] = (uint8_t) 0x71;
  mykey[3] = (uint8_t) 0xc9;
  mykey[4] = (uint8_t) 0x47;
  mykey[5] = (uint8_t) 0xd9;
  mykey[6] = (uint8_t) 0xe8;
  mykey[7] = (uint8_t) 0x59;
  mykey[8] = (uint8_t) 0x0c;
  mykey[9] = (uint8_t) 0xb7;
  mykey[10] = (uint8_t) 0xad;
  mykey[11] = (uint8_t) 0xd6;
  mykey[12] = (uint8_t) 0xaf;
  mykey[13] = (uint8_t) 0x7f;
  mykey[14] = (uint8_t) 0x67;
  mykey[15] = (uint8_t) 0x98;


  // Set data
  for(i=0; i<16; i++)
  {
      mydata[i] = 0x01;
  }

  return SUCCESS;
}


command result_t StdControl.start() {
  call Timer1.start(TIMER_REPEAT, 5120);
  return SUCCESS;
}


command result_t StdControl.stop() {
  return SUCCESS;
}


event result_t SendMsg.sendDone(TOS_MsgPtr m, result_t status) {
  //call Leds.greenToggle();    // Inidicate success.
  busy = FALSE;
  return status;
}


  async event result_t HPLChipconRAM.writeDone(uint16_t ram_addr, uint8_t
ram_len, uint8_t* ram_buf){
      //call Leds.redToggle();
      return SUCCESS;
  }


  async event result_t HPLChipconRAM.readDone(uint16_t ram_addr, uint8_t
ram_len, uint8_t* ram_buf){
      //call Leds.yellowToggle();
      return SUCCESS;
  }


  task void encrypt_and_send(){
      uint8_t status;

      if(keyWritten){
          if(choice==0){
              // send plaintext to SABUF buffer
              if (call HPLChipconRAM.write(RESOURCE_NONE, CC2420_RAM_SABUF,
16, (uint8_t *)&mydata)== SUCCESS)
              {
                      call Leds.redToggle();
                      choice = 1;
              }
              else
              {
                      call Leds.greenToggle();
              }
          }
          else if(choice==1){
              // Encrypt
              call HPLChipcon.cmd(RESOURCE_NONE, CC2420_SAES);
              do {
                  status = call HPLChipcon.cmd(RESOURCE_NONE, CC2420_SNOP);
              } while((status >> CC2420_ENC_BUSY) & 0x01);    // wait until
encryption finishes
              choice = 2;
          }
          else if(!busy && choice==2){
              // Read out the ciphertext:
              call HPLChipconRAM.read(RESOURCE_NONE, CC2420_RAM_KEY0, 16,
(uint8_t *)&mydata );
              if(!busy){
                  if((call SendMsg.send(TOS_BCAST_ADDR, 16, &msg1)) ==
SUCCESS)
                      busy = TRUE;
              }
                  choice = 0;
          }
      }
      else {
          if (call HPLChipconRAM.write(RESOURCE_NONE, CC2420_RAM_KEY0, 16,
(uint8_t*)&mykey)== SUCCESS)
          {
                  keyWritten = TRUE;
                  call Leds.redToggle();
          }
          else
             {
                  call Leds.greenToggle();
             }
      }
  }

  event result_t Timer1.fired() {
      post encrypt_and_send();
      return SUCCESS;
  }
}

Thank you,

NĂ©stor
_______________________________________________
Tinyos-help mailing list
Tinyos-help@Millennium.Berkeley.EDU
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to