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
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 #include "board.h"
00102
00103 #include "uip.h"
00104 #include "uip_arp.h"
00105 #include "gmac_tapdev.h"
00106 #include "timer.h"
00107
00108
00109
00110
00111
00112
00113 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
00114
00115
00116 static const struct uip_eth_addr MacAddress = {{0x3a, 0x1f, 0x34, 0x08, 0x54, 0x54}};
00117
00118
00119 static uint8_t HostIpAddress[4] = {192, 168, 1, 3 };
00120
00121
00122 static const uint8_t RoutIpAddress[4] ={192, 168, 1, 2 };
00123
00124
00125 static const uint8_t NetMask[4] = {255, 255, 255, 0};
00126
00127
00128
00129
00130
00131
00132
00133
00134 static void _app_init(void)
00135 {
00136 printf("P: telnetd application init\n\r");
00137 telnetd_init();
00138
00139 #ifdef __DHCPC_H__
00140 printf("P: DHCPC Init\n\r");
00141 dhcpc_init(MacAddress.addr, 6);
00142 #endif
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 void uip_log(char *m)
00154 {
00155 TRACE_INFO("-uIP log- %s\n\r", m);
00156 }
00157
00158 #ifdef __DHCPC_H__
00159
00160
00161
00162
00163
00164 void dhcpc_configured(const struct dhcpc_state *s)
00165 {
00166 u8_t * pAddr;
00167
00168 printf("\n\r");
00169 printf("=== DHCP Configurations ===\n\r");
00170 pAddr = (u8_t *)s->ipaddr;
00171 printf("- IP : %d.%d.%d.%d\n\r",
00172 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00173 pAddr = (u8_t *)s->netmask;
00174 printf("- Mask : %d.%d.%d.%d\n\r",
00175 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00176 pAddr = (u8_t *)s->default_router;
00177 printf("- GW : %d.%d.%d.%d\n\r",
00178 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00179 pAddr = (u8_t *)s->dnsaddr;
00180 printf("- DNS : %d.%d.%d.%d\n\r",
00181 pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
00182 printf("===========================\n\r\n");
00183 uip_sethostaddr(s->ipaddr);
00184 uip_setnetmask(s->netmask);
00185 uip_setdraddr(s->default_router);
00186
00187 #ifdef __RESOLV_H__
00188 resolv_conf(s->dnsaddr);
00189 #else
00190 printf("DNS NOT enabled in the demo\n\r");
00191 #endif
00192 }
00193 #endif
00194
00195
00196
00197
00198
00199
00200 int main(void)
00201 {
00202 uip_ipaddr_t ipaddr;
00203 struct timer periodic_timer, arp_timer;
00204 uint32_t i;
00205
00206
00207 WDT_Disable( WDT ) ;
00208
00209 SCB_EnableICache();
00210 SCB_EnableDCache();
00211
00212 TimeTick_Configure();
00213 printf("-- GMAC uIP Telnetd Example %s --\n\r", SOFTPACK_VERSION);
00214 printf("-- %s\n\r", BOARD_NAME);
00215 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ;
00216
00217
00218 printf(" - MAC %x:%x:%x:%x:%x:%x\n\r",
00219 MacAddress.addr[0], MacAddress.addr[1], MacAddress.addr[2],
00220 MacAddress.addr[3], MacAddress.addr[4], MacAddress.addr[5]);
00221 #ifndef __DHCPC_H__
00222 printf(" - Host IP %d.%d.%d.%d\n\r",
00223 HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]);
00224 printf(" - Router IP %d.%d.%d.%d\n\r",
00225 RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]);
00226 printf(" - Net Mask %d.%d.%d.%d\n\r",
00227 NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
00228 #endif
00229
00230
00231 gmac_tapdev_setmac((uint8_t *)MacAddress.addr);
00232 gmac_tapdev_init();
00233 clock_init();
00234 timer_set(&periodic_timer, CLOCK_SECOND / 2);
00235 timer_set(&arp_timer, CLOCK_SECOND * 10);
00236
00237
00238 uip_init();
00239
00240 #ifdef __DHCPC_H__
00241 printf("P: DHCP Supported\n\r");
00242 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00243 uip_sethostaddr(ipaddr);
00244 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00245 uip_setdraddr(ipaddr);
00246 uip_ipaddr(ipaddr, 0, 0, 0, 0);
00247 uip_setnetmask(ipaddr);
00248 #else
00249
00250 uip_ipaddr(ipaddr, HostIpAddress[0], HostIpAddress[1],
00251 HostIpAddress[2], HostIpAddress[3]);
00252 uip_sethostaddr(ipaddr);
00253
00254 uip_ipaddr(ipaddr, RoutIpAddress[0], RoutIpAddress[1],
00255 RoutIpAddress[2], RoutIpAddress[3]);
00256 uip_setdraddr(ipaddr);
00257
00258 uip_ipaddr(ipaddr, NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
00259 uip_setnetmask(ipaddr);
00260 #endif
00261
00262 uip_setethaddr(MacAddress);
00263
00264 _app_init();
00265
00266 while(1) {
00267 uip_len = gmac_tapdev_read();
00268 if(uip_len > 0) {
00269 if(BUF->type == htons(UIP_ETHTYPE_IP)) {
00270 uip_arp_ipin();
00271 uip_input();
00272
00273
00274
00275 if(uip_len > 0) {
00276 uip_arp_out();
00277 gmac_tapdev_send();
00278 }
00279 } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
00280 uip_arp_arpin();
00281
00282
00283
00284 if(uip_len > 0) {
00285 gmac_tapdev_send();
00286 }
00287 }
00288 } else if(timer_expired(&periodic_timer)) {
00289 timer_reset(&periodic_timer);
00290 for(i = 0; i < UIP_CONNS; i++) {
00291 uip_periodic(i);
00292
00293
00294
00295 if(uip_len > 0) {
00296 uip_arp_out();
00297 gmac_tapdev_send();
00298 }
00299 }
00300 #if UIP_UDP
00301 for(i = 0; i < UIP_UDP_CONNS; i++) {
00302 uip_udp_periodic(i);
00303
00304
00305
00306 if(uip_len > 0) {
00307 uip_arp_out();
00308 gmac_tapdev_send();
00309 }
00310 }
00311 #endif
00312
00313
00314 if(timer_expired(&arp_timer)) {
00315 timer_reset(&arp_timer);
00316 uip_arp_timer();
00317 }
00318 }
00319 }
00320 }
00321