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