Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkersh3 0:e7ca326e76ee 1 /**
mkersh3 0:e7ca326e76ee 2 * @file
mkersh3 0:e7ca326e76ee 3 * Network Interface Sequential API module
mkersh3 0:e7ca326e76ee 4 *
mkersh3 0:e7ca326e76ee 5 */
mkersh3 0:e7ca326e76ee 6
mkersh3 0:e7ca326e76ee 7 /*
mkersh3 0:e7ca326e76ee 8 * Redistribution and use in source and binary forms, with or without modification,
mkersh3 0:e7ca326e76ee 9 * are permitted provided that the following conditions are met:
mkersh3 0:e7ca326e76ee 10 *
mkersh3 0:e7ca326e76ee 11 * 1. Redistributions of source code must retain the above copyright notice,
mkersh3 0:e7ca326e76ee 12 * this list of conditions and the following disclaimer.
mkersh3 0:e7ca326e76ee 13 * 2. Redistributions in binary form must reproduce the above copyright notice,
mkersh3 0:e7ca326e76ee 14 * this list of conditions and the following disclaimer in the documentation
mkersh3 0:e7ca326e76ee 15 * and/or other materials provided with the distribution.
mkersh3 0:e7ca326e76ee 16 * 3. The name of the author may not be used to endorse or promote products
mkersh3 0:e7ca326e76ee 17 * derived from this software without specific prior written permission.
mkersh3 0:e7ca326e76ee 18 *
mkersh3 0:e7ca326e76ee 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mkersh3 0:e7ca326e76ee 20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mkersh3 0:e7ca326e76ee 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mkersh3 0:e7ca326e76ee 22 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mkersh3 0:e7ca326e76ee 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mkersh3 0:e7ca326e76ee 24 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mkersh3 0:e7ca326e76ee 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mkersh3 0:e7ca326e76ee 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mkersh3 0:e7ca326e76ee 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mkersh3 0:e7ca326e76ee 28 * OF SUCH DAMAGE.
mkersh3 0:e7ca326e76ee 29 *
mkersh3 0:e7ca326e76ee 30 * This file is part of the lwIP TCP/IP stack.
mkersh3 0:e7ca326e76ee 31 *
mkersh3 0:e7ca326e76ee 32 */
mkersh3 0:e7ca326e76ee 33
mkersh3 0:e7ca326e76ee 34 #include "lwip/opt.h"
mkersh3 0:e7ca326e76ee 35
mkersh3 0:e7ca326e76ee 36 #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
mkersh3 0:e7ca326e76ee 37
mkersh3 0:e7ca326e76ee 38 #include "lwip/netifapi.h"
mkersh3 0:e7ca326e76ee 39 #include "lwip/tcpip.h"
mkersh3 0:e7ca326e76ee 40
mkersh3 0:e7ca326e76ee 41 /**
mkersh3 0:e7ca326e76ee 42 * Call netif_add() inside the tcpip_thread context.
mkersh3 0:e7ca326e76ee 43 */
mkersh3 0:e7ca326e76ee 44 void
mkersh3 0:e7ca326e76ee 45 do_netifapi_netif_add(struct netifapi_msg_msg *msg)
mkersh3 0:e7ca326e76ee 46 {
mkersh3 0:e7ca326e76ee 47 if (!netif_add( msg->netif,
mkersh3 0:e7ca326e76ee 48 msg->msg.add.ipaddr,
mkersh3 0:e7ca326e76ee 49 msg->msg.add.netmask,
mkersh3 0:e7ca326e76ee 50 msg->msg.add.gw,
mkersh3 0:e7ca326e76ee 51 msg->msg.add.state,
mkersh3 0:e7ca326e76ee 52 msg->msg.add.init,
mkersh3 0:e7ca326e76ee 53 msg->msg.add.input)) {
mkersh3 0:e7ca326e76ee 54 msg->err = ERR_IF;
mkersh3 0:e7ca326e76ee 55 } else {
mkersh3 0:e7ca326e76ee 56 msg->err = ERR_OK;
mkersh3 0:e7ca326e76ee 57 }
mkersh3 0:e7ca326e76ee 58 TCPIP_NETIFAPI_ACK(msg);
mkersh3 0:e7ca326e76ee 59 }
mkersh3 0:e7ca326e76ee 60
mkersh3 0:e7ca326e76ee 61 /**
mkersh3 0:e7ca326e76ee 62 * Call netif_set_addr() inside the tcpip_thread context.
mkersh3 0:e7ca326e76ee 63 */
mkersh3 0:e7ca326e76ee 64 void
mkersh3 0:e7ca326e76ee 65 do_netifapi_netif_set_addr(struct netifapi_msg_msg *msg)
mkersh3 0:e7ca326e76ee 66 {
mkersh3 0:e7ca326e76ee 67 netif_set_addr( msg->netif,
mkersh3 0:e7ca326e76ee 68 msg->msg.add.ipaddr,
mkersh3 0:e7ca326e76ee 69 msg->msg.add.netmask,
mkersh3 0:e7ca326e76ee 70 msg->msg.add.gw);
mkersh3 0:e7ca326e76ee 71 msg->err = ERR_OK;
mkersh3 0:e7ca326e76ee 72 TCPIP_NETIFAPI_ACK(msg);
mkersh3 0:e7ca326e76ee 73 }
mkersh3 0:e7ca326e76ee 74
mkersh3 0:e7ca326e76ee 75 /**
mkersh3 0:e7ca326e76ee 76 * Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the
mkersh3 0:e7ca326e76ee 77 * tcpip_thread context.
mkersh3 0:e7ca326e76ee 78 */
mkersh3 0:e7ca326e76ee 79 void
mkersh3 0:e7ca326e76ee 80 do_netifapi_netif_common(struct netifapi_msg_msg *msg)
mkersh3 0:e7ca326e76ee 81 {
mkersh3 0:e7ca326e76ee 82 if (msg->msg.common.errtfunc != NULL) {
mkersh3 0:e7ca326e76ee 83 msg->err = msg->msg.common.errtfunc(msg->netif);
mkersh3 0:e7ca326e76ee 84 } else {
mkersh3 0:e7ca326e76ee 85 msg->err = ERR_OK;
mkersh3 0:e7ca326e76ee 86 msg->msg.common.voidfunc(msg->netif);
mkersh3 0:e7ca326e76ee 87 }
mkersh3 0:e7ca326e76ee 88 TCPIP_NETIFAPI_ACK(msg);
mkersh3 0:e7ca326e76ee 89 }
mkersh3 0:e7ca326e76ee 90
mkersh3 0:e7ca326e76ee 91 /**
mkersh3 0:e7ca326e76ee 92 * Call netif_add() in a thread-safe way by running that function inside the
mkersh3 0:e7ca326e76ee 93 * tcpip_thread context.
mkersh3 0:e7ca326e76ee 94 *
mkersh3 0:e7ca326e76ee 95 * @note for params @see netif_add()
mkersh3 0:e7ca326e76ee 96 */
mkersh3 0:e7ca326e76ee 97 err_t
mkersh3 0:e7ca326e76ee 98 netifapi_netif_add(struct netif *netif,
mkersh3 0:e7ca326e76ee 99 ip_addr_t *ipaddr,
mkersh3 0:e7ca326e76ee 100 ip_addr_t *netmask,
mkersh3 0:e7ca326e76ee 101 ip_addr_t *gw,
mkersh3 0:e7ca326e76ee 102 void *state,
mkersh3 0:e7ca326e76ee 103 netif_init_fn init,
mkersh3 0:e7ca326e76ee 104 netif_input_fn input)
mkersh3 0:e7ca326e76ee 105 {
mkersh3 0:e7ca326e76ee 106 struct netifapi_msg msg;
mkersh3 0:e7ca326e76ee 107 msg.function = do_netifapi_netif_add;
mkersh3 0:e7ca326e76ee 108 msg.msg.netif = netif;
mkersh3 0:e7ca326e76ee 109 msg.msg.msg.add.ipaddr = ipaddr;
mkersh3 0:e7ca326e76ee 110 msg.msg.msg.add.netmask = netmask;
mkersh3 0:e7ca326e76ee 111 msg.msg.msg.add.gw = gw;
mkersh3 0:e7ca326e76ee 112 msg.msg.msg.add.state = state;
mkersh3 0:e7ca326e76ee 113 msg.msg.msg.add.init = init;
mkersh3 0:e7ca326e76ee 114 msg.msg.msg.add.input = input;
mkersh3 0:e7ca326e76ee 115 TCPIP_NETIFAPI(&msg);
mkersh3 0:e7ca326e76ee 116 return msg.msg.err;
mkersh3 0:e7ca326e76ee 117 }
mkersh3 0:e7ca326e76ee 118
mkersh3 0:e7ca326e76ee 119 /**
mkersh3 0:e7ca326e76ee 120 * Call netif_set_addr() in a thread-safe way by running that function inside the
mkersh3 0:e7ca326e76ee 121 * tcpip_thread context.
mkersh3 0:e7ca326e76ee 122 *
mkersh3 0:e7ca326e76ee 123 * @note for params @see netif_set_addr()
mkersh3 0:e7ca326e76ee 124 */
mkersh3 0:e7ca326e76ee 125 err_t
mkersh3 0:e7ca326e76ee 126 netifapi_netif_set_addr(struct netif *netif,
mkersh3 0:e7ca326e76ee 127 ip_addr_t *ipaddr,
mkersh3 0:e7ca326e76ee 128 ip_addr_t *netmask,
mkersh3 0:e7ca326e76ee 129 ip_addr_t *gw)
mkersh3 0:e7ca326e76ee 130 {
mkersh3 0:e7ca326e76ee 131 struct netifapi_msg msg;
mkersh3 0:e7ca326e76ee 132 msg.function = do_netifapi_netif_set_addr;
mkersh3 0:e7ca326e76ee 133 msg.msg.netif = netif;
mkersh3 0:e7ca326e76ee 134 msg.msg.msg.add.ipaddr = ipaddr;
mkersh3 0:e7ca326e76ee 135 msg.msg.msg.add.netmask = netmask;
mkersh3 0:e7ca326e76ee 136 msg.msg.msg.add.gw = gw;
mkersh3 0:e7ca326e76ee 137 TCPIP_NETIFAPI(&msg);
mkersh3 0:e7ca326e76ee 138 return msg.msg.err;
mkersh3 0:e7ca326e76ee 139 }
mkersh3 0:e7ca326e76ee 140
mkersh3 0:e7ca326e76ee 141 /**
mkersh3 0:e7ca326e76ee 142 * call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe
mkersh3 0:e7ca326e76ee 143 * way by running that function inside the tcpip_thread context.
mkersh3 0:e7ca326e76ee 144 *
mkersh3 0:e7ca326e76ee 145 * @note use only for functions where there is only "netif" parameter.
mkersh3 0:e7ca326e76ee 146 */
mkersh3 0:e7ca326e76ee 147 err_t
mkersh3 0:e7ca326e76ee 148 netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
mkersh3 0:e7ca326e76ee 149 netifapi_errt_fn errtfunc)
mkersh3 0:e7ca326e76ee 150 {
mkersh3 0:e7ca326e76ee 151 struct netifapi_msg msg;
mkersh3 0:e7ca326e76ee 152 msg.function = do_netifapi_netif_common;
mkersh3 0:e7ca326e76ee 153 msg.msg.netif = netif;
mkersh3 0:e7ca326e76ee 154 msg.msg.msg.common.voidfunc = voidfunc;
mkersh3 0:e7ca326e76ee 155 msg.msg.msg.common.errtfunc = errtfunc;
mkersh3 0:e7ca326e76ee 156 TCPIP_NETIFAPI(&msg);
mkersh3 0:e7ca326e76ee 157 return msg.msg.err;
mkersh3 0:e7ca326e76ee 158 }
mkersh3 0:e7ca326e76ee 159
mkersh3 0:e7ca326e76ee 160 #endif /* LWIP_NETIF_API */