From 7193ee5972fec2cc4a24314f0f0e4961ec345448 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sat, 19 Nov 2011 20:36:16 +0100 Subject: [PATCH] Add old rudimentary rem0te code --- firmware/applications/remote/config.c | 38 ++++ firmware/applications/remote/remote.c | 272 ++++++++++++++++++++++++++ firmware/applications/remote/serial.c | 139 +++++++++++++ firmware/applications/remote/util.c | 128 ++++++++++++ firmware/applications/remote/uuid.c | 26 +++ 5 files changed, 603 insertions(+) create mode 100644 firmware/applications/remote/config.c create mode 100644 firmware/applications/remote/remote.c create mode 100644 firmware/applications/remote/serial.c create mode 100644 firmware/applications/remote/util.c create mode 100644 firmware/applications/remote/uuid.c diff --git a/firmware/applications/remote/config.c b/firmware/applications/remote/config.c new file mode 100644 index 0000000..0d8df7c --- /dev/null +++ b/firmware/applications/remote/config.c @@ -0,0 +1,38 @@ +#include + +#include "basic/basic.h" + +#include "lcd/print.h" +#include "lcd/display.h" + +#include "filesystem/ff.h" + +#include + +/**************************************************************************/ + +void readcfg(void) { + readConfig(); +}; + +void savecfg(void){ + saveConfig(); +}; + +void applycfg(void){ + applyConfig(); +}; + +void show(void){ + lcdClear(); + lcdPrint("time:"); lcdPrintInt(globalconfig.time); lcdNl(); + lcdPrint("btrig:"); lcdPrintInt(globalconfig.backlighttrigger); lcdNl(); + lcdPrint("bval:"); lcdPrintInt(globalconfig.backlightvalue); lcdNl(); + lcdPrint("lcd:"); lcdPrintInt(globalconfig.lcdstate); lcdNl(); + lcdPrint("priv:"); lcdPrintInt(globalconfig.privacy); lcdNl(); + lcdRefresh(); +}; + +void lcdmirror(void){ + lcdToggleFlag(LCD_MIRRORX); +}; diff --git a/firmware/applications/remote/remote.c b/firmware/applications/remote/remote.c new file mode 100644 index 0000000..0c2dbb5 --- /dev/null +++ b/firmware/applications/remote/remote.c @@ -0,0 +1,272 @@ +#include + +#include "basic/basic.h" +#include "basic/byteorder.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "funk/nrf24l01p.h" +#include "usbcdc/usb.h" +#include "usbcdc/usbcore.h" +#include "usbcdc/usbhw.h" +#include "usbcdc/cdcuser.h" +#include "usbcdc/cdc_buf.h" +#include "usbcdc/util.h" + +#include + +#define REMOTE_CHANNEL 91 +#define REMOTE_MAC "REM0T" + +#if CFG_USBMSC +#error "MSC is defined" +#endif + +#if !CFG_USBCDC +#error "CDC is not defined" +#endif + +/**************************************************************************/ + +#include "SECRETS" + +void r_init(void){ + nrf_init(); + + struct NRF_CFG config = { + .channel= REMOTE_CHANNEL, + .txmac= REMOTE_MAC, + .nrmacs=1, + .mac0= REMOTE_MAC, + .maclen ="\x10", + }; + + nrf_config_set(&config); +}; + +void s_init(void){ + usbCDCInit(); + nrf_init(); + + struct NRF_CFG config = { + .channel= REMOTE_CHANNEL, + .txmac= REMOTE_MAC, + .nrmacs=1, + .mac0= REMOTE_MAC, + .maclen ="\x10", + }; + + nrf_config_set(&config); +}; + + void process(uint8_t * input){ + __attribute__ ((aligned (4))) uint8_t buf[32]; + puts("process: "); + puts(input); + puts("\r\n"); + if(input[0]=='M'){ + buf[0]=0x10; // Length: 16 bytes + buf[1]='M'; // Proto + buf[2]=0x01; + buf[3]=0x01; // Unused + + uint32touint8p(0,buf+4); + + uint32touint8p(0x41424344,buf+8); + + buf[12]=0xff; // salt (0xffff always?) + buf[13]=0xff; + nrf_snd_pkt_crc_encr(16,buf,remotekey); + nrf_rcv_pkt_start(); + }; + +}; + +#define INPUTLEN 99 +void r_recv(void){ + __attribute__ ((aligned (4))) uint8_t buf[32]; + int len; + + uint8_t input[INPUTLEN+1]; + int inputptr=0; + + nrf_rcv_pkt_start(); + puts("D start"); + + getInputWaitRelease(); + + while(!getInputRaw()){ + delayms(100); + + // Input + int l=INPUTLEN-inputptr; + CDC_OutBufAvailChar (&l); + + if(l>0){ + CDC_RdOutBuf (input+inputptr, &l); + input[inputptr+l+1]=0; + for(int i=0;i0){ + lcdPrint("Got!"); + lcdDisplay(); + break; + }; + delayms(10); + }; +}; + diff --git a/firmware/applications/remote/serial.c b/firmware/applications/remote/serial.c new file mode 100644 index 0000000..94d41b3 --- /dev/null +++ b/firmware/applications/remote/serial.c @@ -0,0 +1,139 @@ +#include + +#include "basic/basic.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "funk/nrf24l01p.h" + +#include "usbcdc/usb.h" +#include "usbcdc/usbcore.h" +#include "usbcdc/usbhw.h" +#include "usbcdc/cdcuser.h" +#include "usbcdc/cdc_buf.h" +#include "usbcdc/util.h" + +#include + +#define BEACON_CHANNEL 81 +#define BEACON_MAC "\x1\x2\x3\x2\1" + +uint32_t const testkey[4] = { + 0xB4595344,0xD3E119B6,0xA814D0EC,0xEFF5A24E +}; + +#if CFG_USBMSC +#error "MSC is defined" +#endif + +#if !CFG_USBCDC +#error "CDC is not defined" +#endif + +/**************************************************************************/ + + +void ser_enable(void) { + usbCDCInit(); +}; + +void ser_disable(void) { + usbCDCOff(); +}; + +#define myLEN 10 +void ser_read(){ + uint8_t buf[myLEN+1]; + int l=myLEN; + + lcdPrint("Bytes:"); + CDC_OutBufAvailChar (&l); + lcdPrintInt(l); + lcdNl(); + + lcdPrint("read:"); + CDC_RdOutBuf (buf, &l); + lcdPrintInt(l); + lcdNl(); + + buf[l]=0; + lcdPrintln(buf); +}; + +void ser_say(){ + puts("hello world\r\n"); +}; + +void f_init(){ + nrf_init(); + struct NRF_CFG config = { + .channel= BEACON_CHANNEL, + .txmac= BEACON_MAC, + .nrmacs=1, + .mac0= BEACON_MAC, + .maclen ="\x10", + }; + + nrf_config_set(&config); +}; + +void f_beacon(void){ + struct NRF_CFG config = { + .channel= BEACON_CHANNEL, + .txmac= BEACON_MAC, + .nrmacs=1, + .mac0= BEACON_MAC, + .maclen ="\x10", + }; + + nrf_config_set(&config); +}; + +int enctoggle=0; + +void f_enctog(){ + enctoggle=1-enctoggle; + lcdClear(); + lcdPrint("Encryption:"); + if(enctoggle) + lcdPrintln("ON"); + else + lcdPrintln("Off"); +}; + +void f_recser(void){ + __attribute__ ((aligned (4))) uint8_t buf[32]; + int len; + + getInputWaitRelease(); + + do{ + len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,enctoggle?testkey:NULL); + + if(len==0){ + puts("(Timeout)\r\n"); + }; + puts("pkt: "); + puts("[");puts(IntToStrX(len,2));puts("] "); + puts(IntToStrX( *(int*)(buf+ 0),2 )); + puts(" "); + puts(IntToStrX( *(int*)(buf+ 1),2 )); + puts(" "); + puts(IntToStrX( *(int*)(buf+ 2),2 )); + puts(" "); + puts(IntToStrX( *(int*)(buf+ 3),2 )); + puts("."); + puts(IntToStrX( *(int*)(buf+ 4),8 )); + puts("."); + puts(IntToStrX( *(int*)(buf+ 8),8 )); + puts("."); + puts(IntToStrX( *(int*)(buf+ 12),4 )); + puts(" ["); + + len=crc16(buf,14); + puts(IntToStrX(len,4)); puts("]\r\n"); + delayms(10); + }while ((getInputRaw())==BTN_NONE); + +}; diff --git a/firmware/applications/remote/util.c b/firmware/applications/remote/util.c new file mode 100644 index 0000000..8359628 --- /dev/null +++ b/firmware/applications/remote/util.c @@ -0,0 +1,128 @@ +#include + +#include "basic/basic.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" +#include "lcd/allfonts.h" + +#include "filesystem/ff.h" +#include "filesystem/select.h" +#include "funk/nrf24l01p.h" +#include "usb/usbmsc.h" + +#include + +/**************************************************************************/ + +void show_ticks(void) { + int dx=0; + int dy=8; + lcdClear(); + dx=DoString(0,dy,"Ticks:"); + while ((getInputRaw())==BTN_NONE){ + DoInt(0,dy+8,_timectr); + lcdDisplay(); + }; + dy+=16; + dx=DoString(0,dy,"Done."); +}; + + +void chrg_stat(void) { + int stat; + while ((getInputRaw())==BTN_NONE){ + lcdClear(); + lcdPrintln("Chrg_stat:"); + stat=gpioGetValue(RB_PWR_CHRG); + lcdPrint(IntToStr(stat,3,0)); + lcdNl(); + lcdRefresh(); + }; + lcdPrintln("Done."); +}; +void adc_light(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(); + }; + dy+=8; + dx=DoString(0,dy,"Done."); +}; + +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(); + lcdRefresh(); + delayms_queue(200); + }; + lcdPrintln("done."); +}; + +void gotoISP(void) { + DoString(0,0,"Enter ISP!"); + lcdDisplay(); + ISPandReset(); +} + +void lcd_mirror(void) { + lcdToggleFlag(LCD_MIRRORX); +}; + +void lcd_invert(void) { + lcdToggleFlag(LCD_INVERTED); +}; + +void adc_check(void) { + int dx=0; + int dy=8; + // Print Voltage + dx=DoString(0,dy,"Voltage:"); + while ((getInputRaw())==BTN_NONE){ + DoInt(dx,dy,GetVoltage()); + lcdDisplay(); + }; + dy+=8; + dx=DoString(0,dy,"Done."); +}; + +void msc_menu(void){ + DoString(0,8,"MSC Enabled."); + lcdDisplay(); + usbMSCInit(); + getInputWaitRelease(); + getInputWait(); + DoString(0,16,"MSC Disabled."); + usbMSCOff(); +}; + diff --git a/firmware/applications/remote/uuid.c b/firmware/applications/remote/uuid.c new file mode 100644 index 0000000..601a5f7 --- /dev/null +++ b/firmware/applications/remote/uuid.c @@ -0,0 +1,26 @@ +#include + +#include "basic/basic.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" + +#include "funk/nrf24l01p.h" + +#include + +#include "funk/rftransfer.h" +#include "funk/openbeacon.h" + +#include "core/iap/iap.h" + +/**************************************************************************/ + +void f_uuid(void) { + IAP_return_t iap_return; + iap_return = iapReadSerialNumber(); + lcdPrintIntHex(iap_return.Result[0]); lcdNl(); + lcdPrintIntHex(iap_return.Result[1]); lcdNl(); + lcdPrintIntHex(iap_return.Result[2]); lcdNl(); + lcdPrintIntHex(iap_return.Result[3]); lcdNl(); +}