Merge branch 'master' of github.com:r0ket/r0ket

This commit is contained in:
Stefan `Sec` Zehl 2011-07-17 21:58:44 +02:00
commit 54e29bc10b
7 changed files with 66 additions and 97 deletions

View File

@ -11,7 +11,7 @@ FATFS FatFs[_VOLUMES]; /* File system object for logical drive */
#define CONFIGLEN 2
int lcdInitConfig(){
FIL file[2]; /* File objects */
FIL file; /* File objects */
BYTE buf[CONFIGLEN];
UINT readbytes;
int res;
@ -24,13 +24,13 @@ int lcdInitConfig(){
return 1;
};
res=f_open(&file[0], "r0ket.cfg", FA_OPEN_EXISTING|FA_READ);
res=f_open(&file, "r0ket.cfg", FA_OPEN_EXISTING|FA_READ);
lcdPrint("open:");
lcdPrintln(f_get_rc_string(res));
if(res){
lcdPrintln("new r0ket.cfg...");
res=f_open(&file[0], "r0ket.cfg", FA_OPEN_ALWAYS|FA_WRITE);
res=f_open(&file, "r0ket.cfg", FA_OPEN_ALWAYS|FA_WRITE);
lcdPrint("create:");
lcdPrintln(f_get_rc_string(res));
if(res){
@ -39,7 +39,7 @@ int lcdInitConfig(){
buf[0]='0';
buf[1]='0';
res = f_write(&file[0], buf, 2, &readbytes);
res = f_write(&file, buf, 2, &readbytes);
lcdPrint("write:");
lcdPrintln(f_get_rc_string(res));
if(res){
@ -50,7 +50,7 @@ int lcdInitConfig(){
lcdPrintInt(readbytes);
lcdPrintln("b");
res=f_close(&file[0]);
res=f_close(&file);
lcdPrint("close:");
lcdPrintln(f_get_rc_string(res));
if(res){
@ -62,7 +62,7 @@ int lcdInitConfig(){
for(int i=0;i<CONFIGLEN;i++)
buf[i]=0;
res = f_read(&file[0], buf, 2, &readbytes);
res = f_read(&file, buf, 2, &readbytes);
lcdPrint("read:");
lcdPrintln(f_get_rc_string(res));
if(res){
@ -79,7 +79,7 @@ int lcdInitConfig(){
if(buf[1] == '1')
lcdToggleFlag(LCD_MIRRORX);
res=f_close(&file[0]);
res=f_close(&file);
lcdPrint("close:");
lcdPrintln(f_get_rc_string(res));
if(res){

View File

@ -14,6 +14,7 @@ OBJS += crc.o
OBJS += menu.o
OBJS += xxtea.o
OBJS += ecc.o
OBJS += byteorder.o
LIBNAME=basic

View File

@ -0,0 +1,19 @@
#include <stdint.h>
void uint32touint8p(uint32_t v, uint8_t *p)
{
*p++ = (v>>24)&0xFF;
*p++ = (v>>16)&0xFF;
*p++ = (v>> 8)&0xFF;
*p++ = (v>> 0)&0xFF;
}
uint32_t uint8ptouint32(uint8_t *p)
{
uint32_t v;
v |= *p++; v<<=8;
v |= *p++; v<<=8;
v |= *p++; v<<=8;
v |= *p;
return v;
}

View File

@ -0,0 +1,9 @@
#ifndef _BYTEORDER_H_
#define _BYTEORDER_H_
#include <stdint.h>
void uint32touint8p(uint32_t v, uint8_t *p);
uint32_t uint8ptouint32(uint8_t *p);
#endif

View File

@ -14,86 +14,6 @@
#define MX (((z>>5^y<<2) + (y>>3^z<<4)) ^ ((sum^y) + (k[(p&3)^e] ^ z)))
#include "xxtea.h"
uint32_t charp2uint32(uint8_t *data, uint8_t bytes)
{
uint32_t r = 0;
if( bytes ){
r |= *data++;
}
if( bytes > 1){
r<<=8;
r |= *data++;
}
if( bytes > 2){
r<<=8;
r |= *data++;
}
if( bytes > 3){
r<<=8;
r |= *data++;
}
return r;
}
void charp2uint32p(uint8_t* data, uint8_t n, uint32_t *v)
{
int i,j=0;
int fullwords = n/4;
for(i=0; i<fullwords*4; i+=4){
v[j++] = charp2uint32(data+i,4);
}
uint8_t extrabytes = n - i;
v[j] = charp2uint32(data+i,extrabytes);
}
void uint322charp(uint32_t data, uint8_t *buf, uint8_t bytes)
{
if( bytes )
buf[0] = data>>24;
if( bytes > 1)
buf[1] = (data>>16)&0xFF;
if( bytes > 2)
buf[2] = (data>>8)&0xFF;
if( bytes > 3)
buf[3] = (data>>0)&0xFF;
}
void uint32p2charp(uint8_t* data, uint8_t n, uint32_t *v)
{
int i;
int fullwords = n/4;
for(i=0; i<fullwords; i++){
uint322charp(v[i],data+i*4,4);
}
uint8_t extrabytes = n - fullwords*4;
uint322charp(v[i],data+i*4,extrabytes);
}
void xxtea_encode(uint8_t *data, int n, uint32_t const k[4])
{
uint32_t v[8]; //maximum 32 bytes
int words = (n+3)/4;
if( words > 8 )
return;
charp2uint32p(data, n, v);
xxtea_encode_words(v, words, k);
uint32p2charp(data, n, v);
}
void xxtea_decode(uint8_t *data, int n, uint32_t const k[4])
{
uint32_t v[8]; //maximum 32 bytes
int words = (n+3)/4;
if( words > 8 )
return;
charp2uint32p(data, n, v);
xxtea_decode_words(v, words, k);
uint32p2charp(data, n, v);
}
void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4])
{
if(k[0] == 0 && k[1] == 0 && k[2] == 0 && k[3] == 0) return;

View File

@ -1,12 +1,6 @@
#ifndef _XXTEA_H_
#define _XXTEA_H_
uint32_t charp2uint32(uint8_t *data, uint8_t bytes);
void charp2uint32p(uint8_t* data, uint8_t n, uint32_t *v);
void uint322charp(uint32_t data, uint8_t *buf, uint8_t bytes);
void uint32p2charp(uint8_t* data, uint8_t n, uint32_t *v);
void xxtea_encode(uint8_t *data, int n, uint32_t const k[4]);
void xxtea_decode(uint8_t *v, int n, uint32_t const k[4]);
void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4]);
void xxtea_decode_words(uint32_t *v, int n, uint32_t const k[4]);

View File

@ -3,19 +3,45 @@
#include "funk/nrf24l01p.h"
#include "basic/byteorder.h"
#include "sysdefs.h"
#include "filesystem/ff.h"
const uint32_t key[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
const uint8_t enctoggle = 0;
const uint8_t mac[5] = {1,2,3,2,1};
uint32_t oid = 0;
uint32_t ctr = 0;
uint8_t strength = 0;
void openbeaconSave()
{
FIL file;
BYTE buf[4];
UINT readbytes;
if( f_open(&file, "beacon", FA_OPEN_ALWAYS|FA_WRITE) )
return;
uint32touint8p(ctr, buf);
if( f_write(&file, buf, 4, &readbytes) )
return;
f_close(&file);
}
void openbeaconRead()
{
FIL file;
BYTE buf[4];
UINT readbytes;
if( f_open(&file, "beacon", FA_OPEN_EXISTING|FA_READ) )
return;
if( f_read(&file, buf, 4, &readbytes) )
return;
ctr = uint8ptouint32(buf);
}
@ -47,13 +73,13 @@ void openbeaconSendPacket(uint32_t id, uint32_t ctr, uint8_t flags, uint8_t stre
void openbeaconSend(void)
{
//uint8_t tmp = nrfgetstrength();
//nrfsetstrength(strength);
nrf_set_strength(strength);
nrf_set_tx_mac(sizeof(mac), mac);
openbeaconSendPacket(oid, ctr++, 0xFF, strength++);
if( strength == 4 )
strength = 0;
if( ctr % OPENBEACON_SAVECOUNTER == 0 )
openbeaconSave();
//maybe this produces timing problems?
//nrfsetstrength(tmp);
}