47 #define MAX_DATALEN 16
49 #define CC2420_WRITE_RAM_REV(buffer,adr,count) \
52 CC2420_SPI_ENABLE(); \
53 SPI_WRITE_FAST(0x80 | (adr & 0x7f)); \
54 SPI_WRITE_FAST((adr >> 1) & 0xc0); \
55 for(i = (count); i > 0; i--) { \
56 SPI_WRITE_FAST(((uint8_t*)(buffer))[i - 1]); \
58 SPI_WAITFORTx_ENDED(); \
59 CC2420_SPI_DISABLE(); \
62 #define MIN(a,b) ((a) < (b)? (a): (b))
70 CC2420_WRITE_RAM_REV(key, CC2420RAM_KEY0, KEYLEN);
73 CC2420_WRITE_RAM_REV(key, CC2420RAM_KEY1, KEYLEN);
80 cipher16(uint8_t *data,
int len)
84 len = MIN(len, MAX_DATALEN);
86 CC2420_WRITE_RAM(data, CC2420RAM_SABUF, len);
87 CC2420_STROBE(CC2420_SAES);
90 CC2420_GET_STATUS(status);
91 }
while(status & BV(CC2420_ENC_BUSY));
92 CC2420_READ_RAM(data, CC2420RAM_SABUF, len);
101 CC2420_READ_REG(CC2420_SECCTRL0, secctrl0);
103 secctrl0 &= ~(CC2420_SECCTRL0_SAKEYSEL0 | CC2420_SECCTRL0_SAKEYSEL1);
107 secctrl0 |= CC2420_SECCTRL0_SAKEYSEL0;
110 secctrl0 |= CC2420_SECCTRL0_SAKEYSEL1;
113 CC2420_WRITE_REG(CC2420_SECCTRL0, secctrl0);
115 for(i = 0; i < len; i = i + MAX_DATALEN) {
116 cipher16(data + i, MIN(len - i, MAX_DATALEN));