Add old rudimentary rem0te code

This commit is contained in:
Stefan `Sec` Zehl 2011-11-19 20:36:16 +01:00
parent dc24b8488f
commit 7193ee5972
5 changed files with 603 additions and 0 deletions

View File

@ -0,0 +1,38 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/print.h"
#include "lcd/display.h"
#include "filesystem/ff.h"
#include <string.h>
/**************************************************************************/
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);
};

View File

@ -0,0 +1,272 @@
#include <sysinit.h>
#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 <string.h>
#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;i<l;i++){
if(input[inputptr+i] =='\r'){
input[inputptr+i]=0;
process(input);
if(i<l)
memmove(input,input+inputptr+i+1,l-i);
inputptr=-i-1;
break;
};
};
};
inputptr+=l;
len=nrf_rcv_pkt_poll_dec(sizeof(buf),buf,remotekey);
// Receive
if(len<=0){
delayms(10);
continue;
};
if(buf[1]=='C'){ // Cursor
puts("C ");
puts(IntToStrX( buf[2],2 ));
puts(" ");
puts(IntToStrX( uint8ptouint32(buf+4), 8 ));
puts(" ");
puts(IntToStrX( uint8ptouint32(buf+8), 8 ));
}else{
puts("U ");
// 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( uint8ptouint32(buf+4),8 ));
puts(".");
puts(IntToStrX( uint8ptouint32(buf+8),8 ));
puts(" ");
puts(IntToStrX( uint8ptouint32(buf+10),4 ));
};
puts("\r\n");
};
nrf_rcv_pkt_end();
puts("D exit");
}
void r_s1(void){
static int ctr=1;
__attribute__ ((aligned (4))) uint8_t buf[32];
int status;
buf[0]=0x10; // Length: 16 bytes
buf[1]='1'; // Proto
buf[2]=0x00;
buf[3]=0x00; // Unused
uint32touint8p(ctr++,buf+4);
uint32touint8p(0x5ec,buf+8);
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
status=nrf_snd_pkt_crc_encr(16,buf,remotekey);
lcdClear();
lcdPrint("F-St:"); lcdPrintInt(status);
lcdDisplay();
};
void r_s2(void){
static int ctr=1;
__attribute__ ((aligned (4))) uint8_t buf[32];
int status;
buf[0]=0x10; // Length: 16 bytes
buf[1]='C'; // Proto
buf[2]=0x00;
buf[3]=0x00; // Unused
uint32touint8p(ctr++,buf+4);
uint32touint8p(0x5ec,buf+8);
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
status=nrf_snd_pkt_crc_encr(16,buf,remotekey);
buf[0]=0x10; // Length: 16 bytes
buf[1]='I'; // Proto
buf[2]=0x00;
buf[3]=0x00; // Unused
uint32touint8p(ctr++,buf+4);
uint32touint8p(0x5ec,buf+8);
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
status=nrf_snd_pkt_crc_encr(16,buf,remotekey);
lcdClear();
lcdPrint("F-St:"); lcdPrintInt(status);
lcdDisplay();
};
void r_send(void){
int ctr=1;
__attribute__ ((aligned (4))) uint8_t buf[32];
int len;
int status;
while(1){
buf[0]=0x10; // Length: 16 bytes
buf[1]='C'; // Proto
buf[2]=getInputRaw();
buf[3]=0x00; // Unused
ctr++;
*(int*)(buf+4)=ctr;
/*
buf[4]=0x00; // ctr
buf[5]=0x00; // ctr
buf[6]=0x00; // ctr
buf[7]=ctr++; // ctr
*/
buf[8]=0x0; // Object id
buf[9]=0x0;
buf[10]=0x05;
buf[11]=0xec;
buf[12]=0xff; // salt (0xffff always?)
buf[13]=0xff;
lcdClear();
lcdPrint("Key:"); lcdPrintInt(buf[2]); lcdNl();
if(buf[2]==BTN_ENTER)
break;
status=nrf_snd_pkt_crc_encr(16,buf,remotekey);
lcdPrint("F-St:"); lcdPrintInt(status);
lcdDisplay();
len=nrf_rcv_pkt_time_encr(100,sizeof(buf),buf,remotekey);
if(len>0){
lcdPrint("Got!");
lcdDisplay();
break;
};
delayms(10);
};
};

View File

@ -0,0 +1,139 @@
#include <sysinit.h>
#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 <string.h>
#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);
};

View File

@ -0,0 +1,128 @@
#include <sysinit.h>
#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 <string.h>
/**************************************************************************/
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();
};

View File

@ -0,0 +1,26 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
#include "funk/nrf24l01p.h"
#include <string.h>
#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();
}