Restrict default mesh messages to discourage spamming. Allow generation wrapping. Remove some more schnitzel code.

This commit is contained in:
Stefan `Sec` Zehl 2011-12-23 02:44:17 +01:00
parent d69199e563
commit 4be69a1eab
2 changed files with 44 additions and 21 deletions

View File

@ -104,6 +104,11 @@ char *meshmsgs(void){
hi=0xff; hi=0xff;
for(int i=0;i<MESHBUFSIZE;i++){ for(int i=0;i<MESHBUFSIZE;i++){
if(meshbuffer[i].flags&MF_USED){ if(meshbuffer[i].flags&MF_USED){
if(MO_TYPE(meshbuffer[i].pkt)=='E' ||
MO_TYPE(meshbuffer[i].pkt)=='F' ||
MO_TYPE(meshbuffer[i].pkt)=='G' ||
MO_TYPE(meshbuffer[i].pkt)=='T' ||
MO_TYPE(meshbuffer[i].pkt)=='i')
if(MO_TYPE(meshbuffer[i].pkt)>lo) if(MO_TYPE(meshbuffer[i].pkt)>lo)
if(MO_TYPE(meshbuffer[i].pkt)<hi) if(MO_TYPE(meshbuffer[i].pkt)<hi)
hi=MO_TYPE(meshbuffer[i].pkt); hi=MO_TYPE(meshbuffer[i].pkt);
@ -147,16 +152,18 @@ void m_choose(){
while(1){ while(1){
char *p=list; char *p=list;
strcpy(p,"Note"); strcpy(p,"Messages");
while(*p++); while(*p++);
char *mm=meshmsgs(); char *mm=meshmsgs();
char *tmm=mm; char *tmm=mm;
while(*mm){ while(*mm){
switch(*mm){ switch(*mm){
#if 0
case('A'): case('A'):
strcpy(p,"Message"); strcpy(p,"Message");
break; break;
#endif
case('E'): case('E'):
strcpy(p,"Saal 1"); strcpy(p,"Saal 1");
break; break;

View File

@ -19,6 +19,13 @@ MPKT meshbuffer[MESHBUFSIZE];
struct NRF_CFG oldconfig; struct NRF_CFG oldconfig;
static int meshgen_gt(char gen){
unsigned char dif=meshgen-gen;
if(meshgen==0)
return 1;
return (dif>128);
};
void initMesh(void){ void initMesh(void){
for(int i=0;i<MESHBUFSIZE;i++){ for(int i=0;i<MESHBUFSIZE;i++){
meshbuffer[i].flags=MF_FREE; meshbuffer[i].flags=MF_FREE;
@ -30,6 +37,9 @@ void initMesh(void){
}; };
int mesh_sanity(uint8_t * pkt){ int mesh_sanity(uint8_t * pkt){
if(MO_TYPE(pkt)>0x7f || MO_TYPE(pkt)<0x20)
return 1;
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;
@ -41,16 +51,15 @@ int mesh_sanity(uint8_t * pkt){
if(MO_TIME(pkt)<0) if(MO_TIME(pkt)<0)
return 1; return 1;
}; };
if(MO_TYPE(pkt)!='E' && if(MO_TYPE(pkt)!='A' &&
MO_TYPE(pkt)!='a' &&
MO_TYPE(pkt)!='E' &&
MO_TYPE(pkt)!='F' && MO_TYPE(pkt)!='F' &&
MO_TYPE(pkt)!='G' && MO_TYPE(pkt)!='G' &&
MO_TYPE(pkt)!='T' && MO_TYPE(pkt)!='T'
1
){ ){
return 1; return 2;
}; };
if(MO_TYPE(pkt)>0x7f || MO_TYPE(pkt)<0x20)
return 1;
return 0; return 0;
}; };
@ -95,7 +104,7 @@ void mesh_cleanup(void){
if (MO_TIME(meshbuffer[i].pkt)-now>SECS_DAY) if (MO_TIME(meshbuffer[i].pkt)-now>SECS_DAY)
meshbuffer[i].flags=MF_FREE; meshbuffer[i].flags=MF_FREE;
}; };
if(mesh_sanity(meshbuffer[i].pkt)){ if(mesh_sanity(meshbuffer[i].pkt)==1){
meshbuffer[i].flags=MF_FREE; meshbuffer[i].flags=MF_FREE;
#if 0 #if 0
setSystemFont(); setSystemFont();
@ -202,17 +211,15 @@ uint8_t mesh_recvqloop_work(void){
return 0; return 0;
}; };
if(MO_GEN(buf)>meshgen){ // New mesh generation?
if(meshgen) if(MO_TYPE(buf)=='T'){
meshgen++; if(meshgen_gt(MO_GEN(buf))){
else
meshgen=MO_GEN(buf); meshgen=MO_GEN(buf);
_timet=0; _timet=0;
meshincctr=0; meshincctr=0;
meshnice=0; meshnice=0;
}; };
// Set new time iff newer
if(MO_TYPE(buf)=='T'){
time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED)); time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED));
if (toff>_timet){ // Do not live in the past. if (toff>_timet){ // Do not live in the past.
_timet = toff; _timet = toff;
@ -223,12 +230,18 @@ uint8_t mesh_recvqloop_work(void){
return 1; return 1;
}; };
// Discard packets with wrong generation
if(meshgen != MO_GEN(buf)){
return 0;
};
// 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;
// Store packet in a same/free slot // Store packet in a same/free slot
MPKT* mpkt=meshGetMessage(MO_TYPE(buf)); MPKT* mpkt=meshGetMessage(MO_TYPE(buf));
#if 0
// Schnitzel // Schnitzel
if(MO_TYPE(buf)=='Z'){ if(MO_TYPE(buf)=='Z'){
mpkt->flags=MF_USED|MF_LOCK; mpkt->flags=MF_USED|MF_LOCK;
@ -252,15 +265,18 @@ uint8_t mesh_recvqloop_work(void){
}; };
return 1; return 1;
}; };
#endif
// only accept newer/better packets // only accept newer/better packets
if(mpkt->flags==MF_USED) if(mpkt->flags==MF_USED)
if(MO_TIME(buf)<=MO_TIME(mpkt->pkt)) if(MO_TIME(buf)<=MO_TIME(mpkt->pkt))
return 2; return 2;
#if 0
if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') || if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') ||
(MO_TYPE(buf)>='a' && MO_TYPE(buf)<='c')) (MO_TYPE(buf)>='a' && MO_TYPE(buf)<='c'))
meshmsg=1; meshmsg=1;
#endif
memcpy(mpkt->pkt,buf,MESHPKTSIZE); memcpy(mpkt->pkt,buf,MESHPKTSIZE);
mpkt->flags=MF_USED; mpkt->flags=MF_USED;