Some quick code to use UDP-only (no TCP) with mBed. Echos received packets and sends packets when a button is pressed

Dependencies:   mbed

Committer:
pehrhovey
Date:
Sun Mar 14 00:54:12 2010 +0000
Revision:
0:a548a085de55

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pehrhovey 0:a548a085de55 1 /*
pehrhovey 0:a548a085de55 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
pehrhovey 0:a548a085de55 3 * All rights reserved.
pehrhovey 0:a548a085de55 4 *
pehrhovey 0:a548a085de55 5 * Redistribution and use in source and binary forms, with or without modification,
pehrhovey 0:a548a085de55 6 * are permitted provided that the following conditions are met:
pehrhovey 0:a548a085de55 7 *
pehrhovey 0:a548a085de55 8 * 1. Redistributions of source code must retain the above copyright notice,
pehrhovey 0:a548a085de55 9 * this list of conditions and the following disclaimer.
pehrhovey 0:a548a085de55 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
pehrhovey 0:a548a085de55 11 * this list of conditions and the following disclaimer in the documentation
pehrhovey 0:a548a085de55 12 * and/or other materials provided with the distribution.
pehrhovey 0:a548a085de55 13 * 3. The name of the author may not be used to endorse or promote products
pehrhovey 0:a548a085de55 14 * derived from this software without specific prior written permission.
pehrhovey 0:a548a085de55 15 *
pehrhovey 0:a548a085de55 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
pehrhovey 0:a548a085de55 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
pehrhovey 0:a548a085de55 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
pehrhovey 0:a548a085de55 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
pehrhovey 0:a548a085de55 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
pehrhovey 0:a548a085de55 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
pehrhovey 0:a548a085de55 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
pehrhovey 0:a548a085de55 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
pehrhovey 0:a548a085de55 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
pehrhovey 0:a548a085de55 25 * OF SUCH DAMAGE.
pehrhovey 0:a548a085de55 26 *
pehrhovey 0:a548a085de55 27 * This file is part of the lwIP TCP/IP stack.
pehrhovey 0:a548a085de55 28 *
pehrhovey 0:a548a085de55 29 * Author: Adam Dunkels <adam@sics.se>
pehrhovey 0:a548a085de55 30 *
pehrhovey 0:a548a085de55 31 */
pehrhovey 0:a548a085de55 32 #ifndef __LWIP_NETIF_H__
pehrhovey 0:a548a085de55 33 #define __LWIP_NETIF_H__
pehrhovey 0:a548a085de55 34
pehrhovey 0:a548a085de55 35 #include "lwip/opt.h"
pehrhovey 0:a548a085de55 36
pehrhovey 0:a548a085de55 37 #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
pehrhovey 0:a548a085de55 38
pehrhovey 0:a548a085de55 39 #include "lwip/err.h"
pehrhovey 0:a548a085de55 40
pehrhovey 0:a548a085de55 41 #include "lwip/ip_addr.h"
pehrhovey 0:a548a085de55 42
pehrhovey 0:a548a085de55 43 #include "lwip/inet.h"
pehrhovey 0:a548a085de55 44 #include "lwip/pbuf.h"
pehrhovey 0:a548a085de55 45 #if LWIP_DHCP
pehrhovey 0:a548a085de55 46 struct dhcp;
pehrhovey 0:a548a085de55 47 #endif
pehrhovey 0:a548a085de55 48 #if LWIP_AUTOIP
pehrhovey 0:a548a085de55 49 struct autoip;
pehrhovey 0:a548a085de55 50 #endif
pehrhovey 0:a548a085de55 51
pehrhovey 0:a548a085de55 52 #ifdef __cplusplus
pehrhovey 0:a548a085de55 53 extern "C" {
pehrhovey 0:a548a085de55 54 #endif
pehrhovey 0:a548a085de55 55
pehrhovey 0:a548a085de55 56 /* Throughout this file, IP addresses are expected to be in
pehrhovey 0:a548a085de55 57 * the same byte order as in IP_PCB. */
pehrhovey 0:a548a085de55 58
pehrhovey 0:a548a085de55 59 /** must be the maximum of all used hardware address lengths
pehrhovey 0:a548a085de55 60 across all types of interfaces in use */
pehrhovey 0:a548a085de55 61 #define NETIF_MAX_HWADDR_LEN 6U
pehrhovey 0:a548a085de55 62
pehrhovey 0:a548a085de55 63 /** TODO: define the use (where, when, whom) of netif flags */
pehrhovey 0:a548a085de55 64
pehrhovey 0:a548a085de55 65 /** whether the network interface is 'up'. this is
pehrhovey 0:a548a085de55 66 * a software flag used to control whether this network
pehrhovey 0:a548a085de55 67 * interface is enabled and processes traffic.
pehrhovey 0:a548a085de55 68 */
pehrhovey 0:a548a085de55 69 #define NETIF_FLAG_UP 0x01U
pehrhovey 0:a548a085de55 70 /** if set, the netif has broadcast capability */
pehrhovey 0:a548a085de55 71 #define NETIF_FLAG_BROADCAST 0x02U
pehrhovey 0:a548a085de55 72 /** if set, the netif is one end of a point-to-point connection */
pehrhovey 0:a548a085de55 73 #define NETIF_FLAG_POINTTOPOINT 0x04U
pehrhovey 0:a548a085de55 74 /** if set, the interface is configured using DHCP */
pehrhovey 0:a548a085de55 75 #define NETIF_FLAG_DHCP 0x08U
pehrhovey 0:a548a085de55 76 /** if set, the interface has an active link
pehrhovey 0:a548a085de55 77 * (set by the network interface driver) */
pehrhovey 0:a548a085de55 78 #define NETIF_FLAG_LINK_UP 0x10U
pehrhovey 0:a548a085de55 79 /** if set, the netif is an device using ARP */
pehrhovey 0:a548a085de55 80 #define NETIF_FLAG_ETHARP 0x20U
pehrhovey 0:a548a085de55 81 /** if set, the netif has IGMP capability */
pehrhovey 0:a548a085de55 82 #define NETIF_FLAG_IGMP 0x40U
pehrhovey 0:a548a085de55 83
pehrhovey 0:a548a085de55 84 /** Generic data structure used for all lwIP network interfaces.
pehrhovey 0:a548a085de55 85 * The following fields should be filled in by the initialization
pehrhovey 0:a548a085de55 86 * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
pehrhovey 0:a548a085de55 87
pehrhovey 0:a548a085de55 88 struct netif {
pehrhovey 0:a548a085de55 89 /** pointer to next in linked list */
pehrhovey 0:a548a085de55 90 struct netif *next;
pehrhovey 0:a548a085de55 91
pehrhovey 0:a548a085de55 92 /** IP address configuration in network byte order */
pehrhovey 0:a548a085de55 93 struct ip_addr ip_addr;
pehrhovey 0:a548a085de55 94 struct ip_addr netmask;
pehrhovey 0:a548a085de55 95 struct ip_addr gw;
pehrhovey 0:a548a085de55 96
pehrhovey 0:a548a085de55 97 /** This function is called by the network device driver
pehrhovey 0:a548a085de55 98 * to pass a packet up the TCP/IP stack. */
pehrhovey 0:a548a085de55 99 err_t (* input)(struct pbuf *p, struct netif *inp);
pehrhovey 0:a548a085de55 100 /** This function is called by the IP module when it wants
pehrhovey 0:a548a085de55 101 * to send a packet on the interface. This function typically
pehrhovey 0:a548a085de55 102 * first resolves the hardware address, then sends the packet. */
pehrhovey 0:a548a085de55 103 err_t (* output)(struct netif *netif, struct pbuf *p,
pehrhovey 0:a548a085de55 104 struct ip_addr *ipaddr);
pehrhovey 0:a548a085de55 105 /** This function is called by the ARP module when it wants
pehrhovey 0:a548a085de55 106 * to send a packet on the interface. This function outputs
pehrhovey 0:a548a085de55 107 * the pbuf as-is on the link medium. */
pehrhovey 0:a548a085de55 108 err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
pehrhovey 0:a548a085de55 109 #if LWIP_NETIF_STATUS_CALLBACK
pehrhovey 0:a548a085de55 110 /** This function is called when the netif state is set to up or down
pehrhovey 0:a548a085de55 111 */
pehrhovey 0:a548a085de55 112 void (* status_callback)(struct netif *netif);
pehrhovey 0:a548a085de55 113 #endif /* LWIP_NETIF_STATUS_CALLBACK */
pehrhovey 0:a548a085de55 114 #if LWIP_NETIF_LINK_CALLBACK
pehrhovey 0:a548a085de55 115 /** This function is called when the netif link is set to up or down
pehrhovey 0:a548a085de55 116 */
pehrhovey 0:a548a085de55 117 void (* link_callback)(struct netif *netif);
pehrhovey 0:a548a085de55 118 #endif /* LWIP_NETIF_LINK_CALLBACK */
pehrhovey 0:a548a085de55 119 /** This field can be set by the device driver and could point
pehrhovey 0:a548a085de55 120 * to state information for the device. */
pehrhovey 0:a548a085de55 121 void *state;
pehrhovey 0:a548a085de55 122 #if LWIP_DHCP
pehrhovey 0:a548a085de55 123 /** the DHCP client state information for this netif */
pehrhovey 0:a548a085de55 124 struct dhcp *dhcp;
pehrhovey 0:a548a085de55 125 #endif /* LWIP_DHCP */
pehrhovey 0:a548a085de55 126 #if LWIP_AUTOIP
pehrhovey 0:a548a085de55 127 /** the AutoIP client state information for this netif */
pehrhovey 0:a548a085de55 128 struct autoip *autoip;
pehrhovey 0:a548a085de55 129 #endif
pehrhovey 0:a548a085de55 130 #if LWIP_NETIF_HOSTNAME
pehrhovey 0:a548a085de55 131 /* the hostname for this netif, NULL is a valid value */
pehrhovey 0:a548a085de55 132 char* hostname;
pehrhovey 0:a548a085de55 133 #endif /* LWIP_NETIF_HOSTNAME */
pehrhovey 0:a548a085de55 134 /** number of bytes used in hwaddr */
pehrhovey 0:a548a085de55 135 u8_t hwaddr_len;
pehrhovey 0:a548a085de55 136 /** link level hardware address of this interface */
pehrhovey 0:a548a085de55 137 u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
pehrhovey 0:a548a085de55 138 /** maximum transfer unit (in bytes) */
pehrhovey 0:a548a085de55 139 u16_t mtu;
pehrhovey 0:a548a085de55 140 /** flags (see NETIF_FLAG_ above) */
pehrhovey 0:a548a085de55 141 u8_t flags;
pehrhovey 0:a548a085de55 142 /** descriptive abbreviation */
pehrhovey 0:a548a085de55 143 char name[2];
pehrhovey 0:a548a085de55 144 /** number of this interface */
pehrhovey 0:a548a085de55 145 u8_t num;
pehrhovey 0:a548a085de55 146 #if LWIP_SNMP
pehrhovey 0:a548a085de55 147 /** link type (from "snmp_ifType" enum from snmp.h) */
pehrhovey 0:a548a085de55 148 u8_t link_type;
pehrhovey 0:a548a085de55 149 /** (estimate) link speed */
pehrhovey 0:a548a085de55 150 u32_t link_speed;
pehrhovey 0:a548a085de55 151 /** timestamp at last change made (up/down) */
pehrhovey 0:a548a085de55 152 u32_t ts;
pehrhovey 0:a548a085de55 153 /** counters */
pehrhovey 0:a548a085de55 154 u32_t ifinoctets;
pehrhovey 0:a548a085de55 155 u32_t ifinucastpkts;
pehrhovey 0:a548a085de55 156 u32_t ifinnucastpkts;
pehrhovey 0:a548a085de55 157 u32_t ifindiscards;
pehrhovey 0:a548a085de55 158 u32_t ifoutoctets;
pehrhovey 0:a548a085de55 159 u32_t ifoutucastpkts;
pehrhovey 0:a548a085de55 160 u32_t ifoutnucastpkts;
pehrhovey 0:a548a085de55 161 u32_t ifoutdiscards;
pehrhovey 0:a548a085de55 162 #endif /* LWIP_SNMP */
pehrhovey 0:a548a085de55 163 #if LWIP_IGMP
pehrhovey 0:a548a085de55 164 /* This function could be called to add or delete a entry in the multicast filter table of the ethernet MAC.*/
pehrhovey 0:a548a085de55 165 err_t (*igmp_mac_filter)( struct netif *netif, struct ip_addr *group, u8_t action);
pehrhovey 0:a548a085de55 166 #endif /* LWIP_IGMP */
pehrhovey 0:a548a085de55 167 #if LWIP_NETIF_HWADDRHINT
pehrhovey 0:a548a085de55 168 u8_t *addr_hint;
pehrhovey 0:a548a085de55 169 #endif /* LWIP_NETIF_HWADDRHINT */
pehrhovey 0:a548a085de55 170 #if ENABLE_LOOPBACK
pehrhovey 0:a548a085de55 171 /* List of packets to be queued for ourselves. */
pehrhovey 0:a548a085de55 172 struct pbuf *loop_first;
pehrhovey 0:a548a085de55 173 struct pbuf *loop_last;
pehrhovey 0:a548a085de55 174 #if LWIP_LOOPBACK_MAX_PBUFS
pehrhovey 0:a548a085de55 175 u16_t loop_cnt_current;
pehrhovey 0:a548a085de55 176 #endif /* LWIP_LOOPBACK_MAX_PBUFS */
pehrhovey 0:a548a085de55 177 #endif /* ENABLE_LOOPBACK */
pehrhovey 0:a548a085de55 178 };
pehrhovey 0:a548a085de55 179
pehrhovey 0:a548a085de55 180 #if LWIP_SNMP
pehrhovey 0:a548a085de55 181 #define NETIF_INIT_SNMP(netif, type, speed) \
pehrhovey 0:a548a085de55 182 /* use "snmp_ifType" enum from snmp.h for "type", snmp_ifType_ethernet_csmacd by example */ \
pehrhovey 0:a548a085de55 183 netif->link_type = type; \
pehrhovey 0:a548a085de55 184 /* your link speed here (units: bits per second) */ \
pehrhovey 0:a548a085de55 185 netif->link_speed = speed; \
pehrhovey 0:a548a085de55 186 netif->ts = 0; \
pehrhovey 0:a548a085de55 187 netif->ifinoctets = 0; \
pehrhovey 0:a548a085de55 188 netif->ifinucastpkts = 0; \
pehrhovey 0:a548a085de55 189 netif->ifinnucastpkts = 0; \
pehrhovey 0:a548a085de55 190 netif->ifindiscards = 0; \
pehrhovey 0:a548a085de55 191 netif->ifoutoctets = 0; \
pehrhovey 0:a548a085de55 192 netif->ifoutucastpkts = 0; \
pehrhovey 0:a548a085de55 193 netif->ifoutnucastpkts = 0; \
pehrhovey 0:a548a085de55 194 netif->ifoutdiscards = 0
pehrhovey 0:a548a085de55 195 #else /* LWIP_SNMP */
pehrhovey 0:a548a085de55 196 #define NETIF_INIT_SNMP(netif, type, speed)
pehrhovey 0:a548a085de55 197 #endif /* LWIP_SNMP */
pehrhovey 0:a548a085de55 198
pehrhovey 0:a548a085de55 199
pehrhovey 0:a548a085de55 200 /** The list of network interfaces. */
pehrhovey 0:a548a085de55 201 extern struct netif *netif_list;
pehrhovey 0:a548a085de55 202 /** The default network interface. */
pehrhovey 0:a548a085de55 203 extern struct netif *netif_default;
pehrhovey 0:a548a085de55 204
pehrhovey 0:a548a085de55 205 #define netif_init() /* Compatibility define, not init needed. */
pehrhovey 0:a548a085de55 206
pehrhovey 0:a548a085de55 207 struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
pehrhovey 0:a548a085de55 208 struct ip_addr *gw,
pehrhovey 0:a548a085de55 209 void *state,
pehrhovey 0:a548a085de55 210 err_t (* init)(struct netif *netif),
pehrhovey 0:a548a085de55 211 err_t (* input)(struct pbuf *p, struct netif *netif));
pehrhovey 0:a548a085de55 212
pehrhovey 0:a548a085de55 213 void
pehrhovey 0:a548a085de55 214 netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
pehrhovey 0:a548a085de55 215 struct ip_addr *gw);
pehrhovey 0:a548a085de55 216 void netif_remove(struct netif * netif);
pehrhovey 0:a548a085de55 217
pehrhovey 0:a548a085de55 218 /* Returns a network interface given its name. The name is of the form
pehrhovey 0:a548a085de55 219 "et0", where the first two letters are the "name" field in the
pehrhovey 0:a548a085de55 220 netif structure, and the digit is in the num field in the same
pehrhovey 0:a548a085de55 221 structure. */
pehrhovey 0:a548a085de55 222 struct netif *netif_find(char *name);
pehrhovey 0:a548a085de55 223
pehrhovey 0:a548a085de55 224 void netif_set_default(struct netif *netif);
pehrhovey 0:a548a085de55 225
pehrhovey 0:a548a085de55 226 void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
pehrhovey 0:a548a085de55 227 void netif_set_netmask(struct netif *netif, struct ip_addr *netmask);
pehrhovey 0:a548a085de55 228 void netif_set_gw(struct netif *netif, struct ip_addr *gw);
pehrhovey 0:a548a085de55 229
pehrhovey 0:a548a085de55 230 void netif_set_up(struct netif *netif);
pehrhovey 0:a548a085de55 231 void netif_set_down(struct netif *netif);
pehrhovey 0:a548a085de55 232 u8_t netif_is_up(struct netif *netif);
pehrhovey 0:a548a085de55 233
pehrhovey 0:a548a085de55 234 #if LWIP_NETIF_STATUS_CALLBACK
pehrhovey 0:a548a085de55 235 /*
pehrhovey 0:a548a085de55 236 * Set callback to be called when interface is brought up/down
pehrhovey 0:a548a085de55 237 */
pehrhovey 0:a548a085de55 238 void netif_set_status_callback(struct netif *netif, void (* status_callback)(struct netif *netif));
pehrhovey 0:a548a085de55 239 #endif /* LWIP_NETIF_STATUS_CALLBACK */
pehrhovey 0:a548a085de55 240
pehrhovey 0:a548a085de55 241 #if LWIP_NETIF_LINK_CALLBACK
pehrhovey 0:a548a085de55 242 void netif_set_link_up(struct netif *netif);
pehrhovey 0:a548a085de55 243 void netif_set_link_down(struct netif *netif);
pehrhovey 0:a548a085de55 244 u8_t netif_is_link_up(struct netif *netif);
pehrhovey 0:a548a085de55 245 /*
pehrhovey 0:a548a085de55 246 * Set callback to be called when link is brought up/down
pehrhovey 0:a548a085de55 247 */
pehrhovey 0:a548a085de55 248 void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif));
pehrhovey 0:a548a085de55 249 #endif /* LWIP_NETIF_LINK_CALLBACK */
pehrhovey 0:a548a085de55 250
pehrhovey 0:a548a085de55 251 #ifdef __cplusplus
pehrhovey 0:a548a085de55 252 }
pehrhovey 0:a548a085de55 253 #endif
pehrhovey 0:a548a085de55 254
pehrhovey 0:a548a085de55 255 #if ENABLE_LOOPBACK
pehrhovey 0:a548a085de55 256 err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip);
pehrhovey 0:a548a085de55 257 void netif_poll(struct netif *netif);
pehrhovey 0:a548a085de55 258 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
pehrhovey 0:a548a085de55 259 void netif_poll_all(void);
pehrhovey 0:a548a085de55 260 #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
pehrhovey 0:a548a085de55 261 #endif /* ENABLE_LOOPBACK */
pehrhovey 0:a548a085de55 262
pehrhovey 0:a548a085de55 263 #endif /* __LWIP_NETIF_H__ */