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

View File

@ -19,6 +19,13 @@ MPKT meshbuffer[MESHBUFSIZE];
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){
for(int i=0;i<MESHBUFSIZE;i++){
meshbuffer[i].flags=MF_FREE;
@ -30,6 +37,9 @@ void initMesh(void){
};
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_TIME(pkt)>1325379600)
return 1;
@ -41,16 +51,15 @@ int mesh_sanity(uint8_t * pkt){
if(MO_TIME(pkt)<0)
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)!='G' &&
MO_TYPE(pkt)!='T' &&
1
MO_TYPE(pkt)!='T'
){
return 1;
return 2;
};
if(MO_TYPE(pkt)>0x7f || MO_TYPE(pkt)<0x20)
return 1;
return 0;
};
@ -95,7 +104,7 @@ void mesh_cleanup(void){
if (MO_TIME(meshbuffer[i].pkt)-now>SECS_DAY)
meshbuffer[i].flags=MF_FREE;
};
if(mesh_sanity(meshbuffer[i].pkt)){
if(mesh_sanity(meshbuffer[i].pkt)==1){
meshbuffer[i].flags=MF_FREE;
#if 0
setSystemFont();
@ -202,17 +211,15 @@ uint8_t mesh_recvqloop_work(void){
return 0;
};
if(MO_GEN(buf)>meshgen){
if(meshgen)
meshgen++;
else
meshgen=MO_GEN(buf);
_timet=0;
meshincctr=0;
meshnice=0;
};
// New mesh generation?
if(MO_TYPE(buf)=='T'){
if(meshgen_gt(MO_GEN(buf))){
meshgen=MO_GEN(buf);
_timet=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;
@ -223,12 +230,18 @@ uint8_t mesh_recvqloop_work(void){
return 1;
};
// Discard packets with wrong generation
if(meshgen != MO_GEN(buf)){
return 0;
};
// Safety: Truncate ascii packets by 0-ing the CRC
buf[MESHPKTSIZE-2]=0;
// Store packet in a same/free slot
MPKT* mpkt=meshGetMessage(MO_TYPE(buf));
#if 0
// Schnitzel
if(MO_TYPE(buf)=='Z'){
mpkt->flags=MF_USED|MF_LOCK;
@ -252,15 +265,18 @@ uint8_t mesh_recvqloop_work(void){
};
return 1;
};
#endif
// only accept newer/better packets
if(mpkt->flags==MF_USED)
if(MO_TIME(buf)<=MO_TIME(mpkt->pkt))
return 2;
#if 0
if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') ||
(MO_TYPE(buf)>='a' && MO_TYPE(buf)<='c'))
meshmsg=1;
#endif
memcpy(mpkt->pkt,buf,MESHPKTSIZE);
mpkt->flags=MF_USED;