-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbowler.c
44 lines (33 loc) · 1.32 KB
/
bowler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "bowler.h"
#include "packet_header.h"
#include "packet_payload.h"
char runParserSM(V4MicroParser_state *s){
switch(s->state){
case align:
HOOK_SM_ALIGN(s);
/* Do we have a packet header's worth of bytes */
if (s->fifo.inPointer>=sizeof(bowler4_header_fields)){
bowler4_header *h = fifoPeek_array(&s->fifo,sizeof(bowler4_header),0);
HOOK_SM_ALIGN_ENOUGHBYTES(s);
/* Is the packet valid? Does it start with 0x04 and have a valid checksum? */
/* Is it a downstream packet? Is it addressed to us? ) */
if (h->fields.version==0x04 && verify_checksum(h) && testDirection(h->fields.affect)==0x00 && check_mac_address(s->macaddr,h)){
HOOK_SM_ALIGN_VALID_PACKET(s);
/* valid packet. go to next state */
s->state=pailoadWait;
} else {
/* Try to re-align by looking for 0x04. */
unsigned char i=0;
for (i=1; i<(s->fifo.inPointer); i++) if (fifoPeek(&s->fifo,i)==0x04) break;
HOOK_SM_ALIGN_INVALID_PACKET(s,i);
/* Pull off junk bytes before the newly found 4 (or pull em all off cause 4 was not found) */
fifoPull(&s->fifo,i);
}
}
break;
case pailoadWait: printf("PailoadWait..\n"); s->state=pailoadWait; break;
case RPC: printf("RPC..\n"); s->state=align; break;
}
}
void printParserState(V4MicroParser_state *s){
}