From ef4f5d13713344b0abce4848e94dd3af05bfc4cd Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 3 Aug 2011 19:19:49 +0200 Subject: [PATCH 1/6] Remove stuff that is now loadable --- firmware/applications/final/mesh.c | 53 ----------- firmware/applications/final/util.c | 141 ----------------------------- 2 files changed, 194 deletions(-) diff --git a/firmware/applications/final/mesh.c b/firmware/applications/final/mesh.c index 84b4784..82ffc73 100644 --- a/firmware/applications/final/mesh.c +++ b/firmware/applications/final/mesh.c @@ -22,59 +22,6 @@ void init_mesh(void){ initMesh(); }; -void m_tset(void){ - _timet=1311961112; -}; - -//# MENU debug MeshInfo -void m_time(void){ - struct tm* tm; - char c[2]={0,0}; - getInputWaitRelease(); - delayms(100); - do{ - lcdClear(); - tm= mygmtime(getSeconds()); - lcdPrint(IntToStr(tm->tm_hour,2,F_LONG)); - lcdPrint(":"); - lcdPrint(IntToStr(tm->tm_min,2,F_LONG|F_ZEROS)); - lcdPrint(":"); - lcdPrint(IntToStr(tm->tm_sec,2,F_LONG|F_ZEROS)); - lcdNl(); - lcdPrint(IntToStr(tm->tm_mday,2,F_LONG)); - lcdPrint("."); - lcdPrint(IntToStr(tm->tm_mon+1,2,0)); - lcdPrint("."); - lcdPrint(IntToStr(tm->tm_year+YEAR0,4,F_LONG|F_ZEROS)); - lcdNl(); - - lcdNl(); - lcdPrint("<"); - - for(int i=0;i"); - - lcdPrint("Gen:"); - lcdPrintInt(meshgen); - lcdNl(); - lcdRefresh(); - delayms_queue(50); - }while ((getInputRaw())==BTN_NONE); -}; - - -inline void blink(char a, char b){ - gpioSetValue (a,b, 1-gpioGetValue(a,b)); -}; - - int choose(char * texts, int8_t menuselection){ uint8_t numentries = 0; uint8_t visible_lines = 0; diff --git a/firmware/applications/final/util.c b/firmware/applications/final/util.c index fb4fbe7..aa99c61 100644 --- a/firmware/applications/final/util.c +++ b/firmware/applications/final/util.c @@ -13,147 +13,6 @@ /**************************************************************************/ -//# MENU debug ChkLight -void ChkLight(void) { - int dx=0; - int dy=8; - dx=DoString(0,dy,"Light:"); - DoString(0,dy+16,"Night:"); - while ((getInputRaw())==BTN_NONE){ - DoInt(dx,dy,GetLight()); - DoInt(dx,dy+16,isNight()); - DoInt(dx,dy+8,GLOBAL(daytrig)); - lcdDisplay(); - delayms_queue(100); - }; - dx=DoString(0,dy+24,"Done."); -} - -//# MENU debug ChkBattery -void ChkBattery(void) { - do{ - lcdClear(); - lcdPrintln("Voltage:"); - lcdPrintln(IntToStr(GetVoltage(),5,0)); - lcdNl(); - lcdPrintln("Chrg_stat:"); - if(gpioGetValue(RB_PWR_CHRG)){ - lcdPrintln("1"); - }else{ - lcdPrintln("0"); - }; - lcdRefresh(); - delayms_queue(100); - } while ((getInputRaw())==BTN_NONE); -} - -//# MENU debug Uptime -void uptime(void) { - int t; - int h; - char flag; - while ((getInputRaw())==BTN_NONE){ - lcdClear(); - lcdPrintln("Uptime:"); - t=getTimer()/(1000/SYSTICKSPEED); - h=t/60/60; - flag=F_ZEROS; - if(h>0){ - lcdPrint(IntToStr(h,2,flag)); - lcdPrint("h"); - flag|=F_LONG; - }; - h=t/60%60; - if(h>0){ - lcdPrint(IntToStr(h,2,flag)); - lcdPrint("m"); - flag|=F_LONG; - }; - h=t%60; - if(h>0){ - lcdPrint(IntToStr(h,2,flag)); - lcdPrint("s"); - }; - lcdNl(); - lcdNl(); - lcdPrintln("Ticks:"); - lcdPrint(IntToStr(_timectr,10,0)); - lcdRefresh(); - delayms_queue(200); - }; - lcdPrintln("done."); -} - -//# MENU debug Uuid -void uuid(void) { - IAP_return_t iap_return; - iap_return = iapReadSerialNumber(); - lcdClear(); - lcdPrintln("UUID:"); - lcdPrintIntHex(iap_return.Result[0]); lcdNl(); - lcdPrintIntHex(iap_return.Result[1]); lcdNl(); - lcdPrintIntHex(iap_return.Result[2]); lcdNl(); - lcdPrintIntHex(iap_return.Result[3]); lcdNl(); - lcdNl(); - lcdPrintln("Beacon ID:"); - lcdPrintln(IntToStrX(GetUUID32(),4)); - lcdRefresh(); -} - -//# MENU debug Qstatus -void Qstatus(void) { - int dx=0; - int dy=8; - lcdClear(); - dx=DoString(0,dy+16,"Qdepth:"); - while ((getInputRaw())!=BTN_ENTER){ - DoInt(dx,dy+16,(the_queue.qend-the_queue.qstart+MAXQENTRIES)%MAXQENTRIES); - lcdDisplay(); - if(getInputRaw()!=BTN_NONE) - work_queue(); - else - delayms(10); - }; - dy+=16; - dx=DoString(0,dy,"Done."); -}; - -void blink_led0(void){ - gpioSetValue (RB_LED0, 1-gpioGetValue(RB_LED0)); -}; - -void tick_alive(void){ - static int foo=0; - - if(GLOBAL(alivechk)==0) - return; - - if(foo++>500/SYSTICKSPEED){ - foo=0; - if(GLOBAL(alivechk)==2) - push_queue(blink_led0); - else - blink_led0(); - }; - return; -}; - -//# MENU debug ShowSP -void getsp(void) { - int dx=0; - int dy=8; - int x; - lcdClear(); - dx=DoString(0,dy,"SP:"); - while ((getInputRaw())==BTN_NONE){ - __asm( "mov %0, sp\n" : "=r" (x) :); - DoIntX(0,dy+8,x); - lcdDisplay(); - delayms_queue(50); - }; - dy+=16; - dx=DoString(0,dy,"Done."); -}; //# MENU msc void msc_menu(void){ From 7170789b3e855911e43256cd8df54ad54bbb4cae Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 3 Aug 2011 21:56:41 +0200 Subject: [PATCH 2/6] Enhance serial code --- firmware/SERIAL_DOKU | 2 ++ firmware/applications/serial/serial.c | 29 ++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/firmware/SERIAL_DOKU b/firmware/SERIAL_DOKU index 4c28ee7..d67b459 100644 --- a/firmware/SERIAL_DOKU +++ b/firmware/SERIAL_DOKU @@ -4,6 +4,8 @@ Ck: set encryptionkey Ct: set txmac Cc: set channel Ct: set rxmac(0) +Cl: set rxlens +Ce: sec encrpytion on/off s : send packet s+ : send packet 10 times diff --git a/firmware/applications/serial/serial.c b/firmware/applications/serial/serial.c index f27dada..287001a 100644 --- a/firmware/applications/serial/serial.c +++ b/firmware/applications/serial/serial.c @@ -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); From 0c7afe0eb1707691e5acaeae1d0fdb5c5422276e Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 3 Aug 2011 21:57:09 +0200 Subject: [PATCH 3/6] Disable unencrypted receive by default. also add meshkey --- firmware/funk/mesh.c | 2 +- firmware/funk/nrf24l01p.c | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index e69a798..da30c60 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -12,7 +12,7 @@ char meshincctr=0; // Generation MPKT meshbuffer[MESHBUFSIZE]; uint32_t const meshkey[4] = { - 0x00000000, 0x00000000, 0x00000000, 0x00000000 + 0x00000042, 0x000005ec, 0x00000023, 0x00000005 }; struct NRF_CFG oldconfig; diff --git a/firmware/funk/nrf24l01p.c b/firmware/funk/nrf24l01p.c index 8c3c464..383df03 100644 --- a/firmware/funk/nrf24l01p.c +++ b/firmware/funk/nrf24l01p.c @@ -153,13 +153,12 @@ int nrf_rcv_pkt_poll_dec(int maxsize, uint8_t * pkt, uint32_t const key[4]){ return len; cmpcrc=crc16(pkt,len-2); - if(cmpcrc != (pkt[len-2] <<8 | pkt[len-1])) { + if(key!=NULL) xxtea_decode_words((uint32_t*)pkt,len/4,key); - cmpcrc=crc16(pkt,len-2); - if(cmpcrc != (pkt[len-2] <<8 | pkt[len-1])) { - return -3; // CRC failed - }; + cmpcrc=crc16(pkt,len-2); + if(cmpcrc != (pkt[len-2] <<8 | pkt[len-1])) { + return -3; // CRC failed }; return len; }; From 2cb887025860ec8a1ea0e642316f4456e6611e8e Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 3 Aug 2011 21:58:11 +0200 Subject: [PATCH 4/6] Invaders renamed for 8.3 --- firmware/l0dable/{spaceinvaders.c => invaders.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename firmware/l0dable/{spaceinvaders.c => invaders.c} (100%) diff --git a/firmware/l0dable/spaceinvaders.c b/firmware/l0dable/invaders.c similarity index 100% rename from firmware/l0dable/spaceinvaders.c rename to firmware/l0dable/invaders.c From ca86558f3a09ed24b56798c34ce99ce1e9bae344 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 3 Aug 2011 21:58:39 +0200 Subject: [PATCH 5/6] better make clean --- firmware/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/Makefile b/firmware/Makefile index 732c824..349b4ff 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -73,6 +73,8 @@ clean: for dir in $(SUBDIRS); do \ $(MAKE) $(CONFIG_MAKE_PRINTDIRECTORY) -C $$dir clean; \ done + $(MAKE) $(CONFIG_MAKE_PRINTDIRECTORY) -C l0dable clean + flash: all ../tools/bootloader/autoflash From 44802d4b281a65d242c1cd3b70f5eca27d4ad078 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 3 Aug 2011 21:59:47 +0200 Subject: [PATCH 6/6] More ram size for loadables --- firmware/Makefile.inc | 2 +- firmware/filesystem/execute.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/Makefile.inc b/firmware/Makefile.inc index 855d011..69097c0 100644 --- a/firmware/Makefile.inc +++ b/firmware/Makefile.inc @@ -7,7 +7,7 @@ TARGET = LPC13xx FLASH = 32K SRAM = 8K -RAMCODE=2048 +RAMCODE=2548 # For USB HID support the LPC134x reserves 384 bytes from the sram, # if you don't want to use the USB features, just use 0 here. diff --git a/firmware/filesystem/execute.c b/firmware/filesystem/execute.c index 9b0aa91..3ae2a86 100644 --- a/firmware/filesystem/execute.c +++ b/firmware/filesystem/execute.c @@ -30,7 +30,7 @@ void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){ dst=(void (*)(void)) (sram_top); lcdPrint("T:"); lcdPrintIntHex(dst); lcdNl(); */ - dst=(void (*)(void)) 0x10001800; + dst=(void (*)(void)) 0x1000160C; res=f_open(&file, fname, FA_OPEN_EXISTING|FA_READ);