Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00054 #include <dev/board.h>
00055 #include <sys/confnet.h>
00056
00057 #include <string.h>
00058 #include <stdint.h>
00059 #include <stdio.h>
00060 #include <io.h>
00061 #include <arpa/inet.h>
00062 #include <netinet/if_ether.h>
00063
00064 #include "meminfo.h"
00065
00066
00067 static int EditLine(char *prompt, char *line, int siz)
00068 {
00069 int ch;
00070 int pos = strlen(line);
00071
00072 printf("%s: %s", prompt, line);
00073 for (;;) {
00074 ch = getchar();
00075 if (ch == 8) {
00076 if (pos) {
00077 pos--;
00078 printf("\b \b");
00079 }
00080 }
00081 else if (ch < ' ') {
00082 break;
00083 }
00084 else if (pos + 1 < siz) {
00085 putchar(ch);
00086 line[pos++] = ch;
00087 }
00088 else {
00089 putchar('\a');
00090 }
00091 }
00092 line[pos] = 0;
00093 putchar('\n');
00094
00095 return 0;
00096 }
00097
00098
00099 int main(void)
00100 {
00101 uint32_t baud = 115200;
00102 char buf[32];
00103 uint8_t *cp;
00104 uint32_t addr;
00105 char ch;
00106
00107
00108 NutRegisterDevice(&DEV_CONSOLE, 0, 0);
00109 freopen(DEV_CONSOLE_NAME, "w", stdout);
00110 freopen(DEV_CONSOLE_NAME, "r", stdin);
00111 _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
00112 puts("\n\nNetwork Configuration Editor - Compiled " __DATE__ " - " __TIME__);
00113 ShowHardwareConfiguration();
00114
00115 for (;;) {
00116
00117 if (NutNetLoadConfig(DEV_ETHER_NAME)) {
00118 puts("\nNo configuration available");
00119 strcpy(confnet.cd_name, DEV_ETHER_NAME);
00120 } else {
00121 puts("\nConfiguration loaded");
00122 }
00123
00124
00125 do {
00126 strcpy(buf, ether_ntoa(confnet.cdn_mac));
00127 EditLine("MAC Address", buf, 18);
00128 cp = ether_aton(buf);
00129 } while (cp == NULL);
00130 memcpy(confnet.cdn_mac, cp, 6);
00131
00132
00133 do {
00134 strcpy(buf, inet_ntoa(confnet.cdn_cip_addr));
00135 EditLine("IP Address", buf, 16);
00136 addr = inet_addr(buf);
00137 } while (addr == -1);
00138 confnet.cdn_cip_addr = addr;
00139
00140
00141 do {
00142 strcpy(buf, inet_ntoa(confnet.cdn_ip_mask));
00143 EditLine("IP Mask", buf, 16);
00144 addr = inet_addr(buf);
00145 } while (addr == -1);
00146 confnet.cdn_ip_mask = addr;
00147
00148
00149 do {
00150 strcpy(buf, inet_ntoa(confnet.cdn_gateway));
00151 EditLine("IP Gate", buf, 16);
00152 addr = inet_addr(buf);
00153 } while (addr == -1);
00154 confnet.cdn_gateway = addr;
00155
00156
00157 printf("\nPress S to save this configuration ");
00158
00159
00160 while (kbhit()) {
00161 ch = getchar();
00162 }
00163 ch = getchar();
00164
00165
00166 if (ch == 's' || ch == 'S') {
00167 if (NutNetSaveConfig()) {
00168 puts("Failed");
00169 } else {
00170 puts("Saved");
00171 }
00172 } else {
00173 puts("Discarded");
00174 }
00175 }
00176 return 0;
00177 }