static char IPv6(u_char *bytes, unsigned long len) { ipv6hdr *ipv6; size_t ipv6hdr_len; size_t ipv6_len; u_char *next; ipv6 = (ipv6hdr *)bytes; ipv6hdr_len = sizeof(ipv6hdr); ipv6_len = ipv6hdr_len + ntohs(ipv6->plen); if (ipv6_len > len) { return 0; } next = bytes + ipv6hdr_len; len = ipv6_len - ipv6hdr_len; if (def == 0) { ipv6f = 1; memcpy(ipv6_src, ipv6->saddr.s6_addr, IPV6_DIM); memcpy(ipv6_dst, ipv6->daddr.s6_addr, IPV6_DIM); } else n_ipv6 = ipv6; switch (ipv6->nxt) { case IP_PROTO_TCP: if (def) { if (udpf) return 0; } return Tcp(next, len); break; case IP_PROTO_UDP: if (def) { if (udpf == 0) return 0; } return Udp(next, len); break; } return 0; }
void GsmRun(void) { switch (Gsm.ConnectionStatus) { case InitGsm: GsmInit(); break;//InitGsm case GsmConnected: // Tcp(); break;//GsmConnected case GsmDisconnected: break;//GsmDisconnected case Gsm_CSQ_Low: break;//Gsm_CSQ_Low } switch (Gsm.TimeStatus) { case TimerInit: switch (Gsm.ConnectionStatus) { case InitGsm: GsmConfig(Con_InitState,Con_ATE0,Con_ATE0,MsgSend, MsgOk,Sec(5),Sec(10),TimerStart); break;//InitGsm case GsmConnected: GsmConfig(CheckCSQ,CheckCSQ,CheckCSQ,MsgSend, T_CsqReceived,Sec(1),Sec(10),TimerStart); break;//GsmConnected case GsmDisconnected: nop(); break;//GsmDisconnected case Gsm_CSQ_Low: nop(); break;//Gsm_CSQ_Low } break;//TimerInit case TimerRunning: switch (Gsm.ConnectionStatus) { case InitGsm: if(GsmPtr->NextState==Con_CNMI) { if((GsmPtr->TickCnt)%20==0){ drv_sim900_send_cmd(4,"AT\r\n");//test } else if((GsmPtr->TickCnt)%40==0){ drv_sim900_send_cmd(6,"ATE0\r\n");//test } } break;//InitGsm case GsmConnected: nop(); break;//GsmConnected case GsmDisconnected: break;//GsmDisconnected case Gsm_CSQ_Low: break;//Gsm_CSQ_Low } nop(); break; case TimerOver: switch (Gsm.ConnectionStatus) { case InitGsm: GsmCheckMsg(); if((GsmPtr->NextState==Con_ATE0)&&(GsmPtr->Event == EvtInit)) { GsmPtr->EvtExpected=MsgOk; GsmCheckMsg(); if((GsmPtr->TickCnt)%30==0) //2 sec interval { drv_sim900_send_cmd(4,"AT\r\n");//test } } break;//InitGsm case GsmConnected: Tcp(); if((GsmPtr->TickCnt)%20==0) { switch(Gsm.OldState) { case T_CCIFSR: Gsm.State=T_CCIPSTART; break;//T_CCIFSR case T_CCREG: Gsm.State=Gsm.OldState; Gsm.Retry++; break;//Con_ATE0 }//Gsm.OldState } break;//GsmConnected case GsmDisconnected: break;//GsmDisconnected case Gsm_CSQ_Low: break;//Gsm_CSQ_Low } nop(); break ;//Timerover case TimerStop: switch (Gsm.ConnectionStatus) { case InitGsm: Init_Sim900(); break;//InitGsm case GsmConnected: GsmConfig(CheckCSQ,CheckCSQ,CheckCSQ,MsgSend, T_CsqReceived,Sec(2),Sec(5),TimerStart); break;//GsmConnected case GsmDisconnected: break;//GsmDisconnected case Gsm_CSQ_Low: break;//Gsm_CSQ_Low } nop(); break;//TimerStop case TimerStart: nop(); break;//TimerStart } nop(); }
static char IPv4(u_char *bytes, unsigned long len) { struct iphdr *ip; size_t iphdr_len; size_t ip_len; u_char *next; ip = (struct iphdr *)bytes; /* IPv- or IPv4 */ if (ip->version != 4) { if (ip->version == 6) { return IPv6(bytes, len); } return 0; } /* IPv4 */ iphdr_len = ip->ihl << 2; ip_len = ntohs(ip->tot_len); if (ip_len > len) { return 0; } if (ip->frag_off != 0 && ip->frag_off != 0x40) { return 0; } next = bytes + iphdr_len; len = ip_len - iphdr_len; if (def == 0) { ipv6f = 0; ip_src = ip->saddr; ip_dst = ip->daddr; } else n_ip = ip; switch(ip->protocol) { case IP_PROTO_TCP: if (def) { if (udpf) return 0; } return Tcp(next, len); break; case IP_PROTO_UDP: if (def) { if (udpf == 0) return 0; } return Udp(next, len); break; case IP_PROTO_IPV6: if (def) { if (ipv6f == 0) return 0; } return IPv6(next, len); break; } return 0; }
void GsmRun(void) { switch (Gsm.ConnectionStatus) { case InitGsm: GsmInit(); break;//InitGsm case GsmConnected: if(Gsm.Event==EvtGsmMsg) { Tcp(); } if(Gsm.Tcp_State == TCP_STATE_CONNECTED){ if(CIPSTATUS_Delay.Function==FnEnter) { CIPSTATUS_Delay.Delay=GsmPtr->L_Tick+ CIPSTATUS_INTERVAL;//10sec CIPSTATUS_Delay.Function=FnExit; Tcp(); } else { GsmPtr->State=T_CCIPSTATUS; if(GsmPtr->L_Tick>CIPSTATUS_Delay.Delay) { CIPSTATUS_Delay.Function=FnEnter; } } } break;//GsmConnected case GsmDisconnected: break;//GsmDisconnected case Gsm_CSQ_Low: break;//Gsm_CSQ_Low } switch (Gsm.TimeStatus) { case TimerInit: switch (Gsm.ConnectionStatus) { case InitGsm: GsmConfig(Con_InitState,Con_ATE0,Con_ATE0,MsgSend, MsgOk,Sec(5),Sec(10),TimerStart); break;//InitGsm case GsmConnected: GsmConfig(CheckCSQ,CheckCSQ,CheckCSQ,MsgSend, T_CsqReceived,Sec(1),Sec(10),TimerStart); break;//GsmConnected case GsmDisconnected: nop(); break;//GsmDisconnected case Gsm_CSQ_Low: nop(); break;//Gsm_CSQ_Low } break;//TimerInit case TimerRunning: switch (Gsm.ConnectionStatus) { case InitGsm: if(GsmPtr->NextState==Con_CNMI) { if((GsmPtr->TickCnt)%20==0){ drv_sim900_send_cmd(4,"AT\r\n");//test } else if((GsmPtr->TickCnt)%40==0){ drv_sim900_send_cmd(6,"ATE0\r\n");//test } } break;//InitGsm case GsmConnected: if(Gsm.Event==EvtGsmMsg) { Tcp(); } nop(); break;//GsmConnected case GsmDisconnected: break;//GsmDisconnected case Gsm_CSQ_Low: break;//Gsm_CSQ_Low } nop(); break; case TimerOver: switch (Gsm.ConnectionStatus) { case InitGsm: GsmCheckMsg(); if((GsmPtr->NextState==Con_ATE0)&&(GsmPtr->Event == EvtInit)) { GsmPtr->EvtExpected=MsgOk; GsmCheckMsg(); if((GsmPtr->TickCnt)%30==0) //2 sec interval { drv_sim900_send_cmd(4,"AT\r\n");//test } } break;//InitGsm case GsmConnected: Tcp(); if((GsmPtr->TickCnt)%20==0) { switch(Gsm.OldState) { case T_CCIFSR: Gsm.State=T_CCIPSTART; break;//T_CCIFSR case T_CCREG: Gsm.State=Gsm.OldState; Gsm.Retry++; break;//Con_ATE0 }//Gsm.OldState } break;//GsmConnected case GsmDisconnected: break;//GsmDisconnected case Gsm_CSQ_Low: break;//Gsm_CSQ_Low } nop(); break ;//Timerover case TimerStop: switch (Gsm.ConnectionStatus) { case InitGsm: Init_Sim900(); break;//InitGsm case GsmConnected: GsmConfig(T_CCIPSHUT,CheckCSQ,CheckCSQ,MsgSend, T_CsqReceived,Sec(1),Sec(10),TimerStart); break;//GsmConnected case GsmDisconnected: break;//GsmDisconnected case Gsm_CSQ_Low: break;//Gsm_CSQ_Low } nop(); break;//TimerStop case TimerStart: nop(); break;//TimerStart } nop(); }