NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hexley 0:281d6ff68967 1
hexley 0:281d6ff68967 2 /*
hexley 0:281d6ff68967 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
hexley 0:281d6ff68967 4
hexley 0:281d6ff68967 5 Permission is hereby granted, free of charge, to any person obtaining a copy
hexley 0:281d6ff68967 6 of this software and associated documentation files (the "Software"), to deal
hexley 0:281d6ff68967 7 in the Software without restriction, including without limitation the rights
hexley 0:281d6ff68967 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hexley 0:281d6ff68967 9 copies of the Software, and to permit persons to whom the Software is
hexley 0:281d6ff68967 10 furnished to do so, subject to the following conditions:
hexley 0:281d6ff68967 11
hexley 0:281d6ff68967 12 The above copyright notice and this permission notice shall be included in
hexley 0:281d6ff68967 13 all copies or substantial portions of the Software.
hexley 0:281d6ff68967 14
hexley 0:281d6ff68967 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hexley 0:281d6ff68967 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hexley 0:281d6ff68967 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hexley 0:281d6ff68967 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hexley 0:281d6ff68967 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hexley 0:281d6ff68967 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hexley 0:281d6ff68967 21 THE SOFTWARE.
hexley 0:281d6ff68967 22 */
hexley 0:281d6ff68967 23
hexley 0:281d6ff68967 24 #include "netCfg.h"
hexley 0:281d6ff68967 25 #if NET_ETH
hexley 0:281d6ff68967 26
hexley 0:281d6ff68967 27 #include "mbed.h"
hexley 0:281d6ff68967 28
hexley 0:281d6ff68967 29 Ethernet *pEth = NULL;
hexley 0:281d6ff68967 30 #ifdef __cplusplus
hexley 0:281d6ff68967 31 extern "C" {
hexley 0:281d6ff68967 32 #endif
hexley 0:281d6ff68967 33
hexley 0:281d6ff68967 34 #include "lwip/opt.h"
hexley 0:281d6ff68967 35
hexley 0:281d6ff68967 36 #include "lwip/def.h"
hexley 0:281d6ff68967 37 #include "lwip/pbuf.h"
hexley 0:281d6ff68967 38 #include "lwip/sys.h"
hexley 0:281d6ff68967 39 #include "lwip/stats.h"
hexley 0:281d6ff68967 40 #include "netif/etharp.h"
hexley 0:281d6ff68967 41 #include "string.h"
hexley 0:281d6ff68967 42
hexley 0:281d6ff68967 43 //#include "eth_drv.h"
hexley 0:281d6ff68967 44
hexley 0:281d6ff68967 45 #define IFNAME0 'E'
hexley 0:281d6ff68967 46 #define IFNAME1 'X'
hexley 0:281d6ff68967 47
hexley 0:281d6ff68967 48 #define min(x,y) (((x)<(y))?(x):(y))
hexley 0:281d6ff68967 49
hexley 0:281d6ff68967 50 struct netif* eth_netif;
hexley 0:281d6ff68967 51
hexley 0:281d6ff68967 52 static err_t eth_output(struct netif *netif, struct pbuf *p) {
hexley 0:281d6ff68967 53 #if ETH_PAD_SIZE
hexley 0:281d6ff68967 54 pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
hexley 0:281d6ff68967 55 #endif
hexley 0:281d6ff68967 56
hexley 0:281d6ff68967 57 do {
hexley 0:281d6ff68967 58 pEth->write((const char *)p->payload, p->len);
hexley 0:281d6ff68967 59 } while((p = p->next)!=NULL);
hexley 0:281d6ff68967 60
hexley 0:281d6ff68967 61 pEth->send();
hexley 0:281d6ff68967 62
hexley 0:281d6ff68967 63 #if ETH_PAD_SIZE
hexley 0:281d6ff68967 64 pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
hexley 0:281d6ff68967 65 #endif
hexley 0:281d6ff68967 66
hexley 0:281d6ff68967 67 LINK_STATS_INC(link.xmit);
hexley 0:281d6ff68967 68 return ERR_OK;
hexley 0:281d6ff68967 69 }
hexley 0:281d6ff68967 70
hexley 0:281d6ff68967 71 /*
hexley 0:281d6ff68967 72 void show(char *buf, int size) {
hexley 0:281d6ff68967 73 printf("Destination: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
hexley 0:281d6ff68967 74 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
hexley 0:281d6ff68967 75 printf("Source: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
hexley 0:281d6ff68967 76 buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
hexley 0:281d6ff68967 77
hexley 0:281d6ff68967 78 printf("Type %hd\n", htons((short)buf[12]));
hexley 0:281d6ff68967 79
hexley 0:281d6ff68967 80 // hexview(buf, size);
hexley 0:281d6ff68967 81 }
hexley 0:281d6ff68967 82 */
hexley 0:281d6ff68967 83
hexley 0:281d6ff68967 84 void eth_poll() {
hexley 0:281d6ff68967 85 struct eth_hdr *ethhdr;
hexley 0:281d6ff68967 86 struct pbuf *frame, *p;
hexley 0:281d6ff68967 87 int len, read;
hexley 0:281d6ff68967 88
hexley 0:281d6ff68967 89 while((len = pEth->receive()) != 0) {
hexley 0:281d6ff68967 90 frame = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
hexley 0:281d6ff68967 91 if(frame == NULL) {
hexley 0:281d6ff68967 92 return;
hexley 0:281d6ff68967 93 }
hexley 0:281d6ff68967 94 p = frame;
hexley 0:281d6ff68967 95 /* no packet could be read, silently ignore this */
hexley 0:281d6ff68967 96 if (p == NULL) return;
hexley 0:281d6ff68967 97 do {
hexley 0:281d6ff68967 98 read = pEth->read((char *)p->payload, p->len);
hexley 0:281d6ff68967 99 p = p->next;
hexley 0:281d6ff68967 100 } while(p != NULL && read != 0);
hexley 0:281d6ff68967 101
hexley 0:281d6ff68967 102 #if ETH_PAD_SIZE
hexley 0:281d6ff68967 103 pbuf_header(p, ETH_PAD_SIZE);
hexley 0:281d6ff68967 104 #endif
hexley 0:281d6ff68967 105
hexley 0:281d6ff68967 106 ethhdr = (struct eth_hdr *)(frame->payload);
hexley 0:281d6ff68967 107
hexley 0:281d6ff68967 108 // show((char*)ethhdr, 13);
hexley 0:281d6ff68967 109
hexley 0:281d6ff68967 110 /*
hexley 0:281d6ff68967 111 switch(htons(ethhdr->type)) {
hexley 0:281d6ff68967 112
hexley 0:281d6ff68967 113 case ETHTYPE_IP:
hexley 0:281d6ff68967 114 etharp_ip_input(gnetif, frame);
hexley 0:281d6ff68967 115 pbuf_header(frame, -((s16_t) sizeof(struct eth_hdr)));
hexley 0:281d6ff68967 116 gnetif->input(frame, gnetif);
hexley 0:281d6ff68967 117 break;
hexley 0:281d6ff68967 118
hexley 0:281d6ff68967 119 case ETHTYPE_ARP:
hexley 0:281d6ff68967 120 etharp_arp_input(gnetif, (struct eth_addr *)(gnetif->hwaddr), frame);
hexley 0:281d6ff68967 121 break;
hexley 0:281d6ff68967 122
hexley 0:281d6ff68967 123 default:
hexley 0:281d6ff68967 124 break;
hexley 0:281d6ff68967 125 }*/
hexley 0:281d6ff68967 126
hexley 0:281d6ff68967 127
hexley 0:281d6ff68967 128
hexley 0:281d6ff68967 129 //ethernet_input(frame, gnetif);
hexley 0:281d6ff68967 130
hexley 0:281d6ff68967 131 switch (htons(ethhdr->type)) {
hexley 0:281d6ff68967 132 /* IP or ARP packet? */
hexley 0:281d6ff68967 133 case ETHTYPE_IP:
hexley 0:281d6ff68967 134 case ETHTYPE_ARP:
hexley 0:281d6ff68967 135 #if PPPOE_SUPPORT
hexley 0:281d6ff68967 136 /* PPPoE packet? */
hexley 0:281d6ff68967 137 case ETHTYPE_PPPOEDISC:
hexley 0:281d6ff68967 138 case ETHTYPE_PPPOE:
hexley 0:281d6ff68967 139 #endif /* PPPOE_SUPPORT */
hexley 0:281d6ff68967 140 /* full packet send to tcpip_thread to process */
hexley 0:281d6ff68967 141 //if (netif->input(p, gnetif)!=ERR_OK)
hexley 0:281d6ff68967 142 if (ethernet_input(frame, eth_netif)!=ERR_OK)
hexley 0:281d6ff68967 143 { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
hexley 0:281d6ff68967 144 pbuf_free(frame);
hexley 0:281d6ff68967 145 frame = NULL;
hexley 0:281d6ff68967 146 }
hexley 0:281d6ff68967 147 break;
hexley 0:281d6ff68967 148
hexley 0:281d6ff68967 149 default:
hexley 0:281d6ff68967 150 pbuf_free(frame);
hexley 0:281d6ff68967 151 frame = NULL;
hexley 0:281d6ff68967 152 break;
hexley 0:281d6ff68967 153 }
hexley 0:281d6ff68967 154
hexley 0:281d6ff68967 155 /* pbuf_free(frame); */
hexley 0:281d6ff68967 156 }
hexley 0:281d6ff68967 157
hexley 0:281d6ff68967 158
hexley 0:281d6ff68967 159
hexley 0:281d6ff68967 160
hexley 0:281d6ff68967 161 }
hexley 0:281d6ff68967 162
hexley 0:281d6ff68967 163 err_t eth_init(struct netif *netif) {
hexley 0:281d6ff68967 164 LWIP_ASSERT("netif != NULL", (netif != NULL));
hexley 0:281d6ff68967 165
hexley 0:281d6ff68967 166 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 0x2EA);
hexley 0:281d6ff68967 167
hexley 0:281d6ff68967 168 /* maximum transfer unit */
hexley 0:281d6ff68967 169 netif->mtu = 0x2EA;
hexley 0:281d6ff68967 170
hexley 0:281d6ff68967 171 /* device capabilities */
hexley 0:281d6ff68967 172 /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
hexley 0:281d6ff68967 173 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP;
hexley 0:281d6ff68967 174
hexley 0:281d6ff68967 175 netif->state = NULL;
hexley 0:281d6ff68967 176 eth_netif = netif;
hexley 0:281d6ff68967 177
hexley 0:281d6ff68967 178 netif->name[0] = IFNAME0;
hexley 0:281d6ff68967 179 netif->name[1] = IFNAME1;
hexley 0:281d6ff68967 180
hexley 0:281d6ff68967 181 /* We directly use etharp_output() here to save a function call.
hexley 0:281d6ff68967 182 * You can instead declare your own function an call etharp_output()
hexley 0:281d6ff68967 183 * from it if you have to do some checks before sending (e.g. if link
hexley 0:281d6ff68967 184 * is available...) */
hexley 0:281d6ff68967 185 netif->output = etharp_output;
hexley 0:281d6ff68967 186 netif->linkoutput = eth_output;
hexley 0:281d6ff68967 187
hexley 0:281d6ff68967 188 pEth = new Ethernet();
hexley 0:281d6ff68967 189
hexley 0:281d6ff68967 190 return ERR_OK;
hexley 0:281d6ff68967 191 }
hexley 0:281d6ff68967 192
hexley 0:281d6ff68967 193 void eth_free()
hexley 0:281d6ff68967 194 {
hexley 0:281d6ff68967 195 if(pEth)
hexley 0:281d6ff68967 196 delete pEth;
hexley 0:281d6ff68967 197 pEth = NULL;
hexley 0:281d6ff68967 198 }
hexley 0:281d6ff68967 199
hexley 0:281d6ff68967 200 void eth_address(char* mac) {
hexley 0:281d6ff68967 201 pEth->address(mac);
hexley 0:281d6ff68967 202 }
hexley 0:281d6ff68967 203
hexley 0:281d6ff68967 204 #ifdef __cplusplus
hexley 0:281d6ff68967 205 };
hexley 0:281d6ff68967 206 #endif
hexley 0:281d6ff68967 207
hexley 0:281d6ff68967 208 #endif