Enhance serial code

This commit is contained in:
Stefan `Sec` Zehl 2011-08-03 21:56:41 +02:00
parent c241ad30f5
commit 7170789b3e
2 changed files with 24 additions and 7 deletions

View File

@ -4,6 +4,8 @@ Ck<hex>: set encryptionkey
Ct<hex>: set txmac
Cc<hex>: set channel
Ct<hex>: set rxmac(0)
Cl<hex>: set rxlens
Ce<hex>: sec encrpytion on/off
s <hex>: send packet
s+ <hex>: send packet 10 times

View File

@ -29,10 +29,9 @@ uint32_t const beaconkey[4] = {
uint32_t remotekey[4] = {
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
};
uint32_t meshkey[4] = {
0x0, 0x0, 0x0, 0x0
};
extern uint32_t const meshkey[4];
char funkencrypt=0;
#if CFG_USBMSC
#error "MSC is defined"
@ -151,6 +150,7 @@ int process(char * input){
config.nrmacs=1;
nrf_config_set(&config);
memcpy(thekey,meshkey,sizeof(thekey));
funkencrypt=1;
}else if(input[1]=='r'){
config.channel=REMOTE_CHANNEL;
memcpy(config.txmac,REMOTE_MAC,5);
@ -159,6 +159,7 @@ int process(char * input){
config.nrmacs=1;
nrf_config_set(&config);
memcpy(thekey,remotekey,sizeof(thekey));
funkencrypt=1;
}else if(input[1]=='b'){
config.channel=BEACON_CHANNEL;
memcpy(config.txmac,BEACON_MAC,5);
@ -167,6 +168,7 @@ int process(char * input){
config.nrmacs=1;
nrf_config_set(&config);
memcpy(thekey,beaconkey,sizeof(thekey));
funkencrypt=1;
}else if(input[1]=='?'){
nrf_config_get(&config);
puts_plus("Ch: ");puts_plus(IntToStrX( config.channel,2 )); puts_plus("\r\n");
@ -202,6 +204,10 @@ int process(char * input){
puts_plus(" ");
};
puts_plus("\r\n");
puts_plus("encrypt : ");
puts_plus(IntToStrX( funkencrypt,2 ));
puts_plus("\r\n");
};
}else if(input[0]=='C'){
int len;
@ -228,6 +234,15 @@ int process(char * input){
}else if(input[1]=='c'){
config.channel=*hex;
nrf_config_set(&config);
}else if(input[1]=='l'){
config.maclen[0]=uint8ptouint32(hex);
config.maclen[1]=uint8ptouint32(hex+4);
config.maclen[2]=uint8ptouint32(hex+8);
config.maclen[3]=uint8ptouint32(hex+12);
config.maclen[4]=uint8ptouint32(hex+16);
nrf_config_set(&config);
}else if(input[1]=='e'){
funkencrypt= uint8ptouint32(hex);
};
}else if (input[0]=='s'){
__attribute__ ((aligned (4))) uint8_t buf[32];
@ -251,7 +266,7 @@ int process(char * input){
len+=2; // Add crc!
memcpy(buf,hex,len);
status=nrf_snd_pkt_crc_encr(len,buf,thekey);
status=nrf_snd_pkt_crc_encr(len,buf,funkencrypt?thekey:NULL);
puts_plus("P ");
puts_plus("[");puts_plus(IntToStrX(len,2));puts_plus("] ");
@ -266,7 +281,7 @@ int process(char * input){
while(--ctr>0){
delayms(23);
memcpy(buf,hex,len);
status=nrf_snd_pkt_crc_encr(len,buf,thekey);
status=nrf_snd_pkt_crc_encr(len,buf,funkencrypt?thekey:NULL);
};
}else if (input[1]=='t'){
static int ctr=1;
@ -283,7 +298,7 @@ int process(char * input){
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
status=nrf_snd_pkt_crc_encr(16,buf,thekey);
status=nrf_snd_pkt_crc_encr(16,buf,funkencrypt?thekey:NULL);
}else{
};
puts_plus("S state=");
@ -310,7 +325,7 @@ int process(char * input){
puts_plus("D receive ...\r\n");
nrf_rcv_pkt_start();
do{
len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,thekey);
len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,funkencrypt?thekey:NULL);
// Receive
if(len==0||len==-1||len==-2){ //No pkt, Pkt2large, NoPktError
delayms(10);