This is lwip-eth library for WlanBP3595 library. We forked lwip-eth library. We changed the driver.

Fork of lwip-eth by mbed official

Committer:
tousaki
Date:
Fri Dec 25 05:53:36 2015 +0000
Revision:
30:67a5fc1532c0
We forked lwip-eth library.; We changed the driver.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tousaki 30:67a5fc1532c0 1 #include "lwip/opt.h"
tousaki 30:67a5fc1532c0 2 #include "lwip/def.h"
tousaki 30:67a5fc1532c0 3 #include "lwip/mem.h"
tousaki 30:67a5fc1532c0 4 #include "lwip/pbuf.h"
tousaki 30:67a5fc1532c0 5 #include "lwip/sys.h"
tousaki 30:67a5fc1532c0 6 #include "lwip/stats.h"
tousaki 30:67a5fc1532c0 7 #include "lwip/snmp.h"
tousaki 30:67a5fc1532c0 8 #include "lwip/tcpip.h"
tousaki 30:67a5fc1532c0 9 #include "netif/etharp.h"
tousaki 30:67a5fc1532c0 10 #include "netif/ppp_oe.h"
tousaki 30:67a5fc1532c0 11 #include "mbed_interface.h"
tousaki 30:67a5fc1532c0 12
tousaki 30:67a5fc1532c0 13 #include <string.h>
tousaki 30:67a5fc1532c0 14 #include "rza1_bp3595_emac.h"
tousaki 30:67a5fc1532c0 15 #include "WlanBP3595.h"
tousaki 30:67a5fc1532c0 16
tousaki 30:67a5fc1532c0 17 /* Static variable */
tousaki 30:67a5fc1532c0 18 static struct netif * volatile target_netif = NULL;
tousaki 30:67a5fc1532c0 19 static volatile int init_sts = 0; /* 0: not initialized, 1:initialized */
tousaki 30:67a5fc1532c0 20 static int connect_sts = 0; /* 0: disconnected, 1:connected */
tousaki 30:67a5fc1532c0 21
tousaki 30:67a5fc1532c0 22 /* Static function */
tousaki 30:67a5fc1532c0 23 static err_t rza1_bp3595_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr);
tousaki 30:67a5fc1532c0 24 static err_t rza1_bp3595_low_level_output(struct netif *netif, struct pbuf *p);
tousaki 30:67a5fc1532c0 25
tousaki 30:67a5fc1532c0 26 /* This function is called from the receiving thread of WlanBP3595 library. */
tousaki 30:67a5fc1532c0 27 void rza1_bp3595_input(void *buff, u16_t recv_size) {
tousaki 30:67a5fc1532c0 28 struct eth_hdr *ethhdr;
tousaki 30:67a5fc1532c0 29 struct pbuf *p;
tousaki 30:67a5fc1532c0 30 struct pbuf *q;
tousaki 30:67a5fc1532c0 31 unsigned char *current_ptr;
tousaki 30:67a5fc1532c0 32 u16_t remain_len;
tousaki 30:67a5fc1532c0 33 u16_t copy_len;
tousaki 30:67a5fc1532c0 34
tousaki 30:67a5fc1532c0 35 if (recv_size != 0) {
tousaki 30:67a5fc1532c0 36 p = pbuf_alloc(PBUF_RAW, recv_size, PBUF_POOL);
tousaki 30:67a5fc1532c0 37 if (p != NULL) {
tousaki 30:67a5fc1532c0 38 /* Copy data */
tousaki 30:67a5fc1532c0 39 current_ptr = (unsigned char *)buff;
tousaki 30:67a5fc1532c0 40 remain_len = recv_size;
tousaki 30:67a5fc1532c0 41 for (q = p; q != NULL && remain_len > 0; q = q->next) {
tousaki 30:67a5fc1532c0 42 if (remain_len <= q->len)
tousaki 30:67a5fc1532c0 43 {
tousaki 30:67a5fc1532c0 44 copy_len = remain_len;
tousaki 30:67a5fc1532c0 45 }
tousaki 30:67a5fc1532c0 46 else
tousaki 30:67a5fc1532c0 47 {
tousaki 30:67a5fc1532c0 48 copy_len = q->len;
tousaki 30:67a5fc1532c0 49 }
tousaki 30:67a5fc1532c0 50 memcpy(q->payload, current_ptr, copy_len);
tousaki 30:67a5fc1532c0 51 current_ptr += copy_len;
tousaki 30:67a5fc1532c0 52 remain_len -= copy_len;
tousaki 30:67a5fc1532c0 53 }
tousaki 30:67a5fc1532c0 54
tousaki 30:67a5fc1532c0 55 /* Check Ethernet frame type */
tousaki 30:67a5fc1532c0 56 ethhdr = p->payload;
tousaki 30:67a5fc1532c0 57 switch (htons(ethhdr->type)) {
tousaki 30:67a5fc1532c0 58 case ETHTYPE_IP:
tousaki 30:67a5fc1532c0 59 case ETHTYPE_ARP:
tousaki 30:67a5fc1532c0 60 #if PPPOE_SUPPORT
tousaki 30:67a5fc1532c0 61 case ETHTYPE_PPPOEDISC:
tousaki 30:67a5fc1532c0 62 case ETHTYPE_PPPOE:
tousaki 30:67a5fc1532c0 63 #endif /* PPPOE_SUPPORT */
tousaki 30:67a5fc1532c0 64 /* full packet send to tcpip_thread to process */
tousaki 30:67a5fc1532c0 65 if (target_netif->input(p, target_netif) != ERR_OK) {
tousaki 30:67a5fc1532c0 66 /* Free buffer */
tousaki 30:67a5fc1532c0 67 pbuf_free(p);
tousaki 30:67a5fc1532c0 68 }
tousaki 30:67a5fc1532c0 69 break;
tousaki 30:67a5fc1532c0 70 default:
tousaki 30:67a5fc1532c0 71 /* Free buffer */
tousaki 30:67a5fc1532c0 72 pbuf_free(p);
tousaki 30:67a5fc1532c0 73 break;
tousaki 30:67a5fc1532c0 74 }
tousaki 30:67a5fc1532c0 75 }
tousaki 30:67a5fc1532c0 76 }
tousaki 30:67a5fc1532c0 77 }
tousaki 30:67a5fc1532c0 78
tousaki 30:67a5fc1532c0 79 void rza1_bp3595_connected(void) {
tousaki 30:67a5fc1532c0 80 /* 0: not initialized, 1:initialized */
tousaki 30:67a5fc1532c0 81 if (init_sts == 1) {
tousaki 30:67a5fc1532c0 82 /* 0: disconnected, 1:connected */
tousaki 30:67a5fc1532c0 83 if (connect_sts == 0) {
tousaki 30:67a5fc1532c0 84 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*)target_netif, 1);
tousaki 30:67a5fc1532c0 85 connect_sts = 1;
tousaki 30:67a5fc1532c0 86 }
tousaki 30:67a5fc1532c0 87 }
tousaki 30:67a5fc1532c0 88 }
tousaki 30:67a5fc1532c0 89
tousaki 30:67a5fc1532c0 90 void rza1_bp3595_disconnected(void) {
tousaki 30:67a5fc1532c0 91 /* 0: not initialized, 1:initialized */
tousaki 30:67a5fc1532c0 92 if (init_sts == 1) {
tousaki 30:67a5fc1532c0 93 /* 0: disconnected, 1:connected */
tousaki 30:67a5fc1532c0 94 if (connect_sts == 1) {
tousaki 30:67a5fc1532c0 95 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*)target_netif, 1);
tousaki 30:67a5fc1532c0 96 connect_sts = 0;
tousaki 30:67a5fc1532c0 97 }
tousaki 30:67a5fc1532c0 98 }
tousaki 30:67a5fc1532c0 99 }
tousaki 30:67a5fc1532c0 100
tousaki 30:67a5fc1532c0 101 static err_t rza1_bp3595_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr) {
tousaki 30:67a5fc1532c0 102 if (netif->flags & NETIF_FLAG_LINK_UP) {
tousaki 30:67a5fc1532c0 103 return etharp_output(netif, q, ipaddr);
tousaki 30:67a5fc1532c0 104 }
tousaki 30:67a5fc1532c0 105
tousaki 30:67a5fc1532c0 106 return ERR_CONN;
tousaki 30:67a5fc1532c0 107 }
tousaki 30:67a5fc1532c0 108
tousaki 30:67a5fc1532c0 109 static err_t rza1_bp3595_low_level_output(struct netif *netif, struct pbuf *p) {
tousaki 30:67a5fc1532c0 110 err_t err = ERR_MEM;
tousaki 30:67a5fc1532c0 111 int ret;
tousaki 30:67a5fc1532c0 112
tousaki 30:67a5fc1532c0 113 ret = WlanBP3595_Output(p);
tousaki 30:67a5fc1532c0 114 if (ret == 0) {
tousaki 30:67a5fc1532c0 115 err = ERR_OK;
tousaki 30:67a5fc1532c0 116 }
tousaki 30:67a5fc1532c0 117
tousaki 30:67a5fc1532c0 118 return err;
tousaki 30:67a5fc1532c0 119 }
tousaki 30:67a5fc1532c0 120
tousaki 30:67a5fc1532c0 121 err_t eth_arch_enetif_init(struct netif *netif)
tousaki 30:67a5fc1532c0 122 {
tousaki 30:67a5fc1532c0 123 /* Set MAC hardware address */
tousaki 30:67a5fc1532c0 124 #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
tousaki 30:67a5fc1532c0 125 netif->hwaddr[0] = MBED_MAC_ADDR_0;
tousaki 30:67a5fc1532c0 126 netif->hwaddr[1] = MBED_MAC_ADDR_1;
tousaki 30:67a5fc1532c0 127 netif->hwaddr[2] = MBED_MAC_ADDR_2;
tousaki 30:67a5fc1532c0 128 netif->hwaddr[3] = MBED_MAC_ADDR_3;
tousaki 30:67a5fc1532c0 129 netif->hwaddr[4] = MBED_MAC_ADDR_4;
tousaki 30:67a5fc1532c0 130 netif->hwaddr[5] = MBED_MAC_ADDR_5;
tousaki 30:67a5fc1532c0 131 #else
tousaki 30:67a5fc1532c0 132 mbed_mac_address((char *)netif->hwaddr);
tousaki 30:67a5fc1532c0 133 #endif
tousaki 30:67a5fc1532c0 134
tousaki 30:67a5fc1532c0 135 /* Set MAC hardware address length */
tousaki 30:67a5fc1532c0 136 netif->hwaddr_len = ETHARP_HWADDR_LEN;
tousaki 30:67a5fc1532c0 137
tousaki 30:67a5fc1532c0 138 /* Set maximum transfer unit */
tousaki 30:67a5fc1532c0 139 netif->mtu = 1500;
tousaki 30:67a5fc1532c0 140
tousaki 30:67a5fc1532c0 141 /* Set device capabilities */
tousaki 30:67a5fc1532c0 142 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
tousaki 30:67a5fc1532c0 143
tousaki 30:67a5fc1532c0 144 #if LWIP_NETIF_HOSTNAME
tousaki 30:67a5fc1532c0 145 /* Initialize interface hostname */
tousaki 30:67a5fc1532c0 146 netif->hostname = "lwiprza1";
tousaki 30:67a5fc1532c0 147 #endif /* LWIP_NETIF_HOSTNAME */
tousaki 30:67a5fc1532c0 148
tousaki 30:67a5fc1532c0 149 netif->name[0] = 'e';
tousaki 30:67a5fc1532c0 150 netif->name[1] = 'n';
tousaki 30:67a5fc1532c0 151
tousaki 30:67a5fc1532c0 152 netif->output = rza1_bp3595_etharp_output;
tousaki 30:67a5fc1532c0 153 netif->linkoutput = rza1_bp3595_low_level_output;
tousaki 30:67a5fc1532c0 154
tousaki 30:67a5fc1532c0 155 target_netif = netif;
tousaki 30:67a5fc1532c0 156
tousaki 30:67a5fc1532c0 157 init_sts = 1; /* 0: not initialized, 1:initialized */
tousaki 30:67a5fc1532c0 158
tousaki 30:67a5fc1532c0 159 return ERR_OK;
tousaki 30:67a5fc1532c0 160 }
tousaki 30:67a5fc1532c0 161
tousaki 30:67a5fc1532c0 162 void eth_arch_enable_interrupts(void) {
tousaki 30:67a5fc1532c0 163 WlanBP3595_RecvEnable();
tousaki 30:67a5fc1532c0 164 }
tousaki 30:67a5fc1532c0 165
tousaki 30:67a5fc1532c0 166 void eth_arch_disable_interrupts(void) {
tousaki 30:67a5fc1532c0 167 WlanBP3595_RecvDisable();
tousaki 30:67a5fc1532c0 168 }
tousaki 30:67a5fc1532c0 169
tousaki 30:67a5fc1532c0 170 void mbed_mac_address(char *mac) {
tousaki 30:67a5fc1532c0 171 grp_wld_byte_array tBAWidData; /* byte array wid data */
tousaki 30:67a5fc1532c0 172 int ret;
tousaki 30:67a5fc1532c0 173
tousaki 30:67a5fc1532c0 174 tBAWidData.pucData = (grp_u8 *)mac;
tousaki 30:67a5fc1532c0 175 tBAWidData.ulSize = 6;
tousaki 30:67a5fc1532c0 176
tousaki 30:67a5fc1532c0 177 ret = WlanBP3595_Ioctl(GRP_WLD_IOCTL_GET_MAC_ADDRESS, &tBAWidData);
tousaki 30:67a5fc1532c0 178 if (ret != 0) {
tousaki 30:67a5fc1532c0 179 /* error(return a default MAC hardware address) */
tousaki 30:67a5fc1532c0 180 mac[0] = 0x00;
tousaki 30:67a5fc1532c0 181 mac[1] = 0x02;
tousaki 30:67a5fc1532c0 182 mac[2] = 0xF7;
tousaki 30:67a5fc1532c0 183 mac[3] = 0xF0;
tousaki 30:67a5fc1532c0 184 mac[4] = 0x00;
tousaki 30:67a5fc1532c0 185 mac[5] = 0x00;
tousaki 30:67a5fc1532c0 186 }
tousaki 30:67a5fc1532c0 187 }