summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-04-10 14:12:49 (GMT)
committer Hanhui <sylixos@gmail.com>2019-03-07 12:37:36 (GMT)
commit6785593a5a7a30efb470a306cd3f699285d2b337 (patch)
tree1dd450e6788435bbf63a65ef810e7b54f105b390
parent3f9526fdb7d455d1d1fd7f3c00b97b2a071333a9 (diff)
downloadAIC-OS-6785593a5a7a30efb470a306cd3f699285d2b337.zip
Add net device custom format hardware address support(e.g. WiFi radiotap).
-rw-r--r--SylixOS/include/net/if_arp.h13
-rw-r--r--SylixOS/include/network/lwip/netif.h6
-rw-r--r--SylixOS/include/network/lwip/snmp.h5
-rw-r--r--SylixOS/net/lwip/lwip_ifctl.c6
-rw-r--r--SylixOS/net/lwip/netdev/netdev.c41
-rw-r--r--SylixOS/net/lwip/netdev/netdev.h5
-rw-r--r--SylixOS/net/lwip/src/core/netif.c1
7 files changed, 71 insertions, 6 deletions
diff --git a/SylixOS/include/net/if_arp.h b/SylixOS/include/net/if_arp.h
index e4bb3c2..360cd77 100644
--- a/SylixOS/include/net/if_arp.h
+++ b/SylixOS/include/net/if_arp.h
@@ -47,9 +47,16 @@ extern "C" {
struct arphdr {
u_short ar_hrd; /* format of hardware address */
-#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_ETHER 1 /* ethernet hardware format */
+#define ARPHRD_IEEE802 6 /* token-ring hardware format */
+#define ARPHRD_FRELAY 15 /* frame relay 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 */
+#define ARPHRD_IEEE80211_RADIOTAP 803 /* IEEE 802.11 + radiotap header */
+#define ARPHRD_IEEE802154 804 /* IEEE 802.15.4 */
+#define ARPHRD_VOID 0xffff /* Void type, nothing is known */
+#define ARPHRD_NONE 0xfffe /* zero header length */
u_short ar_pro; /* format of protocol address */
u_char ar_hln; /* length of hardware address */
u_char ar_pln; /* length of protocol address */
diff --git a/SylixOS/include/network/lwip/netif.h b/SylixOS/include/network/lwip/netif.h
index f05cf39..025da9d 100644
--- a/SylixOS/include/network/lwip/netif.h
+++ b/SylixOS/include/network/lwip/netif.h
@@ -361,7 +361,11 @@ struct netif {
#endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
#if MIB2_STATS
/** link type (from "snmp_ifType" enum from snmp_mib2.h) */
+#ifdef SYLIXOS /* SylixOS Need u16_t link type */
+ u16_t link_type;
+#else /* SYLIXOS */
u8_t link_type;
+#endif /* !SYLIXOS */
/** (estimate) link speed */
u32_t link_speed;
/** timestamp at last change made (up/down) */
@@ -425,6 +429,8 @@ struct netif {
#define NETIF_NAT_AP 1
#define NETIF_NAT_LOCAL 2
u8_t nat_mode;
+ /* ARPHRD_xxx */
+ u16_t ar_hrd;
void *reserve[6];
#endif /* SYLIXOS */
};
diff --git a/SylixOS/include/network/lwip/snmp.h b/SylixOS/include/network/lwip/snmp.h
index 69b479d..9929c89 100644
--- a/SylixOS/include/network/lwip/snmp.h
+++ b/SylixOS/include/network/lwip/snmp.h
@@ -91,6 +91,11 @@ enum snmp_ifType {
snmp_ifType_ds3, /* T-3 */
snmp_ifType_sip, /* SMDS */
snmp_ifType_frame_relay
+#ifdef SYLIXOS /* SYLIXOS Add some ifType */
+ ,
+ snmp_ifType_ieee80211 = 71,
+ snmp_ifType_ieee802154 = 259
+#endif /* SYLIXOS */
};
/** This macro has a precision of ~49 days because sys_now returns u32_t. \#define your own if you want ~490 days. */
diff --git a/SylixOS/net/lwip/lwip_ifctl.c b/SylixOS/net/lwip/lwip_ifctl.c
index 411608e..c8c92d7 100644
--- a/SylixOS/net/lwip/lwip_ifctl.c
+++ b/SylixOS/net/lwip/lwip_ifctl.c
@@ -242,7 +242,11 @@ static INT __ifSubIoctlIf (INT iCmd, PVOID pvArg)
for (i = 0; i < IFHWADDRLEN; i++) {
pifreq->ifr_hwaddr.sa_data[i] = pnetif->hwaddr[i];
}
- pifreq->ifr_hwaddr.sa_family = ARPHRD_ETHER;
+ if (pnetif->ar_hrd != ARPHRD_VOID) {
+ pifreq->ifr_hwaddr.sa_family = pnetif->ar_hrd;
+ } else {
+ pifreq->ifr_hwaddr.sa_family = ARPHRD_ETHER;
+ }
iRet = ERROR_NONE;
} else {
_ErrorHandle(EINVAL);
diff --git a/SylixOS/net/lwip/netdev/netdev.c b/SylixOS/net/lwip/netdev/netdev.c
index aa460f4..960c8f7 100644
--- a/SylixOS/net/lwip/netdev/netdev.c
+++ b/SylixOS/net/lwip/netdev/netdev.c
@@ -52,6 +52,7 @@
#include "netif/ethernet.h"
#include "netif/lowpan6.h"
#include "netif/lowpan6_ble.h"
+#include "net/if_arp.h"
#include "net/if_lock.h"
#include "net/if_flags.h"
#include "net/if_param.h"
@@ -607,10 +608,11 @@ static err_t netdev_netif_init (struct netif *netif)
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
+ netif->ar_hrd = ARPHRD_ETHER;
break;
case NETDEV_TYPE_LOWPAN:
- MIB2_INIT_NETIF(netif, snmp_ifType_other, 0);
+ MIB2_INIT_NETIF(netif, snmp_ifType_ieee802154, 0);
netif->flags = NETIF_FLAG_BROADCAST;
netif->output = netdev_netif_nulloutput4;
#if LWIP_IPV6
@@ -620,10 +622,11 @@ static err_t netdev_netif_init (struct netif *netif)
lowpan6_timer = 1;
}
#endif /* LWIP_IPV6 */
+ netif->ar_hrd = ARPHRD_IEEE802154;
break;
case NETDEV_TYPE_LOWPAN_BLE:
- MIB2_INIT_NETIF(netif, snmp_ifType_other, 0);
+ MIB2_INIT_NETIF(netif, snmp_ifType_ieee802154, 0);
netif->flags = 0;
netif->output = netdev_netif_nulloutput4;
#if LWIP_IPV6
@@ -634,6 +637,7 @@ static err_t netdev_netif_init (struct netif *netif)
rfc7668_set_local_addr_mac48(netif, netdev->hwaddr, netif->hwaddr_len, 0); /* not public ? */
}
#endif /* LWIP_IPV6 */
+ netif->ar_hrd = ARPHRD_IEEE802154;
break;
default:
@@ -643,6 +647,7 @@ static err_t netdev_netif_init (struct netif *netif)
#if LWIP_IPV6
netif->output_ip6 = netdev_netif_rawoutput6;
#endif /* LWIP_IPV6 */
+ netif->ar_hrd = ARPHRD_VOID;
break;
}
@@ -1287,6 +1292,38 @@ int netdev_ifname (netdev_t *netdev, char *ifname)
return (0);
}
+/* netdev set/get format of hardware address
+ * NOTICE: you can call these function after netdev_add() */
+int netdev_set_ar_hdr (netdev_t *netdev, UINT16 ar_hdr)
+{
+ struct netif *netif;
+
+ if (!netdev || (netdev->magic_no != NETDEV_MAGIC)) {
+ return (-1);
+ }
+
+ netif = (struct netif *)netdev->sys;
+
+ netif->ar_hrd = ar_hdr;
+
+ return (0);
+}
+
+int netdev_get_ar_hdr (netdev_t *netdev, UINT16 *ar_hdr)
+{
+ struct netif *netif;
+
+ if (!netdev || !ar_hdr || (netdev->magic_no != NETDEV_MAGIC)) {
+ return (-1);
+ }
+
+ netif = (struct netif *)netdev->sys;
+
+ *ar_hdr = netif->ar_hrd;
+
+ return (0);
+}
+
/* netdev set/get tcp ack frequecy
* NOTICE: you can call these function after netdev_add() */
int netdev_set_tcpaf (netdev_t *netdev, UINT8 tcpaf)
diff --git a/SylixOS/net/lwip/netdev/netdev.h b/SylixOS/net/lwip/netdev/netdev.h
index e7b372e..aa69d75 100644
--- a/SylixOS/net/lwip/netdev/netdev.h
+++ b/SylixOS/net/lwip/netdev/netdev.h
@@ -352,6 +352,11 @@ netdev_t *netdev_find_by_index(unsigned int index);
netdev_t *netdev_find_by_ifname(const char *if_name);
netdev_t *netdev_find_by_devname(const char *dev_name);
+/* netdev set/get format of hardware address
+ * NOTICE: you can call these function after netdev_add() */
+int netdev_set_ar_hdr(netdev_t *netdev, UINT16 ar_hdr);
+int netdev_get_ar_hdr(netdev_t *netdev, UINT16 *ar_hdr);
+
/* netdev set/get tcp ack frequecy
* NOTICE: you can call these function after netdev_add() */
int netdev_set_tcpaf(netdev_t *netdev, UINT8 tcpaf);
diff --git a/SylixOS/net/lwip/src/core/netif.c b/SylixOS/net/lwip/src/core/netif.c
index 2ebae0a..433971e 100644
--- a/SylixOS/net/lwip/src/core/netif.c
+++ b/SylixOS/net/lwip/src/core/netif.c
@@ -391,6 +391,7 @@ netif_add(struct netif *netif,
netif->mipif = NULL;
netif->masterif = NULL;
netif->nat_mode = NETIF_NAT_NONE;
+ netif->ar_hrd = 0xffff;
lib_bzero(netif->reserve, sizeof(void *[6]));
#endif /* SYLIXOS */