Logiciels Libres et Systèmes Embarqués

lwip_config.c

Aller à la documentation de ce fichier.
00001 #include "global.h"   // XEmacIF_ConfigTable[]
00002 
00003 #ifdef LOOPBACK
00004 extern err_t loopif_init(struct netif *netif);
00005 #endif
00006 
00007 struct netif *lwip_config(const unsigned char mac[6], const unsigned char ip[4],
00008                 const unsigned char subnet[4], const unsigned char gateway[4])
00009 {
00010         struct ip_addr ipaddr;
00011         struct ip_addr netmask;
00012         struct ip_addr gw;
00013         struct netif *netif = NULL;
00014 
00015 #ifdef EMAC
00016         xemacliteif_setmac(0, (u8_t *)mac);
00017 #endif
00018         
00019         IP4_ADDR(&ipaddr, ip[0], ip[1], ip[2], ip[3]);
00020         IP4_ADDR(&netmask, subnet[0], subnet[1], subnet[2], subnet[3]);
00021         IP4_ADDR(&gw, gateway[0], gateway[1], gateway[2], gateway[3]);
00022 
00023         netif = mem_malloc(sizeof(struct netif));
00024         if(NULL == netif) {
00025                 print("mem_alloc(): echec.\n\r");
00026                 return NULL;
00027         }
00028 
00029 #ifdef LOOP
00030         netif = netif_add(netif, &ipaddr, &netmask, &gw, NULL, loopif_init, ip_input);
00031 #endif
00032 #ifdef EMAC
00033         netif = netif_add(netif, &ipaddr, &netmask, &gw, &XEmacLiteIf_ConfigTable[EMAC], xemacliteif_init, ip_input);
00034 #endif
00035 #ifdef SLIP
00036 netif = netif_add(netif, &ipaddr, &netmask, &gw, SLIP, slipif_init, ip_input);
00037 #endif
00038 
00039         if(NULL == netif) {
00040                 print("netif_add(): echec.\n\r");
00041                 return NULL;
00042         }
00043 
00044 
00045         netif_set_default(netif);
00046 
00047         return netif;
00048 }