I shouldn't tell. But apparently I'm stupid.

This commit is contained in:
Stefan `Sec` Zehl 2011-12-28 01:06:22 +01:00
parent 13a1cb9521
commit e9194825d9
1 changed files with 37 additions and 27 deletions

View File

@ -39,7 +39,8 @@ void initMesh(void){
int mesh_sanity(uint8_t * pkt){ int mesh_sanity(uint8_t * pkt){
if(MO_TYPE(pkt)>0x7f || MO_TYPE(pkt)<0x20) if(MO_TYPE(pkt)>0x7f || MO_TYPE(pkt)<0x20)
return 1; return 1;
if(MO_TYPE(pkt)=='T' && MO_BODY(pkt)[5])
return 3;
if(MO_TYPE(pkt)>='A' && MO_TYPE(pkt)<='Z'){ if(MO_TYPE(pkt)>='A' && MO_TYPE(pkt)<='Z'){
if(MO_TIME(pkt)>1325379600) if(MO_TIME(pkt)>1325379600)
return 1; return 1;
@ -88,6 +89,22 @@ MPKT * meshGetMessage(uint8_t type){
return &meshbuffer[free]; return &meshbuffer[free];
}; };
void meshPanic(uint8_t * pkt){
#if 0
setSystemFont();
lcdClear();
lcdPrint("MESH-PANIC:");
lcdNl();
for(int i=0;i<32;i++){
lcdPrint(IntToStrX(pkt[i],2));
if(i%6==5)
lcdNl();
}
lcdRefresh();
while ((getInputRaw())==BTN_NONE);
#endif
};
void mesh_cleanup(void){ void mesh_cleanup(void){
time_t now=getSeconds(); time_t now=getSeconds();
for(int i=1;i<MESHBUFSIZE;i++){ for(int i=1;i<MESHBUFSIZE;i++){
@ -107,21 +124,10 @@ void mesh_cleanup(void){
}; };
if(mesh_sanity(meshbuffer[i].pkt)==1){ if(mesh_sanity(meshbuffer[i].pkt)==1){
meshbuffer[i].flags=MF_FREE; meshbuffer[i].flags=MF_FREE;
#if 0 };
setSystemFont(); if(mesh_sanity(meshbuffer[i].pkt)==3){
lcdClear(); meshbuffer[i].flags=MF_FREE;
lcdPrintln("MESH PANIC!"); meshPanic(meshbuffer[i].pkt);
lcdPrint(IntToStr(i,2,0));
lcdPrintln(":");
lcdPrint(IntToStrX(meshbuffer[i].pkt[0],2));
lcdPrint(" ");
lcdPrintln(IntToStrX(meshbuffer[i].pkt[1],2));
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[i].pkt+2),8));
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[i].pkt+6),8));
lcdPrintln(IntToStrX(uint8ptouint32(meshbuffer[i].pkt+10),8));
lcdRefresh();
while ((getInputRaw())==BTN_NONE);
#endif
}; };
}; };
}; };
@ -209,26 +215,20 @@ uint8_t mesh_recvqloop_work(void){
if(mesh_sanity(buf)){ if(mesh_sanity(buf)){
meshincctr++; meshincctr++;
if(mesh_sanity(buf)==3){
meshPanic(buf);
};
return 0; return 0;
}; };
// New mesh generation? // New mesh generation?
if(MO_TYPE(buf)=='T'){ if(MO_TYPE(buf)=='T'){
if(mesh_gt(meshgen,MO_GEN(buf))){ if(mesh_gt(meshgen,MO_GEN(buf))){
meshgen=MO_GEN(buf);
_timet=0; _timet=0;
meshincctr=0; meshincctr=0;
meshnice=0;
};
// Set new time iff newer
time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED));
if (toff>_timet){ // Do not live in the past.
_timet = toff;
meshincctr++;
};
if(MO_BODY(buf)[4] > meshnice)
meshnice=MO_BODY(buf)[4]; meshnice=MO_BODY(buf)[4];
return 1; meshgen=MO_GEN(buf);
};
}; };
// Discard packets with wrong generation // Discard packets with wrong generation
@ -236,6 +236,16 @@ uint8_t mesh_recvqloop_work(void){
return 0; return 0;
}; };
// Set new time iff newer
if(MO_TYPE(buf)=='T'){
time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED));
if (toff>_timet){ // Do not live in the past.
_timet = toff;
meshincctr++;
};
return 1;
};
// Safety: Truncate ascii packets by 0-ing the CRC // Safety: Truncate ascii packets by 0-ing the CRC
buf[MESHPKTSIZE-2]=0; buf[MESHPKTSIZE-2]=0;