void act_nset_a(int8 mode, uint8 *ip, uint8 *sn, uint8 *gw, uint8 *dns1, uint8 *dns2) { wiz_NetInfo ni = {0,}; if(ip) memcpy(ni.IP, ip, 4); if(sn) memcpy(ni.SN, sn, 4); if(gw) memcpy(ni.GW, gw, 4); if(dns1) memcpy(ni.DNS, dns1, 4); if(dns2) { MAKE_TCMD_DIGIT(atci.tcmd.arg1, 6); CMD_RESP_RET(RET_NOT_ALLOWED, VAL_NONE); } if(mode == 'S') { if(dhcp_static_mode(&ni) != RET_OK) { dhcp_set_storage(&ni); SetNetInfo(&ni); } } else if(mode == 'D') { dhcp_set_storage(&ni); dhcp_alarm_start(NULL); } else { dhcp_set_storage(&ni); GetNetInfo(&ni); if(ni.DHCP == NETINFO_STATIC) SetNetInfo(&ni); } CMD_RESP_RET(RET_OK, VAL_NONE); }
/** * Change DHCP mode to Static. * Even though DHCP was enabled, it can be changed to Static mode through this function * * @param net The addresses you want to set as static addresses * - NULL parameter or NULL member variable will be ignored and internal storage addresses will be used * \n and these address will be returned in this net parameter (if not NULL) */ void dhcp_static_mode(wiz_NetInfo *net) { di.action = DHCP_ACT_NONE; SET_STATE(DHCP_STATE_INIT); if(net != NULL) { if(net->ip[0]!=0 || net->ip[1]!=0 || net->ip[2]!=0 || net->ip[3]!=0) memcpy(storage.ip, net->ip, 4); else memcpy(net->ip, storage.ip, 4); if(net->sn[0]!=0 || net->sn[1]!=0 || net->sn[2]!=0 || net->sn[3]!=0) memcpy(storage.sn, net->sn, 4); else memcpy(net->sn, storage.sn, 4); if(net->gw[0]!=0 || net->gw[1]!=0 || net->gw[2]!=0 || net->gw[3]!=0) memcpy(storage.gw, net->gw, 4); else memcpy(net->gw, storage.gw, 4); if(net->dns[0]!=0 || net->dns[1]!=0 || net->dns[2]!=0 || net->dns[3]!=0) memcpy(storage.dns, net->dns, 4); else memcpy(net->dns, storage.dns, 4); net->dhcp = NETINFO_STATIC; SetNetInfo(net); } else { SetNetInfo(&storage); memset(&workinfo, 0, sizeof(workinfo)); workinfo.dhcp = NETINFO_STATIC; SetNetInfo(&workinfo); } if(dhcp_alarm) alarm_del(dhcp_alarm_cb, -1); //send_checker_NB(); }
/** * Initialize DHCP module. * This should be called just one time at first time * * @param sock Socket number to use * @param ip_update_hook Callback function for IP-update hooking * @param ip_conflict_hook Callback function for IP-conflict hooking (Not implemented yet) * @param def Default Address to set * @return RET_OK: Success * @return RET_NOK: Error */ int8 dhcp_init(uint8 sock, void_func ip_update_hook, void_func ip_conflict_hook, wiz_NetInfo *def) { if(sock >= TOTAL_SOCK_NUM) { ERRA("wrong socket number(%d)", sock); return RET_NOK; } #ifdef DHCP_AUTO dhcp_alarm = TRUE; #endif #ifdef DHCP_ASYNC dhcp_async = TRUE; #endif memset(&di, 0, sizeof(di)); memcpy(&storage, def, sizeof(storage)); memset(&workinfo, 0, sizeof(workinfo)); memcpy(workinfo.mac, storage.mac, 6); workinfo.dhcp = NETINFO_STATIC; SetNetInfo(&workinfo); di.xid = 0x12345678; di.sock = sock; if(ip_update_hook) di.ip_update = ip_update_hook; if(ip_conflict_hook) di.ip_conflict = ip_conflict_hook; // ToDo: Remove setting zero IP & SN (set at start func) return RET_OK; }
int8 dhcp_init(uint8 sock, pFunc ip_update_hook, pFunc ip_conflict_hook, wiz_NetInfo *def) { if(sock >= TOTAL_SOCK_NUM) { ERRA("wrong socket number(%d)", sock); return RET_NOK; } #ifdef DHCP_ALARM dhcp_alarm = TRUE; #endif #ifdef DHCP_ASYNC dhcp_async = TRUE; #endif memset(&di, 0, sizeof(di)); memcpy(&storage, def, sizeof(storage)); memset(&workinfo, 0, sizeof(workinfo)); memcpy(workinfo.Mac, storage.Mac, 6); SetNetInfo(&workinfo); di.xid = 0x12345678; di.sock = sock; if(ip_update_hook) di.ip_update = ip_update_hook; if(ip_conflict_hook) di.ip_conflict = ip_conflict_hook; IINCHIP_WRITE(WIZC_SIPR0, 0); IINCHIP_WRITE(WIZC_SIPR1, 0); IINCHIP_WRITE(WIZC_SIPR2, 0); IINCHIP_WRITE(WIZC_SIPR3, 0); return RET_OK; }
void InitNetInfo(void) { httpclient_NetInfo.Mac[0] = 0x00; httpclient_NetInfo.Mac[1] = 0x08; httpclient_NetInfo.Mac[2] = 0xDC; httpclient_NetInfo.Mac[3] = 0x01; httpclient_NetInfo.Mac[4] = 0x02; httpclient_NetInfo.Mac[5] = 0x03; httpclient_NetInfo.Gateway[0] = 222; httpclient_NetInfo.Gateway[1] = 98; httpclient_NetInfo.Gateway[2] = 173; httpclient_NetInfo.Gateway[3] = 254; httpclient_NetInfo.IP[0] = 222; httpclient_NetInfo.IP[1] = 98; httpclient_NetInfo.IP[2] = 173; httpclient_NetInfo.IP[3] = 224; httpclient_NetInfo.Subnet[0] = 255; httpclient_NetInfo.Subnet[1] = 255; httpclient_NetInfo.Subnet[2] = 255; httpclient_NetInfo.Subnet[3] = 192; SetNetInfo(&httpclient_NetInfo); }
/** * DHCP manual mode handler. * - Blocking Function * - Used only at DHCP manual mode (DHCP mode could be chosen at wizconfig.h file) * - DHCP_MANUAL mode does not need a loop structure, but if there is no loop structure, \n * you should handle renew & rebind with your own way, or just ignore renew & rebind action * * @param action The action you want to do. (@ref dhcp_action) * @param renew For returning renew time when DHCP be bound (NULL will be ignored) * @param rebind For returning rebind time when DHCP be bound (NULL will be ignored) * @return RET_OK: Success * @return RET_NOK: Error */ int8 dhcp_manual(dhcp_action action, uint32 *renew, uint32 *rebind) // blocking function { dhcp_state curstt = di.state; if(dhcp_alarm == TRUE) return RET_NOK; while(curstt != DHCP_STATE_INIT && curstt != DHCP_STATE_BOUND) { dhcp_run(); curstt = di.state; } if(curstt == DHCP_STATE_INIT) { di.action = DHCP_ACT_START; memset(&workinfo, 0, sizeof(workinfo)); workinfo.dhcp = NETINFO_DHCP; SetNetInfo(&workinfo); // ToDo: Set zero IP & SN do { dhcp_run(); curstt = di.state; } while((curstt != DHCP_STATE_INIT || di.action != DHCP_ACT_START) && curstt != DHCP_STATE_BOUND); if(curstt != DHCP_STATE_BOUND) return RET_NOK; if(renew) *renew = di.renew_time; if(rebind) *rebind = di.rebind_time; } else if(curstt == DHCP_STATE_BOUND) { if(action == DHCP_ACT_START) { if(renew) *renew = 0; if(rebind) *rebind = 0; return RET_OK; } else if(action == DHCP_ACT_RENEW) { // renew SET_STATE(DHCP_STATE_SELECTING); di.action = DHCP_ACT_RENEW; di.xid++; } else if(action == DHCP_ACT_REBIND) { // rebind SET_STATE(DHCP_STATE_SELECTING); di.action = DHCP_ACT_REBIND; di.xid++; } else { ERRA("wrong action(%d)", action); return RET_NOK; } curstt = di.state; while(curstt != DHCP_STATE_INIT && curstt != DHCP_STATE_BOUND) { dhcp_run(); curstt = di.state; } if(curstt != DHCP_STATE_BOUND) return RET_NOK; if(renew) *renew = di.renew_time; if(rebind) *rebind = di.rebind_time; } return RET_OK; }
int8 dhcp_manual(int8 action, uint8 *saved_ip, uint32 *renew, uint32 *rebind) // blocking function { int8 curstt = dhcp_get_state(); if(dhcp_alarm == TRUE) return RET_NOK; while(curstt != DHCP_STATE_INIT && curstt != DHCP_STATE_BOUND) { dhcp_run(); curstt = dhcp_get_state(); } if(curstt == DHCP_STATE_INIT) { di.action = DHCP_ACT_START; memset(&workinfo, 0, sizeof(workinfo)); if(saved_ip) memcpy(workinfo.IP, saved_ip, 4); workinfo.DHCP = NETINFO_DHCP_BUSY; SetNetInfo(&workinfo); do { dhcp_run(); curstt = dhcp_get_state(); } while((curstt != DHCP_STATE_INIT || workinfo.DHCP == NETINFO_DHCP_BUSY) && curstt != DHCP_STATE_BOUND); if(curstt != DHCP_STATE_BOUND) return RET_NOK; if(renew) *renew = di.renew_time; if(rebind) *rebind = di.rebind_time; } else if(curstt == DHCP_STATE_BOUND) { if(action == DHCP_ACT_START) { if(renew) *renew = 0; if(rebind) *rebind = 0; return RET_OK; } else if(action == DHCP_ACT_RENEW) { // renew SET_STATE(DHCP_STATE_SELECTING); di.action = DHCP_ACT_RENEW; di.xid++; } else if(action == DHCP_ACT_REBIND) { // rebind SET_STATE(DHCP_STATE_SELECTING); di.action = DHCP_ACT_REBIND; di.xid++; } else { ERRA("wrong action(%d)", action); return RET_NOK; } curstt = dhcp_get_state(); while(curstt != DHCP_STATE_INIT && curstt != DHCP_STATE_BOUND) { dhcp_run(); curstt = dhcp_get_state(); } if(curstt != DHCP_STATE_BOUND) return RET_NOK; if(renew) *renew = di.renew_time; if(rebind) *rebind = di.rebind_time; } return RET_OK; }
void act_nmac_a(uint8 *mac) { #if 1 // Enable MAC change wiz_NetInfo ni = {0,}; memcpy(ni.Mac, mac, 6); SetNetInfo(&ni); CMD_RESP_RET(RET_OK, VAL_NONE); #else CMD_RESP_RET(RET_NOT_ALLOWED, VAL_NONE); #endif }
static void dhcp_fail(void) { LOG("DHCP Fail - set temp addr"); di.action = DHCP_ACT_NONE; SET_STATE(DHCP_STATE_FAILED); memcpy(&workinfo, &storage, sizeof(storage)); memset(workinfo.mac, 0, 6); SetNetInfo(&workinfo); network_disp(NULL); if(dhcp_alarm) alarm_set(DHCP_START_RETRY_DELAY, dhcp_alarm_cb, 0); //send_checker_NB(); }
/** * DHCP Auto mode (alarm mode) start function. * - Used for DHCP start action at Auto mode \n * Auto mode can be selected at @ref wizconfig.h file. \n * (set USE_DHCP to VAL_ENABLE, and uncomment DHCP_AUTO define) \n * and in the main loop, @ref alarm_run should be called continuously. * - At Static mode, it can be changed to DHCP mode through this function */ void dhcp_auto_start(void) { DBG("DHCP Start"); SET_STATE(DHCP_STATE_INIT); di.action = DHCP_ACT_START; memset(&workinfo, 0, sizeof(workinfo)); workinfo.dhcp = NETINFO_DHCP; SetNetInfo(&workinfo); // ToDo: Set zero IP & SN if(dhcp_alarm) alarm_set(10, dhcp_alarm_cb, 0); }
int8 dhcp_alarm_start(uint8 *saved_ip) { GetNetInfo(&workinfo); if(workinfo.DHCP > NETINFO_STATIC) { DBGA("Already DHCP Mode(%d)", workinfo.DHCP); return RET_NOK; } else DBG("DHCP Start"); SET_STATE(DHCP_STATE_INIT); di.action = DHCP_ACT_START; memset(&workinfo, 0, sizeof(workinfo)); if(saved_ip) memcpy(workinfo.IP, saved_ip, 4); workinfo.DHCP = NETINFO_DHCP_BUSY; SetNetInfo(&workinfo); if(dhcp_alarm) alarm_set(10, dhcp_alarm_cb, 0); return RET_OK; }
int8 dhcp_static_mode(wiz_NetInfo *net) { wiz_NetInfo cur; if(net == NULL) { DBG("NULL arg"); return RET_NOK; } GetNetInfo(&cur); if(cur.DHCP == NETINFO_STATIC) { DBG("Already Static Mode"); return RET_NOK; } di.action = DHCP_ACT_NONE; SET_STATE(DHCP_STATE_INIT); if(net->IP[0]!=0 || net->IP[1]!=0 || net->IP[2]!=0 || net->IP[3]!=0) memcpy(storage.IP, net->IP, 4); else memcpy(net->IP, storage.IP, 4); if(net->SN[0]!=0 || net->SN[1]!=0 || net->SN[2]!=0 || net->SN[3]!=0) memcpy(storage.SN, net->SN, 4); else memcpy(net->SN, storage.SN, 4); if(net->GW[0]!=0 || net->GW[1]!=0 || net->GW[2]!=0 || net->GW[3]!=0) memcpy(storage.GW, net->GW, 4); else memcpy(net->GW, storage.GW, 4); if(net->DNS[0]!=0 || net->DNS[1]!=0 || net->DNS[2]!=0 || net->DNS[3]!=0) memcpy(storage.DNS, net->DNS, 4); else memcpy(net->DNS, storage.DNS, 4); net->DHCP = NETINFO_STATIC; SetNetInfo(net); if(dhcp_alarm) alarm_del(dhcp_alarm_cb, -1); //send_checker_NB(); return RET_OK; }
void WIZ_Config(void) { uint8 i; wiz_NetInfo netinfo; Reset_W5200(); wizInit(); for(i=0; i<4; i++){ netinfo.Mac[i] = Mac[i]; printf("MAC[%d]: 0x%2x\r\n", i, Mac[i]); netinfo.IP[i] = IP[i]; netinfo.Subnet[i] = Subnet[i]; netinfo.Gateway[i] = Gateway[i]; netinfo.DNSServerIP[i] = DNSServerIP[i]; } netinfo.Mac[i] = Mac[i]; printf("MAC[%d]: 0x%2x\r\n", i, Mac[i]); i++; netinfo.Mac[i] = Mac[i]; printf("MAC[%d]: 0x%2x\r\n", i, Mac[i]); SetNetInfo(&netinfo); printf("\r\n--------------------------------------- \r\n"); printf("W5200E01-M3 \r\n"); printf("Network Configuration Information \r\n"); printf("--------------------------------------- "); GetNetInfo(&netinfo); printf("\r\nMAC : %.2X.%.2X.%.2X.%.2X.%.2X.%.2X", netinfo.Mac[0],netinfo.Mac[1],netinfo.Mac[2],netinfo.Mac[3],netinfo.Mac[4],netinfo.Mac[5]); printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]); printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]); printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]); printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]); }
static void dhcp_run(void) { static bool udp_open_fail = FALSE; if(di.state == DHCP_STATE_INIT && di.action != DHCP_ACT_START) { DBG("wrong attempt"); return; } else if(GetUDPSocketStatus(di.sock) == SOCKSTAT_CLOSED) { if(udp_open_fail == TRUE && !IS_TIME_PASSED(dhcp_run_tick, DHCP_RETRY_DELAY)) goto RET_ALARM; ClsNetInfo(NI_IP_ADDR); ClsNetInfo(NI_SN_MASK); ClsNetInfo(NI_GW_ADDR); ClsNetInfo(NI_DNS_ADDR); if(UDPOpen(di.sock, DHCP_CLIENT_PORT) == RET_OK) { if(dhcp_async) sockwatch_open(di.sock, dhcp_async_cb); udp_open_fail = FALSE; dhcp_run_tick = wizpf_get_systick(); dhcp_run_cnt = 0; } else { ERR("UDPOpen fail"); udp_open_fail = TRUE; dhcp_run_tick = wizpf_get_systick(); goto RET_ALARM; } } switch(di.state) { case DHCP_STATE_INIT: if(dhcp_run_cnt==0 && !IS_TIME_PASSED(dhcp_run_tick, DHCP_OPEN_DELAY)) goto RET_ALARM; if(dhcp_run_cnt < DHCP_SEND_RETRY_COUNT) { dhcp_run_cnt++; if(send_discover() == RET_OK) { // Discover ok if(dhcp_async) { DBG("DHCP Discovery Send Async"); sockwatch_set(di.sock, WATCH_SOCK_UDP_SEND); return; // alarm set is not needed } else { DBG("DHCP Discovery Sent"); SET_STATE(DHCP_STATE_SEARCHING); dhcp_run_tick = wizpf_get_systick(); } } else { ERRA("DHCP Discovery SEND fail - (%d)times", dhcp_run_cnt); dhcp_run_tick = wizpf_get_systick(); } } else { ERRA("DHCP Discovery SEND fail - (%d)times", dhcp_run_cnt); dhcp_run_cnt = 0; UDPClose(di.sock); if(dhcp_async) sockwatch_close(di.sock); dhcp_fail(); return; // alarm set is not needed } break; case DHCP_STATE_SEARCHING: if(!IS_TIME_PASSED(dhcp_run_tick, DHCP_RETRY_DELAY)) { int8 ret = recv_handler(); if(ret == DHCP_MSG_OFFER) { SET_STATE(DHCP_STATE_SELECTING); dhcp_run_tick = wizpf_get_systick(); dhcp_run_cnt = 0; } else if(ret != RET_NOK) DBGCRTCA(TRUE, "recv wrong packet(%d)", ret); } else { ERRA("DHCP Offer RECV fail - for (%d)msec", DHCP_RETRY_DELAY); SET_STATE(DHCP_STATE_INIT); dhcp_run_tick = wizpf_get_systick(); } break; case DHCP_STATE_SELECTING: if(dhcp_run_cnt < DHCP_SEND_RETRY_COUNT) { dhcp_run_cnt++; if(send_request() == RET_OK) { // Request ok if(dhcp_async) { DBG("DHCP Request Send Async"); sockwatch_set(di.sock, WATCH_SOCK_UDP_SEND); return; // alarm set is not needed } else { DBG("DHCP Request Sent"); SET_STATE(DHCP_STATE_REQUESTING); dhcp_run_tick = wizpf_get_systick(); } } else { ERRA("DHCP Request SEND fail - (%d)times", dhcp_run_cnt); dhcp_run_tick = wizpf_get_systick(); } } else { ERRA("DHCP Request SEND fail - (%d)times", dhcp_run_cnt); dhcp_run_cnt = 0; UDPClose(di.sock); if(dhcp_async) sockwatch_close(di.sock); dhcp_fail(); return; // alarm set is not needed } break; case DHCP_STATE_REQUESTING: if(!IS_TIME_PASSED(dhcp_run_tick, DHCP_RETRY_DELAY)) { int8 ret = recv_handler(); if(ret == DHCP_MSG_ACK) { // Recv ACK LOG("DHCP Success"); SET_STATE(DHCP_STATE_IP_CHECK); dhcp_run_tick = wizpf_get_systick(); dhcp_run_cnt = 0; } else if(ret == DHCP_MSG_NAK) { // Recv NAK if(di.action == DHCP_ACT_START) { SET_STATE(DHCP_STATE_INIT); dhcp_run_tick = wizpf_get_systick(); } else { SET_STATE(DHCP_STATE_BOUND); } dhcp_run_cnt = 0; } else if(ret != RET_NOK) DBGCRTCA(TRUE, "recv wrong packet(%d)", ret); } else { ERRA("DHCP ACK RECV fail - for (%d)msec", DHCP_RETRY_DELAY); if(di.action == DHCP_ACT_START) { SET_STATE(DHCP_STATE_INIT); dhcp_run_tick = wizpf_get_systick(); } else { SET_STATE(DHCP_STATE_BOUND); } } break; case DHCP_STATE_IP_CHECK: //if(send_checker() == RET_OK) { SET_STATE(DHCP_STATE_BOUND); SetNetInfo(&workinfo); if(di.ip_update) di.ip_update(); LOGA("DHCP ok - New IP (%d.%d.%d.%d)", workinfo.ip[0], workinfo.ip[1], workinfo.ip[2], workinfo.ip[3]); //} else { // SET_STATE(DHCP_STATE_INIT); // ERR("IP Addr conflicted - IP(%d.%d.%d.%d)", workinfo.ip[0], workinfo.ip[1], workinfo.ip[2], workinfo.ip[3]); // send_rel_dec(DHCP_MSG_DECLINE); // if(di.ip_conflict) (*di.ip_conflict)(); //} break; case DHCP_STATE_BOUND: di.action = DHCP_ACT_NONE; UDPClose(di.sock); if(dhcp_async) sockwatch_close(di.sock); return; // alarm set is not needed case DHCP_STATE_FAILED: return; // alarm set is not needed default: ERRA("wrong state(%d)", di.state); return; // alarm set is not needed } RET_ALARM: if(dhcp_alarm) alarm_set(10, dhcp_alarm_cb, 0); }
void WIZ_Config(void) { uint8 i; wiz_NetInfo netinfo; extern u_char GET_SN_MASK[4]; /**< Subnet mask received from the DHCP server */ extern u_char GET_GW_IP[4]; /**< Gateway ip address received from the DHCP server */ extern u_char GET_SIP[4]; /**< Local ip address received from the DHCP server */ Reset_W5200(); wizInit(); if(Enable_DHCP == OFF){ for(i=0; i<4; i++){ netinfo.Mac[i] = Mac[i]; netinfo.IP[i] = IP[i]; netinfo.Subnet[i] = Subnet[i]; netinfo.Gateway[i] = Gateway[i]; netinfo.DNSServerIP[i] = DNSServerIP[i]; } netinfo.Mac[i] = Mac[i]; i++; netinfo.Mac[i] = Mac[i]; } else{ for(i=0; i<6; i++){ SRC_MAC_ADDR[i] = Mac[i]; } printf("Delay for 2 Seconds..\r\n"); Delay_ms(2000); // Set DHCP init_dhcp_client(SOCK_DHCP, wizSWReset, wizSWReset); getIP_DHCPS(); for(i=0; i<4; i++){ netinfo.Mac[i] = SRC_MAC_ADDR[i]; netinfo.IP[i] = GET_SIP[i]; netinfo.Subnet[i] = GET_SN_MASK[i]; netinfo.Gateway[i] = GET_GW_IP[i]; netinfo.DNSServerIP[i] = GET_DNS_IP[i]; } netinfo.Mac[i] = SRC_MAC_ADDR[i]; i++; netinfo.Mac[i] = SRC_MAC_ADDR[i]; } SetNetInfo(&netinfo); printf("\r\n--------------------------------------- \r\n"); printf("W5200E01-M3 \r\n"); printf("Network Configuration Information \r\n"); printf("--------------------------------------- "); GetNetInfo(&netinfo); printf("\r\nMAC : %.2X.%.2X.%.2X.%.2X.%.2X.%.2X", netinfo.Mac[0],netinfo.Mac[1],netinfo.Mac[2],netinfo.Mac[3],netinfo.Mac[4],netinfo.Mac[5]); printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]); printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]); printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]); printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]); }
/******************************************************************************* * Function Name : Main_Menu * Description : Display/Manage a Menu on HyperTerminal Window * Input : None * Output : None * Return : None *******************************************************************************/ void Main_Menu(void) { static char choice[3]; static char subject[32], msg[256], sender[32], passwd[32], recipient[32], encodedText[256]; static bool bTreat; static u8 Sip[4]; static char key = 0; static wiz_NetInfo netinfo; while (1) { /* Display Menu on HyperTerminal Window */ bTreat = (bool)RESET ; SerialPutString("\r\n====================== STM32-Discovery ===================\r\n"); SerialPutString("This Application is basic example of UART interface with\r\n"); SerialPutString("Windows Hyper Terminal. \r\n"); SerialPutString("\r\n==========================================================\r\n"); SerialPutString(" APPLICATION MENU :\r\n"); SerialPutString("\r\n==========================================================\r\n\n"); SerialPutString(" 1 - Set LD1 on \r\n"); SerialPutString(" 2 - Set LD1 off \r\n"); SerialPutString(" 3 - Show network setting\r\n"); SerialPutString(" 4 - Set network setting\r\n"); SerialPutString(" 5 - Run TCP Loopback\r\n"); SerialPutString(" 6 - Run UDP Loopback\r\n"); SerialPutString(" 7 - DNS test\r\n"); SerialPutString(" 8 - BASE64 test\r\n"); SerialPutString(" 9 - Send Mail\r\n"); SerialPutString("Enter your choice : "); GetInputString(choice); /* Set LD1 on */ if (strcmp(choice,"1")== 0) { bTreat = (bool)SET; LED3_onoff(ON); LED4_onoff(ON); } /* Set LD1 off */ if ((strcmp(choice,"2") == 0)) { bTreat = (bool)SET; LED3_onoff(OFF); LED4_onoff(OFF); } if (strcmp(choice,"3") == 0) { bTreat = (bool)SET; GetNetInfo(&netinfo); printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]); printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]); printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]); printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]); } if (strcmp(choice,"4") == 0) { bTreat = (bool)SET; // IP address SerialPutString("\r\nIP address : "); GetInputString(msg); if(!VerifyIPAddress(msg, netinfo.IP)) { SerialPutString("\aInvalid."); } // Subnet mask SerialPutString("\r\nSubnet mask : "); GetInputString(msg); if(!VerifyIPAddress(msg, netinfo.Subnet)) { SerialPutString("\aInvalid."); } // gateway address SerialPutString("\r\nGateway address : "); GetInputString(msg); if(!VerifyIPAddress(msg, netinfo.Gateway)) { SerialPutString("\aInvalid."); } // DNS address SerialPutString("\r\nDNS address : "); GetInputString(msg); if(!VerifyIPAddress(msg, netinfo.DNSServerIP)) { SerialPutString("\aInvalid."); } printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]); printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]); printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]); printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]); SetNetInfo(&netinfo); } if (strcmp(choice,"5") == 0) { bTreat = (bool)SET; SerialPutString("\r\nRun TCP loopback"); printf("\r\nRun TCP loopback, port number [%d] is listened", (u16)TCP_LISTEN_PORT); SerialPutString("\r\nTo Exit, press [Q]"); while(1) { if ((SerialKeyPressed((char*)&key) == 1) && (key == 'Q')) { SerialPutString("\r\n Stop "); break; } loopback_tcps(7, (u16)TCP_LISTEN_PORT); } } if (strcmp(choice,"6") == 0) { bTreat = (bool)SET; SerialPutString("\r\nRun UDP loopback"); printf("\r\nRun UDP loopback, port number [%d] is listened", (u16)UDP_LISTEN_PORT); SerialPutString("\r\nTo Exit, press [Q]"); while(1) { if ((SerialKeyPressed((char*)&key) == 1) && (key == 'Q')) { SerialPutString("\r\n Stop "); break; } loopback_udp(7, (u16)UDP_LISTEN_PORT); } } if (strcmp(choice,"7")== 0) { bTreat = (bool)SET; SerialPutString("\r\nServer address : "); GetInputString(msg); SerialPutString("URL = "); SerialPutString(msg); if (dns_query(SOCK_DNS, (void *)msg, Sip) == 1) { printf("\r\nSIP : %d.%d.%d.%d", (u16)Sip[0],(u16)Sip[1],(u16)Sip[2],(u16)Sip[3]); }else { SerialPutString("\n\r DNS fail"); } } if (strcmp(choice,"8")== 0) { bTreat = (bool)SET; memset(encodedText, '\0', 256); SerialPutString("\r\n"); SerialPutString(" 1 - BASE64 Encode \r\n"); SerialPutString(" 2 - BASE64 Decode \r\n"); SerialPutString("Enter your choice : "); GetInputString(choice); if (strcmp(choice,"1")== 0) { SerialPutString("Type Plain Text\r\n"); GetInputString(msg); base64_encode(msg, strlen(msg)+1, encodedText); SerialPutString("Encoded Text\r\n"); printf("%s\r\n", encodedText); }else if(strcmp(choice,"2")== 0){ SerialPutString("Type Encoded Text\r\n"); GetInputString(msg); base64_decode(msg, (void *)encodedText, strlen(msg)); SerialPutString("Decoded Text\r\n"); printf("%s\r\n", encodedText); } } if (strcmp(choice,"9")== 0) { bTreat = (bool)SET; SerialPutString("\r\nServer address : "); GetInputString(msg); SerialPutString("URL = "); SerialPutString(msg); // DNS if (dns_query(SOCK_DNS, (void *)msg, Sip) == 1) { printf("\r\nSIP : %d.%d.%d.%d", (u16)Sip[0],(u16)Sip[1],(u16)Sip[2],(u16)Sip[3]); while(1) { SerialPutString("\r\nType a Sender: "); GetInputString(sender); SerialPutString("Type a Password: "******"Type a Recipient: "); GetInputString(recipient); SerialPutString("Type a Subject: "); GetInputString(subject); SerialPutString("Type a message: "); GetInputString(msg); send_mail(SOCK_SMTP, (void *)sender, (void *) passwd, (void *)recipient, (void *)subject, (void *)msg, Sip); SerialPutString("\r\nIf you want send another message? [YES]: any key, [NO]: Q"); key = GetKey(); if (key == 'Q') { SerialPutString("\r\n Stop "); break; } } }else { SerialPutString("\r\nDNS error"); } } /* OTHERS CHOICE*/ if (bTreat == (bool)RESET) { SerialPutString(" wrong choice \r\n"); } } /* While(1)*/ }/* Main_Menu */
/******************************************************************************* * Function Name : Main_Menu * Description : Display/Manage a Menu on HyperTerminal Window * Input : None * Output : None * Return : None *******************************************************************************/ void Main_Menu(void) { static char choice[3]; static char msg[256]; static bool bTreat; static u8 Sip[4]; static char key = 0; static wiz_NetInfo netinfo; while (1) { /* Display Menu on HyperTerminal Window */ bTreat = (bool)RESET ; SerialPutString("\r\n====================== STM32-Discovery ===================\r\n"); SerialPutString("This Application is basic example of UART interface with\r\n"); SerialPutString("Windows Hyper Terminal. \r\n"); SerialPutString("\r\n==========================================================\r\n"); SerialPutString(" APPLICATION MENU :\r\n"); SerialPutString("\r\n==========================================================\r\n\n"); SerialPutString(" 1 - Set LD1 on \r\n"); SerialPutString(" 2 - Set LD1 off \r\n"); SerialPutString(" 3 - Show network setting\r\n"); SerialPutString(" 4 - Set network setting\r\n"); SerialPutString(" 5 - Run TCP Loopback\r\n"); SerialPutString(" 6 - Run UDP Loopback\r\n"); SerialPutString(" 7 - DNS test\r\n"); SerialPutString(" 8 - Twitter\r\n"); SerialPutString("Enter your choice : "); GetInputString(choice); /* Set LD1 on */ if (strcmp(choice,"1")== 0) { bTreat = (bool)SET; LED3_onoff(ON); LED4_onoff(ON); } /* Set LD1 off */ if ((strcmp(choice,"2") == 0)) { bTreat = (bool)SET; LED3_onoff(OFF); LED4_onoff(OFF); } if (strcmp(choice,"3") == 0) { bTreat = (bool)SET; GetNetInfo(&netinfo); printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]); printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]); printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]); printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]); } if (strcmp(choice,"4") == 0) { bTreat = (bool)SET; // IP address SerialPutString("\r\nIP address : "); GetInputString(msg); if(!VerifyIPAddress(msg, netinfo.IP)) { SerialPutString("\aInvalid."); } // Subnet mask SerialPutString("\r\nSubnet mask : "); GetInputString(msg); if(!VerifyIPAddress(msg, netinfo.Subnet)) { SerialPutString("\aInvalid."); } // gateway address SerialPutString("\r\nGateway address : "); GetInputString(msg); if(!VerifyIPAddress(msg, netinfo.Gateway)) { SerialPutString("\aInvalid."); } // DNS address SerialPutString("\r\nDNS address : "); GetInputString(msg); if(!VerifyIPAddress(msg, netinfo.DNSServerIP)) { SerialPutString("\aInvalid."); } printf("\r\nIP : %d.%d.%d.%d", netinfo.IP[0],netinfo.IP[1],netinfo.IP[2],netinfo.IP[3]); printf("\r\nSN : %d.%d.%d.%d", netinfo.Subnet[0],netinfo.Subnet[1],netinfo.Subnet[2],netinfo.Subnet[3]); printf("\r\nGW : %d.%d.%d.%d", netinfo.Gateway[0],netinfo.Gateway[1],netinfo.Gateway[2],netinfo.Gateway[3]); printf("\r\nDNS server : %d.%d.%d.%d", netinfo.DNSServerIP[0],netinfo.DNSServerIP[1],netinfo.DNSServerIP[2],netinfo.DNSServerIP[3]); SetNetInfo(&netinfo); } if (strcmp(choice,"5") == 0) { bTreat = (bool)SET; SerialPutString("\r\nRun TCP loopback"); printf("\r\nRun TCP loopback, port number [%d] is listened", (u16)TCP_LISTEN_PORT); SerialPutString("\r\nTo Exit, press [Q]"); while(1) { if ((SerialKeyPressed((char*)&key) == 1) && (key == 'Q')) { SerialPutString("\r\n Stop "); break; } loopback_tcps(7, (u16)TCP_LISTEN_PORT); } } if (strcmp(choice,"6") == 0) { bTreat = (bool)SET; SerialPutString("\r\nRun UDP loopback"); printf("\r\nRun UDP loopback, port number [%d] is listened", (u16)UDP_LISTEN_PORT); SerialPutString("\r\nTo Exit, press [Q]"); while(1) { if ((SerialKeyPressed((char*)&key) == 1) && (key == 'Q')) { SerialPutString("\r\n Stop "); break; } loopback_udp(7, (u16)UDP_LISTEN_PORT); } } if (strcmp(choice,"7")== 0) { bTreat = (bool)SET; SerialPutString("\r\nServer address : "); GetInputString(msg); SerialPutString("URL = "); SerialPutString(msg); if (dns_query(SOCK_DNS, (void *)msg, Sip) == 1) { printf("\r\nSIP : %d.%d.%d.%d", (u16)Sip[0],(u16)Sip[1],(u16)Sip[2],(u16)Sip[3]); }else { SerialPutString("\n\r DNS fail"); } } if (strcmp(choice,"8")== 0) { bTreat = (bool)SET; // DNS if (dns_query(SOCK_DNS, LIB_DOMAIN, Sip) == 1) { printf("\r\nSIP : %d.%d.%d.%d", (u16)Sip[0],(u16)Sip[1],(u16)Sip[2],(u16)Sip[3]); while(1) { /* sprintf(msg, "Hello, World [%d] from wiz820io", twit_cnt++); SerialPutString("\r\nSend Twitter Message: "); SerialPutString(msg); */ SerialPutString("\r\nType a message: "); GetInputString(msg); Twitter_Post(SOCK_TWITTER, (void *)msg, Sip); SerialPutString("\r\nIf you want send another message? [YES]: any key, [NO]: Q"); key = GetKey(); if (key == 'Q') { SerialPutString("\r\n Stop "); break; } } }else { SerialPutString("\r\nDNS error"); } } if (strcmp(choice,"9") == 0) { uint8 l_ip[4] = {222, 98, 173, 237}; bTreat = (bool)SET; SerialPutString("\r\nRun TCP loopback [Client]"); SerialPutString("\r\nTo Exit, press [Q]"); while(1) { if ((SerialKeyPressed((char*)&key) == 1) && (key == 'Q')) { SerialPutString("\r\n Stop "); break; } TCPClientOpen(7, 5000, l_ip, 5000); Delay_ms(3000); TCPClose(7); Delay_ms(3000); } } /* OTHERS CHOICE*/ if (bTreat == (bool)RESET) { SerialPutString(" wrong choice \r\n"); } } /* While(1)*/ }/* Main_Menu */