summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-04-11 08:26:20 (GMT)
committer Hanhui <sylixos@gmail.com>2019-03-07 12:37:37 (GMT)
commitf25fa7a9e86de2baee679a20f795001c46248b58 (patch)
tree0acad37b05e6161c03f7d170f9feb414d7bbe815
parent6785593a5a7a30efb470a306cd3f699285d2b337 (diff)
downloadAIC-OS-f25fa7a9e86de2baee679a20f795001c46248b58.zip
Add 'if_hwaddr.h' to support all 'haltype' net interface.
-rw-r--r--SylixOS/include/net/if_arp.h2
-rw-r--r--SylixOS/include/net/if_hwaddr.h59
-rw-r--r--SylixOS/net/libc/getifaddrs.c20
-rw-r--r--SylixOS/net/lwip/lwip_ifctl.c24
-rw-r--r--SylixOS/net/lwip/src/core/netif.c1
-rw-r--r--SylixOS/vpmpdm/net/getifaddrs.c20
6 files changed, 101 insertions, 25 deletions
diff --git a/SylixOS/include/net/if_arp.h b/SylixOS/include/net/if_arp.h
index 360cd77..1a79c45 100644
--- a/SylixOS/include/net/if_arp.h
+++ b/SylixOS/include/net/if_arp.h
@@ -50,6 +50,8 @@ struct arphdr {
#define ARPHRD_ETHER 1 /* ethernet hardware format */
#define ARPHRD_IEEE802 6 /* token-ring hardware format */
#define ARPHRD_FRELAY 15 /* frame relay hardware format */
+#define ARPHRD_IEEE1394 24 /* firewire hardware format */
+#define ARPHRD_INFINIBAND 32 /* infiniband hardware format */
#define ARPHRD_IEEE802_TR 800 /* Magic type ident for TR */
#define ARPHRD_IEEE80211 801 /* IEEE 802.11 */
#define ARPHRD_IEEE80211_PRISM 802 /* IEEE 802.11 + Prism2 header */
diff --git a/SylixOS/include/net/if_hwaddr.h b/SylixOS/include/net/if_hwaddr.h
new file mode 100644
index 0000000..79741d0
--- /dev/null
+++ b/SylixOS/include/net/if_hwaddr.h
@@ -0,0 +1,59 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: if_hwaddr.h
+**
+** 创 建 人: Han.Hui (韩辉)
+**
+** 文件创建日期: 2019 年 05 月 11 日
+**
+** 描 述: ARP.
+*********************************************************************************************************/
+
+#ifndef __IF_HWADDR_H
+#define __IF_HWADDR_H
+
+#include <sys/types.h>
+
+/*********************************************************************************************************
+ 裁剪控制
+*********************************************************************************************************/
+#if LW_CFG_NET_EN > 0
+
+#define IFHWADDR_MAXLEN 25
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct sockaddr_ha {
+ u_char sha_type_hi; /* hal type high => sa_len */
+ u_char sha_type_lo; /* hal type low => sa_family */
+ u_char sha_ha[IFHWADDR_MAXLEN]; /* hal hwaddr */
+ u_char sha_alen; /* hal hwaddr length */
+};
+
+#define HALTYPE_FROM_SA(sa) (((u_short)(sa)->sa_len << 8) + (sa)->sa_family)
+#define HALTYPE_FROM_SAHA(saha) (((u_short)(saha)->sha_type_hi << 8) + (saha)->sha_type_lo)
+
+#define HALALEN_FROM_SA(sa) (sa)->sa_data[25]
+#define HALALEN_FROM_SAHA(saha) (saha)->sha_alen
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LW_CFG_NET_EN */
+#endif /* __IF_HWADDR_H */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/net/libc/getifaddrs.c b/SylixOS/net/libc/getifaddrs.c
index 9fa79ba..977bb9e 100644
--- a/SylixOS/net/libc/getifaddrs.c
+++ b/SylixOS/net/libc/getifaddrs.c
@@ -34,6 +34,7 @@
#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_dl.h>
+#include <net/if_hwaddr.h>
#include <net/if_types.h>
#include <netinet6/in6.h>
#include <netpacket/packet.h>
@@ -93,23 +94,23 @@ __init_in6 (struct sockaddr_in6 *in6)
#endif
static void
-__init_ll (struct sockaddr_ll *ll)
+__init_ll (struct sockaddr_ll *ll, u_short hatype, u_char alen)
{
bzero(ll, sizeof(struct sockaddr_ll));
ll->sll_len = sizeof(struct sockaddr_ll);
ll->sll_family = AF_PACKET;
- ll->sll_hatype = ARPHRD_ETHER;
- ll->sll_halen = IFHWADDRLEN;
+ ll->sll_hatype = hatype;
+ ll->sll_halen = alen;
}
static void
-__init_dl (struct sockaddr_dl *dl)
+__init_dl (struct sockaddr_dl *dl, u_char alen)
{
bzero(dl, sizeof(struct sockaddr_dl));
dl->sdl_len = sizeof(struct sockaddr_dl);
dl->sdl_family = AF_LINK;
dl->sdl_nlen = 4;
- dl->sdl_alen = IFHWADDRLEN;
+ dl->sdl_alen = alen;
}
#if LWIP_IPV6
@@ -268,11 +269,16 @@ getifaddrs(struct ifaddrs **pif)
#endif /* LWIP_IPV6 */
if (ioctl(s, SIOCGIFHWADDR, &req[i]) == 0) { /* get hwaddr */
+ u_short hatype;
+ u_char alen;
struct ifaddrs *ifaddr_ll;
struct ifaddrs *ifaddr_dl;
struct sockaddr_ll *ll;
struct sockaddr_dl *dl;
+ hatype = HALTYPE_FROM_SA(&req[i].ifr_hwaddr);
+ alen = HALALEN_FROM_SA(&req[i].ifr_hwaddr);
+
/* setup AF_PACKET */
ifaddr_ll = (struct ifaddrs *)malloc(IFADDR_SIZE);
if (ifaddr_ll == NULL) {
@@ -285,7 +291,7 @@ getifaddrs(struct ifaddrs **pif)
ifaddr_ll->ifa_flags = ifaddr->ifa_flags;
ll = (struct sockaddr_ll *)ifaddr_ll->ifa_addr;
- __init_ll(ll);
+ __init_ll(ll, hatype, alen);
ll->sll_ifindex = netif_index;
memcpy(ll->sll_addr, req[i].ifr_hwaddr.sa_data, IFHWADDRLEN);
@@ -306,7 +312,7 @@ getifaddrs(struct ifaddrs **pif)
ifaddr_dl->ifa_flags = ifaddr->ifa_flags;
dl = (struct sockaddr_dl *)ifaddr_dl->ifa_addr;
- __init_dl(dl);
+ __init_dl(dl, alen);
dl->sdl_index = netif_index;
memcpy(LLADDR(dl), req[i].ifr_hwaddr.sa_data, IFHWADDRLEN);
diff --git a/SylixOS/net/lwip/lwip_ifctl.c b/SylixOS/net/lwip/lwip_ifctl.c
index c8c92d7..abf938b 100644
--- a/SylixOS/net/lwip/lwip_ifctl.c
+++ b/SylixOS/net/lwip/lwip_ifctl.c
@@ -26,6 +26,7 @@
#if LW_CFG_NET_EN > 0
#include "net/if.h"
#include "net/if_arp.h"
+#include "net/if_hwaddr.h"
#include "net/if_types.h"
#include "net/if_lock.h"
#include "net/if_flags.h"
@@ -149,8 +150,8 @@ static INT __ifReq6Size (struct in6_ifreq *pifreq6)
*********************************************************************************************************/
static INT __ifSubIoctlIf (INT iCmd, PVOID pvArg)
{
+ INT i, iIsUp, iFlags;
INT iRet = PX_ERROR;
- INT iFlags;
struct ifreq *pifreq = LW_NULL;
struct netif *pnetif;
@@ -237,16 +238,18 @@ static INT __ifSubIoctlIf (INT iCmd, PVOID pvArg)
break;
case SIOCGIFHWADDR: /* 获得物理地址 */
- if (pnetif->flags & (NETIF_FLAG_ETHERNET | NETIF_FLAG_ETHARP)) {
- INT i;
- for (i = 0; i < IFHWADDRLEN; i++) {
- pifreq->ifr_hwaddr.sa_data[i] = pnetif->hwaddr[i];
- }
+ if (pnetif->hwaddr_len && (pnetif->hwaddr_len <= IFHWADDR_MAXLEN)) {
if (pnetif->ar_hrd != ARPHRD_VOID) {
- pifreq->ifr_hwaddr.sa_family = pnetif->ar_hrd;
+ pifreq->ifr_hwaddr.sa_len = pnetif->ar_hrd >> 8;
+ pifreq->ifr_hwaddr.sa_family = pnetif->ar_hrd & 0xff; /* 设置网卡地址类型 */
} else {
+ pifreq->ifr_hwaddr.sa_len = 0;
pifreq->ifr_hwaddr.sa_family = ARPHRD_ETHER;
}
+ for (i = 0; i < pnetif->hwaddr_len; i++) {
+ pifreq->ifr_hwaddr.sa_data[i] = pnetif->hwaddr[i];
+ }
+ HALALEN_FROM_SA(&pifreq->ifr_hwaddr) = pnetif->hwaddr_len;
iRet = ERROR_NONE;
} else {
_ErrorHandle(EINVAL);
@@ -254,14 +257,13 @@ static INT __ifSubIoctlIf (INT iCmd, PVOID pvArg)
break;
case SIOCSIFHWADDR: /* 设置 mac 地址 */
- if (pnetif->flags & (NETIF_FLAG_ETHERNET | NETIF_FLAG_ETHARP)) {
- INT i;
- INT iIsUp = netif_is_up(pnetif);
+ if (pnetif->hwaddr_len && (pnetif->hwaddr_len <= IFHWADDR_MAXLEN)) {
+ iIsUp = netif_is_up(pnetif);
if (pnetif->ioctl) {
netifapi_netif_set_down(pnetif); /* 关闭网口 */
iRet = pnetif->ioctl(pnetif, SIOCSIFHWADDR, pvArg);
if (iRet == ERROR_NONE) {
- for (i = 0; i < IFHWADDRLEN; i++) {
+ for (i = 0; i < pnetif->hwaddr_len; i++) {
pnetif->hwaddr[i] = pifreq->ifr_hwaddr.sa_data[i];
}
}
diff --git a/SylixOS/net/lwip/src/core/netif.c b/SylixOS/net/lwip/src/core/netif.c
index 433971e..442a84b 100644
--- a/SylixOS/net/lwip/src/core/netif.c
+++ b/SylixOS/net/lwip/src/core/netif.c
@@ -371,6 +371,7 @@ netif_add(struct netif *netif,
#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
#ifdef SYLIXOS /* SylixOS Add */
+ netif->hwaddr_len = 0;
netif->ioctl = NULL;
netif->up = NULL;
netif->down = NULL;
diff --git a/SylixOS/vpmpdm/net/getifaddrs.c b/SylixOS/vpmpdm/net/getifaddrs.c
index d2fb188..276ff24 100644
--- a/SylixOS/vpmpdm/net/getifaddrs.c
+++ b/SylixOS/vpmpdm/net/getifaddrs.c
@@ -37,6 +37,7 @@ __RCSID("$NetBSD: getifaddrs.c,v 1.11.12.1 2009/05/03 13:17:52 bouyer Exp $");
#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_dl.h>
+#include <net/if_hwaddr.h>
#include <net/if_types.h>
#include <netinet6/in6.h>
#include <netpacket/packet.h>
@@ -88,23 +89,23 @@ __init_in6 (struct sockaddr_in6 *in6)
}
static void
-__init_ll (struct sockaddr_ll *ll)
+__init_ll (struct sockaddr_ll *ll, u_short hatype, u_char alen)
{
bzero(ll, sizeof(struct sockaddr_ll));
ll->sll_len = sizeof(struct sockaddr_ll);
ll->sll_family = AF_PACKET;
- ll->sll_hatype = ARPHRD_ETHER;
- ll->sll_halen = IFHWADDRLEN;
+ ll->sll_hatype = hatype;
+ ll->sll_halen = alen;
}
static void
-__init_dl (struct sockaddr_dl *dl)
+__init_dl (struct sockaddr_dl *dl, u_char alen)
{
bzero(dl, sizeof(struct sockaddr_dl));
dl->sdl_len = sizeof(struct sockaddr_dl);
dl->sdl_family = AF_LINK;
dl->sdl_nlen = 4;
- dl->sdl_alen = IFHWADDRLEN;
+ dl->sdl_alen = alen;
}
static void
@@ -258,11 +259,16 @@ getifaddrs(struct ifaddrs **pif)
}
if (ioctl(s, SIOCGIFHWADDR, &req[i]) == 0) { /* get hwaddr */
+ u_short hatype;
+ u_char alen;
struct ifaddrs *ifaddr_ll;
struct ifaddrs *ifaddr_dl;
struct sockaddr_ll *ll;
struct sockaddr_dl *dl;
+ hatype = HALTYPE_FROM_SA(&req[i].ifr_hwaddr);
+ alen = HALALEN_FROM_SA(&req[i].ifr_hwaddr);
+
/* setup AF_PACKET */
ifaddr_ll = (struct ifaddrs *)malloc(IFADDR_SIZE);
if (ifaddr_ll == NULL) {
@@ -275,7 +281,7 @@ getifaddrs(struct ifaddrs **pif)
ifaddr_ll->ifa_flags = ifaddr->ifa_flags;
ll = (struct sockaddr_ll *)ifaddr_ll->ifa_addr;
- __init_ll(ll);
+ __init_ll(ll, hatype, alen);
ll->sll_ifindex = netif_index;
memcpy(ll->sll_addr, req[i].ifr_hwaddr.sa_data, IFHWADDRLEN);
@@ -296,7 +302,7 @@ getifaddrs(struct ifaddrs **pif)
ifaddr_dl->ifa_flags = ifaddr->ifa_flags;
dl = (struct sockaddr_dl *)ifaddr_dl->ifa_addr;
- __init_dl(dl);
+ __init_dl(dl, alen);
dl->sdl_index = netif_index;
memcpy(LLADDR(dl), req[i].ifr_hwaddr.sa_data, IFHWADDRLEN);