diff --git a/port/ethernetif.c b/port/ethernetif.c index faa64fa3..5de759e7 100644 --- a/port/ethernetif.c +++ b/port/ethernetif.c @@ -52,6 +52,7 @@ #include "lwip/sys.h" #include #include +#include "lwip/ethip6.h" #include "ethernetif.h" #include @@ -135,6 +136,9 @@ static void low_level_init(struct netif *netif) /* device capabilities */ /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; +#ifdef CONFIG_IPV6 + netif->flags |= NETIF_FLAG_MLD6; +#endif ETH_INTF_PRT("leave low level!\r\n"); } @@ -212,6 +216,7 @@ ethernetif_input(int iface, struct pbuf *p) /* IP or ARP packet? */ case ETHTYPE_IP: case ETHTYPE_ARP: + case ETHTYPE_IPV6: #if PPPOE_SUPPORT /* PPPoE packet? */ case ETHTYPE_PPPOEDISC: @@ -272,6 +277,9 @@ ethernetif_init(struct netif *netif) * is available...) */ netif->output = etharp_output; netif->linkoutput = low_level_output; +#ifdef CONFIG_IPV6 + netif->output_ip6 = ethip6_output; +#endif /* initialize the hardware */ low_level_init(netif); @@ -332,6 +340,9 @@ err_t lwip_netif_uap_init(struct netif *netif) * is available...) */ netif->output = etharp_output; netif->linkoutput = low_level_output; +#ifdef CONFIG_IPV6 + netif->output_ip6 = ethip6_output; +#endif /* initialize the hardware */ low_level_init(netif); diff --git a/port/lwip_netif_address.h b/port/lwip_netif_address.h index d92ac247..4ed32786 100644 --- a/port/lwip_netif_address.h +++ b/port/lwip_netif_address.h @@ -29,6 +29,17 @@ struct ipv4_config { unsigned dns2; }; +#ifdef CONFIG_IPV6 +struct ipv6_config +{ + /** The system's IPv6 address in network order. */ + uint32_t addr[4]; + /** The address type: linklocal, site-local or global. */ + unsigned char addr_type; + /** The state of IPv6 address (Tentative, Preferred, etc). */ + unsigned char addr_state; +}; +#endif /** Network IP configuration. * * This data structure represents the network IP configuration @@ -38,7 +49,7 @@ struct wlan_ip_config { #ifdef CONFIG_IPV6 /** The network IPv6 address configuration that should be * associated with this interface. */ - struct ipv6_config ipv6[MAX_IPV6_ADDRESSES]; + struct ipv6_config ipv6[LWIP_IPV6_NUM_ADDRESSES]; #endif /** The network IPv4 address configuration that should be * associated with this interface. */ diff --git a/port/lwipopts.h b/port/lwipopts.h index 24858b76..7a40cd74 100644 --- a/port/lwipopts.h +++ b/port/lwipopts.h @@ -233,6 +233,7 @@ * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. */ #define LWIP_RAW 1 +#define LWIP_IPV4 1 #ifdef CONFIG_IPV6 #define LWIP_IPV6 1 #endif diff --git a/port/net.c b/port/net.c index c72a4985..6f20781e 100644 --- a/port/net.c +++ b/port/net.c @@ -49,7 +49,6 @@ uint32_t uap_ip_start_flag = 0; #define IPV6_ADDR_UNKNOWN "Unknown" #endif - #define net_e warning_prf #define net_d warning_prf @@ -57,9 +56,9 @@ typedef void (*net_sta_ipup_cb_fn)(void* data); struct interface { struct netif netif; - ip_addr_t ipaddr; - ip_addr_t nmask; - ip_addr_t gw; + ip4_addr_t ipaddr; + ip4_addr_t nmask; + ip4_addr_t gw; }; FUNCPTR sta_connected_func; @@ -78,38 +77,6 @@ extern int dhcp_server_start(void *intrfc_handle); extern void dhcp_server_stop(void); extern void net_configure_dns(struct wlan_ip_config *ip); -#ifdef CONFIG_IPV6 -char *ipv6_addr_state_to_desc(unsigned char addr_state) -{ - if (ip6_addr_istentative(addr_state)) - return IPV6_ADDR_STATE_TENTATIVE; - else if (ip6_addr_ispreferred(addr_state)) - return IPV6_ADDR_STATE_PREFERRED; - else if (ip6_addr_isinvalid(addr_state)) - return IPV6_ADDR_STATE_INVALID; - else if (ip6_addr_isvalid(addr_state)) - return IPV6_ADDR_STATE_VALID; - else if (ip6_addr_isdeprecated(addr_state)) - return IPV6_ADDR_STATE_DEPRECATED; - else - return IPV6_ADDR_UNKNOWN; -} - -char *ipv6_addr_type_to_desc(struct ipv6_config *ipv6_conf) -{ - if (ip6_addr_islinklocal((ip6_addr_t *)ipv6_conf->address)) - return IPV6_ADDR_TYPE_LINKLOCAL; - else if (ip6_addr_isglobal((ip6_addr_t *)ipv6_conf->address)) - return IPV6_ADDR_TYPE_GLOBAL; - else if (ip6_addr_isuniquelocal((ip6_addr_t *)ipv6_conf->address)) - return IPV6_ADDR_TYPE_UNIQUELOCAL; - else if (ip6_addr_issitelocal((ip6_addr_t *)ipv6_conf->address)) - return IPV6_ADDR_TYPE_SITELOCAL; - else - return IPV6_ADDR_UNKNOWN; -} -#endif /* CONFIG_IPV6 */ - int net_dhcp_hostname_set(char *hostname) { netif_set_hostname(&g_mlan.netif, hostname); @@ -127,47 +94,6 @@ void net_ipv4stack_init(void) tcpip_init_done = true; } -#ifdef CONFIG_IPV6 -void net_ipv6stack_init(struct netif *netif) -{ - uint8_t mac[6]; - - netif->flags |= NETIF_IPV6_FLAG_UP; - - /* Set Multicast filter for IPV6 link local address - * It contains first three bytes: 0x33 0x33 0xff (fixed) - * and last three bytes as last three bytes of device mac */ - mac[0] = 0x33; - mac[1] = 0x33; - mac[2] = 0xff; - mac[3] = netif->hwaddr[3]; - mac[4] = netif->hwaddr[4]; - mac[5] = netif->hwaddr[5]; - wifi_add_mcast_filter(mac); - - netif_create_ip6_linklocal_address(netif, 1); - netif->ip6_autoconfig_enabled = 1; - - /* IPv6 routers use multicast IPv6 ff02::1 and MAC address - 33:33:00:00:00:01 for router advertisements */ - mac[0] = 0x33; - mac[1] = 0x33; - mac[2] = 0x00; - mac[3] = 0x00; - mac[4] = 0x00; - mac[5] = 0x01; - wifi_add_mcast_filter(mac); -} - -static void wm_netif_ipv6_status_callback(struct netif *n) -{ - /* TODO: Implement appropriate functionality here*/ - net_d("Received callback on IPv6 address state change"); - wlan_wlcmgr_send_msg(WIFI_EVENT_NET_IPV6_CONFIG, - WIFI_EVENT_REASON_SUCCESS, NULL); -} -#endif /* CONFIG_IPV6 */ - void net_wlan_init(void) { static int wlan_init_done = 0; @@ -183,9 +109,6 @@ void net_wlan_init(void) /*FIXME: Handle the error case cleanly */ net_e("MLAN interface add failed"); } -#ifdef CONFIG_IPV6 - net_ipv6stack_init(&g_mlan.netif); -#endif /* CONFIG_IPV6 */ ret = netifapi_netif_add(&g_uap.netif, &g_uap.ipaddr, &g_uap.ipaddr, &g_uap.ipaddr, NULL, @@ -244,7 +167,7 @@ static void wm_netif_status_callback(struct netif *n) { if (dhcp->state == DHCP_STATE_BOUND) { - os_printf("ip_addr: %x\r\n", n->ip_addr.addr); + os_printf("ip_addr: %x\r\n", ip_addr_get_ip4_u32(&n->ip_addr)); #if CFG_ROLE_LAUNCH rl_pre_sta_set_status(RL_STATUS_STA_LAUNCHED); @@ -352,15 +275,6 @@ void net_interface_down(void *intrfc_handle) netifapi_netif_set_down(&if_handle->netif); } -#ifdef CONFIG_IPV6 -void net_interface_deregister_ipv6_callback(void *intrfc_handle) -{ - struct interface *if_handle = (struct interface *)intrfc_handle; - if (intrfc_handle == &g_mlan) - netif_set_ipv6_status_callback(&if_handle->netif, NULL); -} -#endif - void net_interface_dhcp_stop(void *intrfc_handle) { struct interface *if_handle = (struct interface *)intrfc_handle; @@ -518,16 +432,6 @@ int net_configure_address(struct ipv4_config *addr, void *intrfc_handle) * address configuration. */ netif_set_status_callback(&if_handle->netif, NULL); -#ifdef CONFIG_IPV6 - if (if_handle == &g_mlan) { - netif_set_ipv6_status_callback(&if_handle->netif, - wm_netif_ipv6_status_callback); - /* Explicitly call this function so that the linklocal address - * gets updated even if the interface does not get any IPv6 - * address in its lifetime */ - wm_netif_ipv6_status_callback(&if_handle->netif); - } -#endif switch (addr->addr_type) { case ADDR_TYPE_STATIC: if_handle->ipaddr.addr = addr->address; @@ -562,6 +466,9 @@ int net_configure_address(struct ipv4_config *addr, void *intrfc_handle) default: break; } +#ifdef CONFIG_IPV6 + netif_create_ip6_linklocal_address(&if_handle->netif, 1); +#endif /* Finally this should send the following event. */ if (if_handle == &g_mlan) { // static IP up; @@ -596,14 +503,15 @@ int net_get_if_addr(struct wlan_ip_config *addr, void *intrfc_handle) struct interface *if_handle = (struct interface *)intrfc_handle; if(netif_is_up(&if_handle->netif)) { - addr->ipv4.address = if_handle->netif.ip_addr.addr; - addr->ipv4.netmask = if_handle->netif.netmask.addr; - addr->ipv4.gw = if_handle->netif.gw.addr; + addr->ipv4.address = ip_addr_get_ip4_u32(&if_handle->netif.ip_addr); + addr->ipv4.netmask = ip_addr_get_ip4_u32(&if_handle->netif.netmask); + addr->ipv4.gw = ip_addr_get_ip4_u32(&if_handle->netif.gw); tmp = dns_getserver(0); - addr->ipv4.dns1 = tmp->addr; - tmp = dns_getserver(1); - addr->ipv4.dns2 = tmp->addr; + addr->ipv4.dns1 = ip_addr_get_ip4_u32(tmp); + + tmp = dns_getserver(1); + addr->ipv4.dns2 = ip_addr_get_ip4_u32(tmp); } return 0; @@ -624,10 +532,10 @@ int net_get_if_ipv6_addr(struct wlan_ip_config *addr, void *intrfc_handle) struct interface *if_handle = (struct interface *)intrfc_handle; int i; - for (i = 0; i < MAX_IPV6_ADDRESSES; i++) { - memcpy(addr->ipv6[i].address, - if_handle->netif.ip6_addr[i].addr, 16); - addr->ipv6[i].addr_state = if_handle->netif.ip6_addr_state[i]; + for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + ip6_addr_copy_to_packed(addr->ipv6[i], + *ip_2_ip6(&if_handle->netif.ip6_addr[i])); + addr->ipv6[i].addr_state = if_handle->netif.ip6_addr_state[i]; } /* TODO carry out more processing based on IPv6 fields in netif */ return 0; @@ -638,10 +546,11 @@ int net_get_if_ipv6_pref_addr(struct wlan_ip_config *addr, void *intrfc_handle) int i, ret = 0; struct interface *if_handle = (struct interface *)intrfc_handle; - for (i = 0; i < MAX_IPV6_ADDRESSES; i++) { + for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { if (if_handle->netif.ip6_addr_state[i] == IP6_ADDR_PREFERRED) { - memcpy(addr->ipv6[ret++].address, - if_handle->netif.ip6_addr[i].addr, 16); + ip6_addr_copy_to_packed(addr->ipv6[ret], + *ip_2_ip6(&if_handle->netif.ip6_addr[i])); + ret++; } } return ret; @@ -652,7 +561,7 @@ int net_get_if_ip_addr(uint32_t *ip, void *intrfc_handle) { struct interface *if_handle = (struct interface *)intrfc_handle; - *ip = if_handle->netif.ip_addr.addr; + *ip = ip_addr_get_ip4_u32(&if_handle->netif.ip_addr); return 0; } @@ -660,7 +569,7 @@ int net_get_if_gw_addr(uint32_t *ip, void *intrfc_handle) { struct interface *if_handle = (struct interface *)intrfc_handle; - *ip = if_handle->netif.gw.addr; + *ip = ip_addr_get_ip4_u32(&if_handle->netif.gw); return 0; } @@ -669,7 +578,7 @@ int net_get_if_ip_mask(uint32_t *nm, void *intrfc_handle) { struct interface *if_handle = (struct interface *)intrfc_handle; - *nm = if_handle->netif.netmask.addr; + *nm = ip_addr_get_ip4_u32(&if_handle->netif.netmask); return 0; } @@ -684,9 +593,9 @@ void net_configure_dns(struct wlan_ip_config *ip) if (ip->ipv4.dns2 == 0) ip->ipv4.dns2 = ip->ipv4.dns1; - tmp.addr = ip->ipv4.dns1; + ip_addr_set_ip4_u32(&tmp, ip->ipv4.dns1); dns_setserver(0, &tmp); - tmp.addr = ip->ipv4.dns2; + ip_addr_set_ip4_u32(&tmp, ip->ipv4.dns2); dns_setserver(1, &tmp); } @@ -697,10 +606,6 @@ void net_configure_dns(struct wlan_ip_config *ip) void net_wlan_initial(void) { net_ipv4stack_init(); - -#ifdef CONFIG_IPV6 - net_ipv6stack_init(&g_mlan.netif); -#endif /* CONFIG_IPV6 */ } void net_wlan_add_netif(void *mac) diff --git a/port/net.h b/port/net.h index 89c3cbef..346fffa3 100644 --- a/port/net.h +++ b/port/net.h @@ -15,6 +15,10 @@ extern void net_wlan_remove_netif(void *mac); extern int net_get_if_macaddr(void *macaddr, void *intrfc_handle); extern int net_get_if_addr(struct wlan_ip_config *addr, void *intrfc_handle); extern void ip_address_set(int iface, int dhcp, char *ip, char *mask, char*gw, char*dns); +#ifdef CONFIG_IPV6 +int net_get_if_ipv6_addr(struct wlan_ip_config *addr, void *intrfc_handle); +int net_get_if_ipv6_pref_addr(struct wlan_ip_config *addr, void *intrfc_handle); +#endif #endif // _NET_H_ // eof