Changeset 389
- Timestamp:
- 01/20/08 19:38:52 (7 months ago)
- Files:
-
- nano-RK/projects/basic_adc/main.c (modified) (1 diff)
- nano-RK/projects/basic_bmac/main.c (modified) (4 diffs)
- nano-RK/projects/basic_bmac/nrk_cfg.h (modified) (1 diff)
- nano-RK/projects/flash_flood/client/main.c (modified) (1 diff)
- nano-RK/projects/flash_flood/gateway/main.c (modified) (2 diffs)
- nano-RK/projects/flash_flood/include/flash_flood.h (modified) (3 diffs)
- nano-RK/projects/flash_flood/include/pkt_packer.c (modified) (1 diff)
- nano-RK/src/net/bmac/bmac.c (modified) (1 diff)
- nano-RK/src/net/bmac/bmac.h (modified) (1 diff)
- nano-RK/src/radio/cc2420/include/basic_rf.h (modified) (1 diff)
- nano-RK/src/radio/cc2420/source/basic_rf.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nano-RK/projects/basic_adc/main.c
r369 r389 80 80 cnt=0; 81 81 chan=0; 82 val=nrk_set_status(fd,ADC_CHAN, 4);82 val=nrk_set_status(fd,ADC_CHAN,5); 83 83 if(val==NRK_ERROR) nrk_kprintf( PSTR("Failed to set ADC status\r\n" )); 84 84 while(1) { nano-RK/projects/basic_bmac/main.c
r380 r389 81 81 82 82 // init bmac on channel 25 83 bmac_init ( 25);83 bmac_init (15); 84 84 85 85 // Enable AES 128 bit encryption … … 128 128 } 129 129 130 uint8_t ctr_cnt[4]; 130 131 131 132 void tx_task () … … 148 149 nrk_signal_register (tx_done_signal); 149 150 151 ctr_cnt[0]=0; ctr_cnt[1]=0; ctr_cnt[2]=0; ctr_cnt[3]=0; 150 152 cnt = 0; 151 153 while (1) { … … 171 173 // bmac_addr_decode_disable(); 172 174 175 ctr_cnt[0]=cnt; 176 if(ctr_cnt[0]==255) ctr_cnt[1]++; 177 if(ctr_cnt[1]==255) ctr_cnt[2]++; 178 if(ctr_cnt[2]==255) ctr_cnt[3]++; 179 // You need to increase the ctr on each packet to make the 180 // stream cipher not repeat. 181 bmac_encryption_set_ctr_counter(&ctr_cnt,4); 173 182 174 183 // For blocking transmits, use the following function call. nano-RK/projects/basic_bmac/nrk_cfg.h
r148 r389 11 11 // NRK_HALT_ON_ERRORS will cause the kernel to freeze on errors so that 12 12 // it is easier to see debugging messages. 13 //#define NRK_HALT_ON_ERROR14 #define NRK_HALT_AND_LOOP_ON_ERROR13 #define NRK_HALT_ON_ERROR 14 //#define NRK_HALT_AND_LOOP_ON_ERROR 15 15 16 16 // NRK_STACK_CHECK adds a little check to see if the bottom of the stack nano-RK/projects/flash_flood/client/main.c
r386 r389 90 90 nrk_setup_uart (UART_BAUDRATE_115K2); 91 91 92 my_subnet_mac = 1;93 my_mac = 5;92 my_subnet_mac = 2; 93 my_mac = 10; 94 94 95 95 nrk_init (); nano-RK/projects/flash_flood/gateway/main.c
r388 r389 247 247 tx_buf[PKT_TYPE]=PING_PKT; 248 248 // tx_buf[PKT_TYPE]=SENSOR_SHORT_PKT; 249 tx_buf[CTRL_FLAGS]= ENCRYPT | LINK_ACK | DS_MASK | TREE_FILTER | LED_FLOOD; 249 tx_buf[CTRL_FLAGS]= ENCRYPT | LINK_ACK | DS_MASK | LED_FLOOD; 250 // tx_buf[CTRL_FLAGS]= ENCRYPT | LINK_ACK | DS_MASK | LED_FLOOD; 250 251 tx_buf[SEQ_NUM]=cnt; 251 252 tx_buf[PRIORITY]=0; … … 255 256 tx_buf[DS_DELAY_PER_LEVEL]=1; 256 257 tx_buf[DS_NAV]=15; 257 tx_buf[DS_MAC_CHECK_RATE]= 25;258 tx_buf[DS_MAC_CHECK_RATE]=50; 258 259 mac_check_rate = tx_buf[DS_MAC_CHECK_RATE]; 259 tx_buf[DS_RSSI_THRESHOLD]=-45; 260 // tx_buf[DS_RSSI_THRESHOLD]=5; 260 tx_buf[DS_RSSI_THRESHOLD]=-50; 261 tx_buf[DS_AES_CTR_3]=0; 262 tx_buf[DS_AES_CTR_2]=0; 263 tx_buf[DS_AES_CTR_1]=0; 264 tx_buf[DS_AES_CTR_0]=cnt; 265 // tx_buf[DS_RSSI_THRESHOLD]=-30; 261 266 tx_buf[DS_LAST_HOP_MAC]=gw_mac; 262 267 len=DS_PAYLOAD_START; nano-RK/projects/flash_flood/include/flash_flood.h
r388 r389 82 82 83 83 // Common to all packets 84 #define PKT_TYPE 085 #define CTRL_FLAGS 184 #define CTRL_FLAGS 0 85 #define PKT_TYPE 1 86 86 #define SEQ_NUM 2 87 87 #define PRIORITY 3 … … 100 100 #define DS_MAC_CHECK_RATE 12 101 101 #define DS_RSSI_THRESHOLD 13 102 #define DS_PAYLOAD_START 1 4102 #define DS_PAYLOAD_START 18 103 103 104 104 // Common to upstream reply packets … … 137 137 uint8_t last_hop_mac; 138 138 uint8_t mac_filter_num; 139 uint8_t aes_ctr[4]; 139 140 140 141 // Buffer Management nano-RK/projects/flash_flood/include/pkt_packer.c
r382 r389 15 15 ds_pkt->ack_retry = (ds_pkt->buf[ACK_RETRY]&0xF0)>>4; 16 16 ds_pkt->subnet_mac= ds_pkt->buf[SUBNET_MAC]; 17 18 17 19 18 ds_pkt->hop_cnt = ds_pkt->buf[DS_HOP_CNT]; nano-RK/src/net/bmac/bmac.c
r380 r389 57 57 // Any code here gets called the instant a packet is received from the interrupt 58 58 return pRRI; 59 } 60 61 int8_t bmac_encryption_set_ctr_counter(uint8_t *counter, uint8_t len) 62 { 63 if(len!=4 ) return NRK_ERROR; 64 rf_security_set_ctr_counter(counter); 65 return NRK_OK; 59 66 } 60 67 nano-RK/src/net/bmac/bmac.h
r381 r389 70 70 int8_t bmac_encryption_set_key(uint8_t *key, uint8_t len); 71 71 int8_t bmac_encryption_enable(); 72 int8_t bmac_encryption_set_ctr_counter(uint8_t *counter, uint8_t len); 72 73 int8_t bmac_encryption_disable(); 73 74 int8_t bmac_rx_pkt_is_encrypted(); nano-RK/src/radio/cc2420/include/basic_rf.h
r380 r389 76 76 uint8_t rf_security_last_pkt_status(); 77 77 void rf_security_set_key(uint8_t *key); 78 void rf_security_set_ctr_counter(uint8_t *counter); 78 79 void rf_security_enable(); 79 80 void rf_security_disable(); nano-RK/src/radio/cc2420/source/basic_rf.c
r383 r389 44 44 uint8_t last_pkt_encrypted; 45 45 uint16_t mdmctrl0; 46 uint8_t tx_ctr[4]; 47 uint8_t rx_ctr[4]; 46 48 47 49 // Returns 1 if the last packet was encrypted, 0 otherwise … … 50 52 return last_pkt_encrypted; 51 53 } 54 55 56 void rf_security_set_ctr_counter(uint8_t *counter) 57 { 58 uint8_t n; 59 // CTR counter value 60 FASTSPI_WRITE_RAM(&counter[0],(CC2420RAM_TXNONCE+9),2,n); 61 FASTSPI_WRITE_RAM(&counter[2],(CC2420RAM_TXNONCE+11),2,n); 62 tx_ctr[0]=counter[0]; 63 tx_ctr[1]=counter[1]; 64 tx_ctr[2]=counter[2]; 65 tx_ctr[3]=counter[3]; 66 } 67 52 68 53 69 void rf_security_set_key(uint8_t *key) … … 65 81 } 66 82 67 // Set AES nonce 83 // Set AES nonce to all zeros 68 84 nrk_spin_wait_us(100); 69 for(i=0; i< 8; i++ )85 for(i=0; i<7; i++ ) 70 86 { 71 87 key_buf=0; 72 nrk_spin_wait_us(100);73 88 FASTSPI_WRITE_RAM_LE(&key_buf,(CC2420RAM_TXNONCE+(i*2)),2,n); 74 nrk_spin_wait_us(100);75 89 FASTSPI_WRITE_RAM_LE(&key_buf,(CC2420RAM_RXNONCE+(i*2)),2,n); 76 90 } 91 // block counter set 1 92 key_buf=1; 93 FASTSPI_WRITE_RAM_LE(&key_buf,(CC2420RAM_TXNONCE+14),2,n); 94 FASTSPI_WRITE_RAM_LE(&key_buf,(CC2420RAM_RXNONCE+14),2,n); 77 95 } 78 96 … … 80 98 { 81 99 FASTSPI_SETREG(CC2420_SECCTRL0, 0x0306); // Enable CTR encryption with key 0 82 FASTSPI_SETREG(CC2420_SECCTRL1, 0x0 a0a); // Encrypt / Decrypt 6bytes into header100 FASTSPI_SETREG(CC2420_SECCTRL1, 0x0e0e); // Encrypt / Decrypt 18 bytes into header 83 101 84 102 security_enable=1; … … 606 624 // Slots for example are at a slighly higher later since they assume TDMA 607 625 packetLength = pRTI->length + RF_PACKET_OVERHEAD_SIZE + CHECKSUM_OVERHEAD; 626 if(security_enable) packetLength+=4; // for CTR counter 608 627 609 628 … … 647 666 FASTSPI_WRITE_FIFO((uint8_t*) &pRTI->destAddr, 2); // Dest. address 648 667 FASTSPI_WRITE_FIFO((uint8_t*) &rfSettings.myAddr, 2); // Source address 668 if(security_enable) 669 FASTSPI_WRITE_FIFO((uint8_t*) &tx_ctr, 4); // CTR counter 670 649 671 FASTSPI_WRITE_FIFO((uint8_t*) pRTI->pPayload, pRTI->length); // Payload 650 672 FASTSPI_WRITE_FIFO((uint8_t*) &checksum, 1); // Checksum … … 763 785 return SFD_IS_1; 764 786 } 787 uint16_t tmp_blah; 765 788 766 789 int8_t rf_polling_rx_packet() … … 850 873 */ 851 874 // Skip the destination PAN and address (that's taken care of by harware address recognition!) 852 if(frameControlField & RF_SEC_BM) 875 FASTSPI_READ_FIFO_GARBAGE(4); 876 877 // Read the source address 878 FASTSPI_READ_FIFO_NO_WAIT((uint8_t*) &rfSettings.pRxInfo->srcAddr, 2); 879 880 if(frameControlField & RF_SEC_BM) 853 881 { 882 uint8_t n; 883 // READ rx_ctr and set it 884 FASTSPI_READ_FIFO_NO_WAIT((uint8_t*) &rx_ctr, 4); 885 FASTSPI_WRITE_RAM(&rx_ctr[0],(CC2420RAM_RXNONCE+9),2,n); 886 FASTSPI_WRITE_RAM(&rx_ctr[2],(CC2420RAM_RXNONCE+11),2,n); 854 887 FASTSPI_STROBE(CC2420_SRXDEC); // if packet is encrypted then decrypt 855 888 last_pkt_encrypted=1; 889 rfSettings.pRxInfo->length -= 4; 856 890 } 857 FASTSPI_READ_FIFO_GARBAGE(4); 858 859 // Read the source address 860 FASTSPI_READ_FIFO_NO_WAIT((uint8_t*) &rfSettings.pRxInfo->srcAddr, 2); 861 891 862 892 // Read the packet payload 863 893 FASTSPI_READ_FIFO_NO_WAIT(rfSettings.pRxInfo->pPayload, rfSettings.pRxInfo->length);
