aboutsummaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-11-21 13:36:25 -0800
committerJosh Blum <josh@joshknows.com>2010-12-11 18:43:09 -0800
commit6004410a7b73a52d95b8f5f0cf0fa969bef4e910 (patch)
tree0f3cfd706b992c9008a90b75d9eb2315d4f8b7c6 /firmware
parentfe35b8ae0785fff7d33e18b62e3b435cfd5a5475 (diff)
downloaduhd-6004410a7b73a52d95b8f5f0cf0fa969bef4e910.tar.gz
uhd-6004410a7b73a52d95b8f5f0cf0fa969bef4e910.tar.bz2
uhd-6004410a7b73a52d95b8f5f0cf0fa969bef4e910.zip
packet_router: implemented code to program the addresses into the router
Diffstat (limited to 'firmware')
-rw-r--r--firmware/microblaze/apps/txrx_uhd.c6
-rw-r--r--firmware/microblaze/lib/net_common.c15
-rw-r--r--firmware/microblaze/lib/net_common.h4
-rw-r--r--firmware/microblaze/lib/pkt_ctrl.c24
-rw-r--r--firmware/microblaze/lib/pkt_ctrl.h7
5 files changed, 38 insertions, 18 deletions
diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c
index f922ce4af..741167c0e 100644
--- a/firmware/microblaze/apps/txrx_uhd.c
+++ b/firmware/microblaze/apps/txrx_uhd.c
@@ -348,9 +348,9 @@ main(void)
printf("Firmware compatibility number: %d\n", USRP2_FW_COMPAT_NUM);
//1) register the addresses into the network stack
- register_mac_addr(ethernet_mac_addr());
- register_ip_addr(get_ip_addr());
-
+ register_addrs(ethernet_mac_addr(), get_ip_addr());
+ pkt_ctrl_register_addrs(ethernet_mac_addr(), get_ip_addr());
+
//2) register callbacks for udp ports we service
register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet);
register_udp_listener(USRP2_UDP_DATA_PORT, handle_udp_data_packet);
diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c
index 48aa460f9..e9b633b13 100644
--- a/firmware/microblaze/lib/net_common.c
+++ b/firmware/microblaze/lib/net_common.c
@@ -39,21 +39,12 @@
static const eth_mac_addr_t BCAST_MAC_ADDR = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
-static inline bool
-ip_addr_eq(const struct ip_addr a, const struct ip_addr b)
-{
- return a.addr == b.addr;
-}
-
// ------------------------------------------------------------------------
static eth_mac_addr_t _local_mac_addr;
-void register_mac_addr(const eth_mac_addr_t *mac_addr){
- _local_mac_addr = *mac_addr;
-}
-
static struct ip_addr _local_ip_addr;
-void register_ip_addr(const struct ip_addr *ip_addr){
+void register_addrs(const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr){
+ _local_mac_addr = *mac_addr;
_local_ip_addr = *ip_addr;
}
@@ -382,7 +373,7 @@ handle_arp_packet(struct arp_eth_ipv4 *p, size_t size)
sip.addr = get_int32(p->ar_sip);
tip.addr = get_int32(p->ar_tip);
- if (ip_addr_eq(tip, _local_ip_addr)){ // They're looking for us...
+ if (memcmp(&tip, &_local_ip_addr, sizeof(_local_ip_addr)) == 0){ // They're looking for us...
send_arp_reply(p, _local_mac_addr);
}
}
diff --git a/firmware/microblaze/lib/net_common.h b/firmware/microblaze/lib/net_common.h
index 9d6a3e345..5e364adeb 100644
--- a/firmware/microblaze/lib/net_common.h
+++ b/firmware/microblaze/lib/net_common.h
@@ -26,9 +26,7 @@
typedef void (*udp_receiver_t)(struct socket_address src, struct socket_address dst,
unsigned char *payload, int payload_len);
-void register_mac_addr(const eth_mac_addr_t *mac_addr);
-
-void register_ip_addr(const struct ip_addr *ip_addr);
+void register_addrs(const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr);
void register_udp_listener(int port, udp_receiver_t rcvr);
diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c
index 9f662122d..52ba80e3a 100644
--- a/firmware/microblaze/lib/pkt_ctrl.c
+++ b/firmware/microblaze/lib/pkt_ctrl.c
@@ -47,6 +47,30 @@ static bool is_status_bit_set(int bit){
#define MODE_BIT 2
#define CLR_BIT 8
+void pkt_ctrl_register_addrs(
+ const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr
+){
+ //program in the ip addr
+ set_control(0x1 << 4, 0x7 << 4);
+ set_control((ip_addr->addr & 0x0000ffff) << 16, 0xffff << 16);
+ set_control(0x2 << 4, 0x7 << 4);
+ set_control((ip_addr->addr & 0xffff0000) << 0, 0xffff << 16);
+
+ //program in the mac addr
+ set_control(0x3 << 4, 0x7 << 4);
+ set_control((uint32_t)mac_addr->addr[0] << 16, 0x00ff << 16);
+ set_control((uint32_t)mac_addr->addr[1] << 24, 0xff00 << 16);
+ set_control(0x4 << 4, 0x7 << 4);
+ set_control((uint32_t)mac_addr->addr[2] << 16, 0x00ff << 16);
+ set_control((uint32_t)mac_addr->addr[3] << 24, 0xff00 << 16);
+ set_control(0x5 << 4, 0x7 << 4);
+ set_control((uint32_t)mac_addr->addr[4] << 16, 0x00ff << 16);
+ set_control((uint32_t)mac_addr->addr[5] << 24, 0xff00 << 16);
+
+ //clear cmd
+ set_control(0x0, 0x7 << 4);
+}
+
void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){
switch(mode){
case PKT_CTRL_ROUTING_MODE_SLAVE:
diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h
index 86fb46d32..761209530 100644
--- a/firmware/microblaze/lib/pkt_ctrl.h
+++ b/firmware/microblaze/lib/pkt_ctrl.h
@@ -19,12 +19,19 @@
#define INCLUDED_PKT_CTRL_H
#include <stddef.h>
+#include <lwip/ip_addr.h>
+#include <net/eth_mac_addr.h>
typedef enum {
PKT_CTRL_ROUTING_MODE_SLAVE,
PKT_CTRL_ROUTING_MODE_MASTER,
} pkt_ctrl_routing_mode_t;
+//! Register this devices addresses into the router
+void pkt_ctrl_register_addrs(
+ const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr
+);
+
//! Set the routing mode for this device
void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode);