/*---------------------------------------------------------------------------*/ int main(void) { uint16_t plen; init_serial(); init_mac(mymac); init_udp_or_www_server(mymac,myip); enc28j60Init(mymac); enc28j60PhyWrite(PHLCON,0x476); enc28j60EnableBroadcast(); xprintf(PSTR("Hello World!\r\n")); /* main loop */ while(1) { /* poll hardware ethernet buffer */ plen = enc28j60PacketReceive(BUFFER_SIZE,buf); /* any new message? */ if(plen > 0) { checkBootloaderCondition(buf); } } return 0; }
int main(void) { uint8_t i; struct light_packet lp; uint8_t src; uint8_t taille; unsigned char datas[16]; uart_init(); init_mac(); _delay_ms(10000); while (1) { if( recv(&src, &taille, datas) > 0) { for (i = 0 ; i < taille ; i++) { uart_send_char(datas[i]); } } print("\r\n"); } return 0; }
int setinit(int argc, char** argv) { int i, cmdRet=-1; int intValue=0, intValue1=0; char cmdBuffer[100], tmpBuff[512]; char *token=NULL, *savestr1=NULL; char tmp_args[16]; char Ip[32], Mask[32], Gateway[32]; char strPID[32]; int pid = 0; int wlan_support = 0; int index; int old_wlan_idx; int repeater_enable1=0; int repeater_enable2=0; int reinit=1; #ifdef AEI_WECB if( (!strcmp(argv[2], "aei")) && (!strcmp(argv[3], "mac"))) { #ifdef AEI_CTL_BRIDGE init_mac(); #endif up_mib_value(); RunSystemCmd(REINIT_FILE, "echo", "1", NULL_STR); RunSystemCmd("/var/sys_op", "echo", "1", NULL_STR); RunSystemCmd("/proc/sys/net/ipv4/ip_forward", "echo", "0", NULL_STR); RunSystemCmd(PROC_BR_IGMPPROXY, "echo", "0", NULL_STR); /*cleanup hardware tables*/ RunSystemCmd(HW_NAT_FILE, "echo", "2", NULL_STR); /*bridge mode*/ RunSystemCmd("/proc/br_wlanblock", "echo","0",NULL_STR); RunSystemCmd(NULL_FILE, "iptables", "-F", NULL_STR); RunSystemCmd(NULL_FILE, "iptables", "-F", "-t", "nat", NULL_STR); RunSystemCmd(NULL_FILE, "iptables", "-A", "INPUT", "-j", "ACCEPT", NULL_STR); RunSystemCmd(NULL_FILE, "rm", "-f", "/var/eth1_ip", NULL_STR); RunSystemCmd(NULL_FILE, "rm", "-f", "/var/ntp_run", NULL_STR); //set kthreadd high priority for performance RunSystemCmd(NULL_FILE, "renice -20 2", NULL_STR); //set ksoftirqd high priority for performance RunSystemCmd(NULL_FILE, "renice -20 3", NULL_STR); //set boa high priority if(isFileExist(WEBS_PID_FILE)){ pid=getPid_fromFile(WEBS_PID_FILE); if(pid != 0){ sprintf(strPID, "%d", pid); RunSystemCmd(NULL_FILE, "renice", "-20", strPID, NULL_STR); } } RunSystemCmd("/proc/custom_Passthru", "echo", (intValue & 0x1)?"1":"0", NULL_STR); /*enable igmp snooping*/ /*igmp snooping is independent with igmp proxy*/ #ifdef AEI_IGMPV3 RunSystemCmd(PROC_BR_IGMPVERSION, "echo", "3", NULL_STR); #else RunSystemCmd(PROC_BR_IGMPVERSION, "echo", "2", NULL_STR); #endif RunSystemCmd(PROC_BR_IGMPSNOOP, "echo", "1", NULL_STR); #if defined(AEI_DISABLE_IGMP_QUERY) || defined(AEI_CONTROL_IGMP_QUERY) RunSystemCmd(PROC_BR_IGMPQUERY, "echo", "0", NULL_STR); #else RunSystemCmd(PROC_BR_IGMPQUERY, "echo", "1", NULL_STR); #endif RunSystemCmd(PROC_BR_MLDSNOOP, "echo", "1", NULL_STR); RunSystemCmd(PROC_BR_MLDQUERY, "echo", "1", NULL_STR); /*increase routing cache rebuild count from 4 to 2048*/ RunSystemCmd(RT_CACHE_REBUILD_COUNT, "echo", "2048", NULL_STR); return 0; } #endif //step 1: 802.1x client support #ifdef CONFIG_RTL_802_1X_CLIENT_SUPPORT if((isFileExist(RS_USER_CERT_5G)==0) && (isFileExist(RS_ROOT_CERT_5G)==0) && (isFileExist(RS_USER_CERT_2G)==0) && (isFileExist(RS_ROOT_CERT_2G)==0)){ RunSystemCmd(NULL_FILE, "rsCert","-rd", NULL_STR); } #endif printf("Init Start...\n"); //step 2 num_wlan_interface=get_interfaces_list(5, "wlan", NULL, wlan_interface, sizeof(wlan_interface)); num_wlan_virtual_interface=get_interfaces_list(9, "wlan", "-va", wlan_virtual_interface, sizeof(wlan_virtual_interface)); /*currently, we just support init gw/ap all */ // clean_process(BRIDGE_MODE,0,1, 1, "br0", wlan_interface, "eth1"); RunSystemCmd(HW_NAT_FILE, "echo", "2", NULL_STR); /*bridge mode*/ RunSystemCmd(NULL_FILE, "killall", "-9", "reload", NULL_STR); /*init wlan interface*/ //ifconfig rootap down && flash set_mib for(i=0;i<NUM_WLAN_INTERFACE;i++) { int wlan_disable = 1; unsigned char wlan_name[10]; memset(wlan_name,0x00,sizeof(wlan_name)); int j; for(j=0; j<NUM_VWLAN; j++){ sprintf(wlan_name, "wlan%d-va%d",i, j); RunSystemCmd(NULL_FILE, "ifconfig", wlan_name, "down", NULL_STR); } sprintf(wlan_name, "wlan%d",i); apmib_save_wlanIdx(); if(SetWlan_idx(wlan_name)) { apmib_get( MIB_WLAN_WLAN_DISABLED, (void *)&wlan_disable); if(wlan_disable == 1) { RunSystemCmd(NULL_FILE, "ifconfig", wlan_name, "down", NULL_STR); RunSystemCmd(NULL_FILE, "iwpriv", wlan_name, "radio_off", NULL_STR); } else { RunSystemCmd(NULL_FILE, "ifconfig", wlan_name, "down", NULL_STR); cmdRet=RunSystemCmd(NULL_FILE, "flash", "set_mib", wlan_name, NULL_STR); if(cmdRet != 0) { printf("init %s failed!\n", wlan_name); continue; } } } apmib_recov_wlanIdx(); } //ifconfig vap down && flash set_mib if(wlan_interface[0]){ if(wlan_virtual_interface[0]){ token=NULL; savestr1=NULL; sprintf(tmpBuff, "%s", wlan_virtual_interface); token = strtok_r(tmpBuff," ", &savestr1); do{ if (token == NULL){ break; }else{ RunSystemCmd(NULL_FILE, "ifconfig", token, "down", NULL_STR); RunSystemCmd(NULL_FILE, "flash", "set_mib", token, NULL_STR);/*set virtual wlan iface*/ } token = strtok_r(NULL, " ", &savestr1); }while(token !=NULL); } } /////////////////////////////////////////////////////////// //set_br_interface(tmpBuff); sprintf(tmpBuff, "%s %s", wlan_interface, wlan_virtual_interface); setbridge(tmpBuff);//ifconfig wlanx up or not sprintf(br_interface, "%s", "br0"); start_wlanapp(1); system("reload -k /var/wlsch.conf &"); #if defined(CONFIG_IPV6) set_ipv6(BRIDGE_MODE); #endif return 0; }
int main(void) { static uint8_t buffer[BufferSize + 1]; int8_t i; uint8_t message[4] = { 0, 0, CID, P2CID }; uint16_t received; snesIO port0 = 0xffff, port1 = 0xffff; // Initialise basic I/O. initLed(); initInput(); initOutput(); // Switched mode: B + Y. port0 = recvInput(); if (port0 == 0xfffc) { switchedMode = Enabled; ledSignal(5); } ledOnRed(); // Initialise network interface. enc28j60Init(mymac); _delay_ms(100); // Magjack leds configuration, see enc28j60 datasheet, page 11 // LEDB=yellow LEDA=green // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); enc28j60PhyWrite(PHLCON, 0x476); _delay_ms(100); // Get the initial IP via DHCP and configure network. init_mac(mymac); while (i != 1) { received = enc28j60PacketReceive(BufferSize, buffer); buffer[BufferSize] = '\0'; i = packetloop_dhcp_initial_ip_assignment(buffer, received, mymac[5]); } dhcp_get_my_ip(myip, netmask, gwip); client_ifconfig(myip, netmask); // Resolve MAC address from server IP. if (route_via_gw(serverip)) // Must be routed via gateway. get_mac_with_arp(gwip, TransNumGwmac, &arpresolverResultCallback); else // Server is on local network. get_mac_with_arp(serverip, TransNumGwmac, &arpresolverResultCallback); while (get_mac_with_arp_wait()) { received = enc28j60PacketReceive(BufferSize, buffer); // Call packetloop to process ARP reply. packetloop_arp_icmp_tcp(buffer, received); } // Lookup DNS of the server hostname. while (dnslkup_haveanswer() != 1) { uint16_t tmp; received = enc28j60PacketReceive(BufferSize, buffer); tmp = packetloop_arp_icmp_tcp(buffer, received); if (received == 0) { if (!enc28j60linkup()) continue; dnslkup_request(buffer, ServerVHost, gwmac); _delay_ms(100); continue; } if (tmp == 0) udp_client_check_for_dns_answer(buffer, received); } dnslkup_get_ip(serverip); ledOnGreen(); // Connected. while (1) { // Main loop start. received = enc28j60PacketReceive(BufferSize, buffer); // Software reset: L + R + Select + Start. if (port0 == 0xf3f3) reset(); // Do something while no packet in queue. if (received == 0) { port0 = recvInput(); // Prepare message and send it to the server. for (i = 0; i < 8; i++) { // Lo-Byte. char *c = message; *c = port0 & (1 << i) ? *c | (1 << i) : *c & ~(1 << i); } for (i = 0; i < 8; i++) { // Hi-Byte. char *c = message + 1; *c = port0 & (1 << i + 8) ? *c | (1 << i) : *c & ~(1 << i); } send_udp(buffer, message, sizeof(message), 57351, serverip, 57350, gwmac); // Send controller data to SNES. if (switchedMode == Disabled) sendOutput(port0, port1); else sendOutput(port1, port0); continue; } // Answer to ARP requests. if (eth_type_is_arp_and_my_ip(buffer, received)) { make_arp_answer_from_request(buffer, received); continue; } // Check if IP packets (ICMP or UDP) are for us. if (eth_type_is_ip_and_my_ip(buffer, received) == 0) continue; // Answer ping with pong. if ( buffer[IP_PROTO_P] == IP_PROTO_ICMP_V && buffer[ICMP_TYPE_P] == ICMP_TYPE_ECHOREQUEST_V) { make_echo_reply_from_request(buffer, received); continue; } // Listen for UDP packets on port 57351 (0xe007) and process // received data. if ( buffer[IP_PROTO_P] == IP_PROTO_UDP_V && buffer[UDP_DST_PORT_H_P] == 0xe0 && buffer[UDP_DST_PORT_L_P] == 0x07) { for (i = 0; i < 8; i++) { uint16_t *c = &port1; *c = buffer[UDP_DATA_P] & (1 << i) ? *c | (1 << i) : *c & ~(1 << i); } for (i = 0; i < 8; i++) { uint16_t *c = &port1; *c = buffer[UDP_DATA_P + 1] & (1 << i) ? *c | (1 << i + 8) : *c & ~(1 << i + 8); } } } // Main loop end. return (0); }
/*---------------------------------------------------------------------------*/ int main(void) { uint16_t rval; /* init hardware layer */ init_hci(); timer1_init(); init_serial(); sei(); led1_high(); led2_high(); /* init protothreads */ PT_INIT(&blink_pt); PT_INIT(&nrf24_pt); PT_INIT(&www_client_pt); PT_INIT(&www_server_pt); PT_INIT(&udp_server_pt); PT_INIT(&coap_server_pt); PT_INIT(&temperature_pt); PT_INIT(&udp_broadcast_pt); /* greeting message */ dbg(PSTR("> Hello World!\r\n")); /* init the ethernet chip */ enc28j60Init(mymac); enc28j60PhyWrite(PHLCON,0x476); /* get automatic IP */ rval=0; init_mac(mymac); while(rval==0) { plen=enc28j60PacketReceive(BUFFER_SIZE, buf); rval=packetloop_dhcp_initial_ip_assignment(buf,plen,mymac[5]); } dhcp_get_my_ip(myip,netmask,gwip); client_ifconfig(myip,netmask); /* learn the MAC address of the gateway */ get_mac_with_arp(gwip,0,&arpresolver_result_callback); while(get_mac_with_arp_wait()) { plen=enc28j60PacketReceive(BUFFER_SIZE, buf); packetloop_arp_icmp_tcp(buf,plen); } /* set WWW server port */ www_server_port(MYWWWPORT); dbg(PSTR("> System is ready.\r\n")); led1_low(); led2_low(); /* main loop */ while(1) { if(enc28j60linkup()) { /* poll hardware ethernet buffer */ plen = enc28j60PacketReceive(BUFFER_SIZE,buf); /* terminate the buffer */ buf[BUFFER_SIZE]='\0'; /* handle DHCP messages if neccessary */ plen = packetloop_dhcp_renewhandler(buf,plen); /* handle and analyse the packet slightly */ dat_p = packetloop_arp_icmp_tcp(buf,plen); if( dat_p == 0) { udp_client_check_for_dns_answer(buf,plen); } new_packet = 0xFF; PT_SCHEDULE(blink_thread(&blink_pt)); PT_SCHEDULE(nrf24_thread(&nrf24_pt)); PT_SCHEDULE(www_server_thread(&www_server_pt)); PT_SCHEDULE(udp_server_thread(&udp_server_pt)); PT_SCHEDULE(www_client_thread(&www_client_pt)); PT_SCHEDULE(coap_server_thread(&coap_server_pt)); PT_SCHEDULE(temperature_thread(&temperature_pt)); PT_SCHEDULE(udp_broadcast_thread(&udp_broadcast_pt)); } } return 0; }